从MATLAB运行多进程应用程序 [英] Running multiprocess applications from MATLAB
问题描述
我在VC ++中编写了一个多进程应用程序,并尝试使用 system
命令。它运行,但只有一个核心 - 任何建议?
更新:实际上,它甚至看不到第二个核心。我使用OpenMP并使用 omp_get_max_threads()
和 omp_get_thread_num()
检查和 omp_get_max_threads当我从MATLAB执行应用程序时,
似乎是
1
,但它 2
确认:
使用 Process Explorer 检查线程数是否有任何差异。
当我从命令窗口调用应用程序时, 1
线程转到 cmd。 exe
和 2
转到我的应用程序。
26
线程适用于 MATLAB.exe
, 1
code> cmd.exe 和 1
。
$ p
问题是Matlab是如何影响你的应用程序的行为,因为它是一个单独的过程。我怀疑Matlab正在以影响OMP的方式修改环境变量,也许是因为它在内部使用了OMP,而您从Matlab派生的进程正在继承此修改后的环境。
从命令窗口中执行一个set> plain.txt,您将在其中启动您的应用程序,和system('set> from_matlab.txt')从Matlab,并差异输出。这将显示Matlab介绍的环境变量的差异。当我这样做,这出现在继承自Matlab的环境中,但不是在纯命令窗口的环境中。
OMP_NUM_THREADS = 1
这看起来像一个与您的问题中的函数调用相关的OpenMP设置。我会打赌你生成的应用程序看到和尊重它。
我不知道为什么Matlab设置它。但是,作为解决方法,当您从Matlab启动应用程序,而不是直接调用它,调用一个包装器.bat文件,清除OMP_NUM_THREADS环境变量,或将其设置为更高的数字。
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 --- any suggestions?
Update:In fact, it doesn't even see the second core. I used OpenMP and used omp_get_max_threads()
and omp_get_thread_num()
to check and omp_get_max_threads()
seems to be 1
when I execute the application from MATLAB but it's 2
(as is expected) if I run it from the command window.
Question:My task manager reports that CPU usage is close to 100% --- could this mean that the aforementioned API is malfunctioning it's still running as a multiprocess application?
Confirmation:
I used Process Explorer to check if there were any differences in the number of threads.
When I call the application from the command window, 1
thread goes to cmd.exe
and 2
go to my application.
When I call it from MATLAB, 26
threads are for MATLAB.exe
, 1
for cmd.exe
and 1
for my application.
Any ideas?
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.
这篇关于从MATLAB运行多进程应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!