Presentation is loading. Please wait.

Presentation is loading. Please wait.

PP Lab MPI programming II. Program#1 Write a program that prints hello from every created process. Like: Hello World from process 0 of 5 Hello World from.

Similar presentations


Presentation on theme: "PP Lab MPI programming II. Program#1 Write a program that prints hello from every created process. Like: Hello World from process 0 of 5 Hello World from."— Presentation transcript:

1 PP Lab MPI programming II

2 Program#1 Write a program that prints hello from every created process. Like: Hello World from process 0 of 5 Hello World from process 1 of 5 Hello World from process 3 of 5 Hello World from process 2 of 5 Hello World from process 4 of 5

3 Communicators MPI_COMM_WORLD: Contains all of the processes MPI_COMM_SELF: Contains only the calling process

4 Functions to be used MPI_Comm_rank: Determines the rank of the calling process in the communicator Synopsis: #include "mpi.h" int MPI_Comm_rank(MPI_Comm comm, int *rank ) Input Parameters: – comm: communicator Output Parameter: – rank: rank of the calling process in group of comm

5 Functions to be used MPI_Comm_size: Determines the size of the group associated with a communicator Synopsis: #include "mpi.h" int MPI_Comm_size(MPI_Comm comm, int *size ) Input Parameter: – comm: communicator Output Parameter: – size: number of processes in the group of comm

6 Code #include main(int argc, char **argv){ int rank,size; MPI_Init(&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); printf("Hello World from %d of %d\n”,rank,size); MPI_Finalize(); }

7 Program#2 Write another program that has the same objective but it prints the name of node also. Like: Hello world from server Hello world from node1.

8 Function to be used MPI_Get_processor_name: Gets the name of the processor Synopsis: #include "mpi.h" int MPI_Get_processor_name(char *name, int *resultlen) Output Parameters: – name: A unique specifier for the actual node. This must be an array of size at least MPI_MAX_PROCESSOR_NAME. – resultlen: Length (in characters) of the name

9 Code #include main(int argc, char **argv){ int resultlen; char name[MPI_MAX_PROCESSOR_NAME]; MPI_Init(&argc,&argv); MPI_Get_processor_name(name, &resultlen); printf("Hello World from %s\n“,name); MPI_Finalize(); }


Download ppt "PP Lab MPI programming II. Program#1 Write a program that prints hello from every created process. Like: Hello World from process 0 of 5 Hello World from."

Similar presentations


Ads by Google