Running multiprocess applications from MATLAB

后端 未结 3 1048
臣服心动
臣服心动 2021-01-18 15:58

I\'ve written a multitprocess application in VC++ and tried to execute it with command line arguments with the system command from MATLAB. It runs, but only on one core ---

3条回答
  •  礼貌的吻别
    2021-01-18 16:43

    The question is how Matlab is affecting your app's behavior, since it's a separate process. I suspect Matlab is modifying environment variables in a manner that affects OMP, maybe because it uses OMP internally, and the process you are spawning from Matlab is inheriting this modified environment.

    Do a "set > plain.txt" from the command window where you're launching you app plain, and "system('set > from_matlab.txt')" from within Matlab, and diff the outputs. This will show you the differences in environment variables that Matlab is introducing. When I do this, this appears in the environment inherited from Matlab, but not in the plain command window's environment.

    OMP_NUM_THREADS=1 
    

    That looks like an OpenMP setting related to the function calls in your question. I'll bet your spawned app is seeing that and respecting it.

    I don't know why Matlab is setting it. But as a workaround, when you launch the app from Matlab, instead of calling it directly, call a wrapper .bat file that clears the OMP_NUM_THREADS environment variable, or sets it to a higher number.

提交回复
热议问题