Hello!
I have a Monte Carlo integrator with quite large complex integrand(I consider only real part at the first stage). Integrand itself contains the product of double-valued and thrust::complex-valued functions. The result is absolutely unpredictable(for me at least):
For example:
thrust::complex<double> part11, part12;
double part11r, part12r;
part11r=(-(FDEl_k2P*FDHo_dsqrt_mo_kqP_p) + FDEl_dsqrt_mo_k2pqP_m*(-1.0 + FDEl_k2P + FDHo_dsqrt_mo_kqP_p))*VPG_qP; // all functions and variables are double-valued
part11=-DWEn(k,omegaIn,"c","c","c","v",k,k2P,dsqrt_mo_k2pqP_m,dsqrt_mo_kqP_p)*part11r; //DWEn returns thrust::complex<double>.
part12r=(-((-1 + FDEl_dsqrt_mo_kqP_m)*FDHo_k2P) + (FDEl_dsqrt_mo_kqP_m - FDHo_k2P)*FDHo(dsqrt_mo_k2pqP_m))*VPG_qP;
part12=DWEn(k,omegaIn,"c","v","v","v",dsqrt_mo_kqP_m,k2P,dsqrt_mo_k2pqP_m,k)*part12r;
thrust::complex<double> integrand;
integrand=part11+part12;
return integrand.real();
This works fine(can be calculated by MC at least and does not return NaN)
But without some local variables:
integrand =-DWEn(k,omegaIn,"c","c","c","v",k,k2P,dsqrt_mo_k2pqP_m,dsqrt_mo_kqP_p)*(-(FDEl_k2P*FDHo_dsqrt_mo_kqP_p) + FDEl_dsqrt_mo_k2pqP_m*(-1 + FDEl_k2P +FDHo_dsqrt_mo_kqP_p))*VPG_qP+DWEn(k,omegaIn,"c","v","v","v",dsqrt_mo_kqP_m,k2P,dsqrt_mo_k2pqP_m,k)*(-((-1 + FDEl_dsqrt_mo_kqP_m)*FDHo_k2P) + (FDEl_dsqrt_mo_kqP_m - FDHo_k2P)*FDHo(dsqrt_mo_k2pqP_m))*VPG_qP;
The integration returns NaN.
I can present other scenarios of strange behavior(the answer will be nan or not depends on the introducing of local variables). I do not understand a logic of how to work with huge product of real(double) and comlex(thrust::complex) valued functions.
I will be infinitely grateful for the help.