|
General MPI Program Structure
MPI include header file #include "mpi.h"
...
Initialize MPI environment
...
Main coding and Message Passing calls
...
Terminate MPI environment
|
Major Environment Management Routines
MPI_Init (&argc,&argv)
MPI_Comm_size (comm,&size)
MPI_Comm_rank (comm,&rank)
MPI_Abort (comm,errorcode)
MPI_Get_processor_name (&name,&resultlength)
MPI_Finalize ()
Environment Management Routines Example
#include "mpi.h"
#include <stdio.h>
int main(argc,argv)
int argc;
char *argv[]; {
int numtasks, rank, rc;
char processor_name[MPI_MAX_PROCESSOR_NAME];
int namelen;
rc = MPI_Init(&argc,&argv);
if (rc != MPI_SUCCESS) {
printf ("Error starting MPI program. Terminating.\n");
MPI_Abort(MPI_COMM_WORLD, rc);
}
MPI_Comm_size(MPI_COMM_WORLD,&numtasks);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
MPI_Get_processor_name(processor_name,&namelen);
printf ("Number of tasks= %d My rank= %d My processor name=%s\n", numtasks,rank ,processor_name);
/******* do some work *******/
MPI_Finalize();
}
|
|
|