#include #include #include "mpi.h" int main (int argc, char *argv[]) { int ntasks_world, /* # of tasks in MPI_COMM_WORLD */ mytid, /* my task id */ namelen, /* length of processor name */ i; /* loop variable */ char processor_name[MPI_MAX_PROCESSOR_NAME]; MPI_Init (&argc, &argv); MPI_Comm_rank (MPI_COMM_WORLD, &mytid); MPI_Comm_size (MPI_COMM_WORLD, &ntasks_world); MPI_Get_processor_name (processor_name, &namelen); /* With the next statement every process executing this code will * print one line on the display. It may happen that the lines will * get mixed up because the display is a critical section. In general * only one process (mostly the process with rank 0) will print on * the display and all other processes will send their messages to * this process. Nevertheless for debugging purposes (or to * demonstrate that it is possible) it may be useful if every * process prints itself. */ fprintf (stdout, "Slave process %d of %d running on %s\n", mytid, ntasks_world, processor_name); fflush (stdout); MPI_Barrier (MPI_COMM_WORLD); /* wait for all other processes */ for (i = 0; i < argc; ++i) { printf ("%s %d: argv[%d]: %s\n", argv[0], mytid, i, argv[i]); } MPI_Finalize (); return EXIT_SUCCESS; }