dano
dano

Reputation: 21

How to make/configure an MPI project to run on multiple processes?

I have a small piece of code that should run on multilple processes, which is :

  #include <stdio.h>
  #include "mpi.h"

  main(int argc, char **argv)
  {
  int ierr, num_procs, my_id;

  ierr = MPI_Init(&amp;argc, &amp;argv);

  /* find out MY process ID, and how many processes were started. */

  ierr = MPI_Comm_rank(MPI_COMM_WORLD, &amp;my_id);
  ierr = MPI_Comm_size(MPI_COMM_WORLD, &amp;num_procs);

  printf("Hello world! I'm process %i out of %i processes\n",
     my_id, num_procs);

  ierr = MPI_Finalize();
  }

the output is : Hello world! I'm process 0 out of 1 processes. although it should run on more than one process

We edited the run configurations arguments to "-np 2" so it would run on 2 processes but it always gives us 1 process no matter what the value is.

The used environment is: Eclipse Juno on Ubuntu 12.04

Source of code: http://condor.cc.ku.edu/~grobe/docs/intro-MPI-C.shtml[^]

Upvotes: 0

Views: 6117

Answers (2)

TonySalimi
TonySalimi

Reputation: 8427

Some small points about mpirun or mpiexec commands:

If you are trying to run you app on multiple nodes, make sure that your app is copied to all the nodes.In addition, make sure that all needed binary files (executable & libraries) could be found directly from command line. I personally, prefer to run my MPI programs within a shell script like this:

#!/bin/sh
PATH=/path/to/all/executable/files \
LD_LIBRARY_PATH=/path/to/all/libraries \
mpirun -np 4 ./my_app  arg1 arg2 arg3 

Upvotes: 0

suszterpatt
suszterpatt

Reputation: 8273

It seems that you are trying to launch your MPI application directly, i.e. starting the compiled executable with -np 2, like this:

$ ./my_app -np 2

That's not the right way of launching MPI programs. Instead, you should call your MPI implementation's launcher (usually named mpirun or mpiexec), and pass the name of your executable and -np 2 to that. So if your executable is called my_app, then instead of the above command, you should run:

$ mpirun -np 2 ./my_app

Consult your MPI implementation's documentation for the specifics.

Upvotes: 3

Related Questions