我使用MQL5创建了一个指示器。
在分析之后,我看到99%的CPU是由我的OnCalculate()
使用的。
这是我的功能:
int OnCalculate( const int rates_total,
const int prev_calculated,
const int begin,
const double &price[]
)
{
//--- check for bars count
float tempprice[];
ArrayResize( tempprice, ArraySize( price ) );
if ( rates_total < InpMAPeriod - 1 + begin ) return( 0 ); // not enough bars for calculation
//--- first calculation or number of bars was changed
if ( prev_calculated == 0 ) ArrayInitialize( ExtLineBuffer, 0 );
ArrayCopy( tempprice, price );
//--- sets first bar from what index will be draw
PlotIndexSetInteger( 0, PLOT_DRAW_BEGIN, InpMAPeriod - 1 + begin );
switch( InpMAMethod )
{
case MODE_EMA: Execute_Me( price,
"CalculateEMA",
rates_total,
prev_calculated,
begin
);
break;
case MODE_LWMA: Execute_Me( price,
"CalculateLWMA",
rates_total,
prev_calculated,
begin
);
break;
case MODE_SMMA: Execute_Me( price,
"CalculateSmoothedMA",
rates_total,
prev_calculated,
begin
);
break;
case MODE_SMA: Execute_Me( price,
"CalculateSimpleMA",
rates_total,
prev_calculated,
begin
);
break;
}
return( rates_total );
}
下面是分析的结果:
好心,让我知道,我如何使OnCalculate()
工作在GPU而不是CPU。
发布于 2018-04-27 13:08:52
哪个计算设备,即您的程序是否使用CPU,可以通过CLContextCreate
调用来控制:
int CLContextCreate(int device)
其中device
可以是CL_USE_GPU_ONLY
,或者是特定的设备编号。
如何找出数字被描述为这里。
然而,:我从配置文件中看到的是,大部分时间都用于创建和释放OpenCL上下文。如果配置文件代表某种类型的调用堆栈,我假设为每次计算创建和释放OpenCL上下文,而不是在程序初始化和去初始化期间进行一次。
这似乎花费了您运行时的85 %。因此,请确保在初始化期间创建OpenCL上下文、程序、内核和缓冲区对象。对于重复的计算,您只需要设置内核参数、读/写缓冲区对象,并将内核排队执行。
希望这能有所帮助。
https://stackoverflow.com/questions/49995076
复制相似问题