Running multiprocess applications from MATLAB

后端 未结 3 1052
臣服心动
臣服心动 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:25

    you have to execute in MATLAB command-line:

    setenv OMP_NUM_THREADS 4

    if you want to use 4 threads.

    0 讨论(0)
  • 2021-01-18 16:27

    Run the command outside of Matlab and see how many cores its using. There should be no difference running it from within Matlab because its just a call down to the operating system. IE. equivalent from running on command line.

    EDIT

    Ok odd, what do you get when you call feature('NumCores') ? What version of Matlab are you using?

    Does it help to enable this?

    Hosted by imgur.com

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题