nonlinear equations solver (cminpack) application in Optix

At the moment, I’m working on temperature calculation of ground. Ground temperature is affected significantly by the solar irradiance and some other
environment conditions. To solve the problem, Optix seems to be a good choice, because of its parallel characteristics and shadow judgement.
As you know, to get the temperature, a system of nonlinear equations should be solved. However, cuBLAS can only be applied to linear equations, in order to solve nonlinear equations, CMINPACK is a good choice, and I have tested the feasibility with cuda, it works will. Then, CMINPACK is introduced
into Optix, unfortunately, a big problem appeared.
In ray generation program, a shadow ray will be used to determine whether somewhere is in the shadow sun, than I will use CMINPACK to solve the nonlinear equations. The shadow ray tracing is like this:

Shadow_Ray_Load sh_prd;
sh_prd.attenuate=0;//1,shadow.0, out of shadow
optix::Ray shadow_ray=make_Ray(center_vertex,sun_dir,0,1.e-2.f,1.e10.f);//just need 1 type of ray,0,shadow ray
rtTrace(top_object,shadow_ray,sh_prd);
attenuate=sh_prd.attenuate; 
rtPrintf("attenate=%d\n",attenuate);
CMINPACK nonlinear equations solver
tol = sqrt(__cminpack_func__(dpmpar)(1));
info = __cminpack_func__(hybrd1)(__cminpack_param_fcn_nn__ &packet, n, Temp, fvec, tol, wa, lwa);

Problem:
I found ray-tracing can not excute normally if cminpack_func(hybrd1) function exists, why can I know the rtTrace don’t give right result? because the statement(rtPrintf) didn’t excute. however if I comment the nonlinear equations solver, rtTrace will works well.

//info = __cminpack_func__(hybrd1)(__cminpack_param_fcn_nn__ &packet, n, Temp, fvec, tol, wa, lwa);

I do not understand what’s wrong with it. Is there anyone have any idea? Or you can give me some suggestion about how to solve nonlinear equations with
other toolkit.
Look forward your answers.
Best regard.

You cannot call arbitrary CUDA functions from an OptiX kernel.

Do you absolutely need to solve the non-linear equations inside the OptiX ray tracing kernel?
I also need sophisticated calculations, but they are NOT run within OptiX but rather use the output buffers which were filled by OptiX.

Simply put, I first launch the OptiX kernel, then as a second step I launch a CUDA kernel which reads the OptiX results and produces the final results.

I agree with this whole comment, and I do the same. maxli, you should limit what’s being done in OptiX to only what requires ray tracing. There are optimizations that OptiX applies to your kernels that may introduce errors in complex code, among other issues.

Thank you, @m_sch and @over0219.
You really give me a good suggestion, according to what you have said, I separate the raytracing program and nonlinear calculation. Now it works well.
Another point I’d like to make is that cminpack can be applied in Optix, it is a good supplement for the lack of nonlinear equations solver in CUDA and Optix.