user3112193
user3112193

Reputation: 25

MPI how to decide how many processes we create

I want to write a program in C which will have a file as an input and inside this file the matrix of NxM size will be defined. So in my MPI program I would like to have N*M processes for every cell of the matrix.

I will be using makefile and hosts file to run this program

run:

    mpirun --hostfile ${HOSTFILE} ./${TARGET}

I have searched internet and stackoverflow, but in vain, so could you please explain me how to achieve it?

Upvotes: 0

Views: 956

Answers (2)

Stan Graves
Stan Graves

Reputation: 6955

In general terms, the MPI implementation will need "a priori" knowledge of the total number of ranks that need to be started BEFORE the ranks are actually started. This requirement precludes the use of rank 0 to read an input file and determine the number of ranks at run-time.

In practical terms, the number of ranks must be known at the time mpirun is invoked (I am leaving aside the spawn and connect/accept paths for now). The specific syntax for starting more than one rank per entry in the hostfile is implementation dependent. Refer to the supplied documentation for more.

The two "obvious" choices are to:

  1. Manually examine each input file and note the NxM size (perhaps in the filename) before invoking the mpirun command.
  2. Have the "script" examine the file (either directly, or with a "helper" program derived from the application code), determine the NxM size, and format the appropriate mpirun command.

"Spawn" is another possible solution, but will tend to add a LOT of complication to the overall solution. Overall, the simple brute force methods listed above are preferable.

Upvotes: 1

Hrushikesh Kulkarni
Hrushikesh Kulkarni

Reputation: 301

You could read the number of rows and columns from the file by writing a small bash script, then use it in your makefile.

Upvotes: 0

Related Questions