Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a parallelized executable with MATLAB 'dos' command behaves differently from the standalone executable

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?

like image 850
Jim Avatar asked Jun 19 '14 16:06

Jim


1 Answers

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
like image 149
Daniel Avatar answered Sep 29 '22 09:09

Daniel