When I attempt to call a parallelized executable with MATLAB's dos()
command, it won't run the executable and returns an error.
On its own, this simple C++ program runs exactly as you would expect:
/* Serial.exe */
#include <iostream>
int main(void) {
std::cout << "Apple!\n";
std::cout << "Banana!\n";
return 0;
}
Result:
Apple!
Banana!
So does this one:
/* Parallel */
#include <iostream>
#include <omp.h>
int main(void) {
std::cout << "Apple!\n";
#pragma omp parallel num_threads(8)
{
std::cout << "Banana!\n";
}
return 0;
}
Result:
Apple!
Banana!
Banana!
Banana!
Banana!
Banana!
Banana!
Banana!
Banana!
Now, I try to call both of these programs with the following MATLAB script:
%% MATLAB call script
exe_path_1 = 'C:\\Users\\Jim\\Documents\\MATLAB\\Serial.exe';
exe_path_2 = 'C:\\Users\\Jim\\Documents\\MATLAB\\Parallel.exe';
rtn_1 = dos(exe_path_1)
rtn_2 = dos(exe_path_2)
Result:
Apple!
Banana!
rtn_1 = 0
rtn_2 = -1.0737e+09
What is it about MATLAB's dos()
command that causes my parallel C++ code to fail?
I fixed a similar issue calling the command via java. Here is some m-code which uses the java classes:
rt = java.lang.Runtime.getRuntime();
pr = rt.exec(command);
input= java.io.BufferedReader(java.io.InputStreamReader(pr.getInputStream()));
while(1)
f=(input.readLine());
if isempty(f)
break;
end
disp(char(f));
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With