It is necessary to run a prog using the mpi command line a large number of times in a loop to calculate the average time to complete it. To do this, we will create a separate C ++ program (not mpi), in which the command line with commands will be called in the loop

cd C:\Program Files\MPICH2\bin 

and then you need to betray this command line

 mpiexec -n количество процессов путь к mpi-проге 

(within which there will be a measurement of its time by means of mpi). What are the commands in C ++ for this?

  • 1. Such things are easier to do through shell scripts. 2. So which line should the console get? I did not understand something. - skegg
  • Two lines: - first cd C:\Program Files\MPICH2\bin - and then mpiexec -n количество процессов путь к mpi-проге program - ivan89

4 answers 4

First you want to change the current directory. It is better to do this with C ++ methods. In unixes, there is a chdir () system call for this. There is probably something similar in Windows too. Look for it.

Then you want to run mpiexec and pass several parameters to it. This can be done by several methods.

  1. use system (). If you want to change the -n parameter, you can form a string either using the string class or in the C style using sprintf ().
  2. Using _popen (). It returns a pointer to FILE, from which you can read what the executable program sends to stdout.
  3. Using API functions like exec.

PS You can change the current directory using the _chdir () function

     #include <stdlib.h> int system(const char *command); 

    Will not work? In general, such things are not found in C / C ++, but in the system used. If you need troubles with paths, I / O redirection - then you need to look at the system API (in this case, as I understand it, this is Windows). About two commands - like cmd.exe allows them to be written together, using ";"

    • After executing the mpi-program, the line C:\Program Files\MPICH2\bin appears in the console. How can I read it? If there are links to these commands, then put them in response. - ivan89 4:08
    • Try popen () - skegg
    • In the Windows at least work pipe. programm1 | programm2 | programm2 > logfile.txt programm1 | programm2 | programm2 > logfile.txt - Majestio

    use CreateProcess

      Use the operating system tools. For example, the command shela - FOR. At the same time, it is quite possible to start both sequentially and in parallel (using the START keys).