我有一个相当复杂的mql5 for循环代码集,需要通过opencl运行。这意味着我需要能够让一些内核函数调用其他函数。因此,我尝试了这个简单的代码,当我通过它调用另一个函数时,它无法创建程序(错误5105)。为什么?
const string _cl_source=
" rn"
" rn"
"__kernel void Tester() rn"
"{ rn"
" rn"
" float _margin = 10f; rn"
" float _balance = 10f; rn"
" float _equity = 10f; rn"
" float _openprice = 10f; rn"
" float _closeprice = 10f; rn"
" float _position = 10f; rn"
" rn"
/*fails on adding this line*/" CouponReset(_margin,_balance,_equity,_openprice,_closeprice,_position);rn"
" rn"
"} rn"
" rn"
" rn"
"__kernel void CouponReset(float margin, rn"
" float balance, rn"
" float equity, rn"
" float openprice, rn"
" float closeprice, rn"
" float position) rn"
"{ rn"
" position = 0f; rn"
" openprice = 0f; rn"
" closeprice = 0f; rn"
" balance = equity; rn"
" margin = balance; rn"
" rn"
"} rn"
" rn";
EDIT:实际上,我已经看过了,可以从另一个内核调用内核。但是,您不应该这样做,因为这可能会导致以后出现问题(特别是如果您使用__local
内存)。
应用程序中的关键问题只是0.0f
浮动。
您还可以执行一个由两个内核调用的单独函数。其中一个只是函数的包装器。
void _CouponReset(float margin,
float balance,
float equity,
float openprice,
float closeprice,
float position)
{
position = 0.0f;
openprice = 0.0f;
closeprice = 0.0f;
balance = equity;
margin = balance;
}
__kernel void Tester()
{
float _margin = 10.0f;
float _balance = 10.0f;
float _equity = 10.0f;
float _openprice = 10.0f;
float _closeprice = 10.0f;
float _position = 10.0f;
_CouponReset(_margin,_balance,_equity,_openprice,_closeprice,_position);
}
__kernel void CouponReset(float margin,
float balance,
float equity,
float openprice,
float closeprice,
float position)
{
_CouponReset(margin, balance, equity, openprice, closeprice, position);
}