Poor raytrace performance in Matlab standalone application.

  • 14 April 2020
  • 1 reply
  • 80 views

Hello, we are doing some analysis where I modify a scene and do a raytrance and than read the data back to matlab. All is working fine with the ZOS-api. But I notices that if I do the raytrace in zemax it takes about 20 seconds, in matlab with the same file the


"NSCRayTrace.RunAndWaitForCompletion();"

takes 75 seconds.

If I run the raytrace in Zemax with only one core it takes about 60 seconds. 

Watching the Task Manager in windows looks like only one core is working if matlab calls the raytrace command. 



Even if I set the


"NSCRayTrace.NumberOfCores = 4;" 

variable. Right now we don't have the matlab parallel processing toolbox, could be this the issue and would buying the toolbox solve the performance problem? 




1 reply

Userlevel 6
Badge +2
Hello Andreas



Sorry for the delay in answering.

My guess would be that the raytrace in Matlab should be as fast as the raytrace in OpticStudio. OpticStudio is the one handling the multi-threading. Then what can be longer is how you read the data back in Matlab. Just in case you haven't seen it, one of my colleague has worked on a DLL to fasten the reading in Matlab: Batch Processing of Ray Trace Data using ZOS-API in MATLAB



So back to the ray-tracing, I ran a simple test. I run a raytracing on the sample file \Non-sequential\Miscellaneous\Digital_projector_flys_eye_homogenizer.zmx'. I just ran a test using the sample file "\Zemax\ZOS-API Sample Code\MATLAB\MATLABStandalone_02_NSC_ray_trace.m" and added a tic toc command to measure the time.



 
    % Run ray trace
tic;
NSCRayTrace.RunAndWaitForCompletion();
NSCRayTrace.Close();
%! [e02s02_m]
toc;
elapsedTime = toc

   



Matlab gives 5.6161 seconds.



Then I ran the same test in OpticStudio:

- all cores (12): 5.2 seconds

- one core : 21 seconds



So to me this looks correct.

Would you mind checking the same example on your computer and see how it behaves? It may give us a clue whether the issue comes from a setting or the file itself.



Thank you!



Sandrine

Reply