I have a personal work to complete in C programming language

profilekittu_unadu
MPI-01.tar.gz

MPI-01/Ring-Pass/Ring-Pass-3/Ring-Example-3.c

//////////////////////////////////////////////////////////////// // // This is our third version of ring pass program in MPI // // Compile: mpicc Ring-Example-3.c -o Ring-Example-3 // // Run: mpiexec -n <p> ./Ring-Example-3 // // -p: the number of processes // /////////////////////////////////////////////////////////////// #include <stdio.h> #include <stdlib.h> #include <string.h> #include <mpi.h> int main(void) { char Greeting[100]; int comm_sz, my_rank; MPI_Init(NULL, NULL); MPI_Comm_size(MPI_COMM_WORLD, &comm_sz); MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); if (my_rank == 0) { sprintf(Greeting, "Greeting from process %d!", my_rank); MPI_Send(Greeting, strlen(Greeting) + 1, MPI_CHAR, 1, 0, MPI_COMM_WORLD); /* print out the message */ printf("Process %d sent the message > %s < to process %d\n", my_rank, Greeting, my_rank + 1); MPI_Recv(Greeting, 100, MPI_CHAR, comm_sz - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); printf("Process %d received: %s \n", my_rank, Greeting); } else if (my_rank == comm_sz - 1) { MPI_Recv(Greeting, 100, MPI_CHAR, my_rank - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); MPI_Send(Greeting, strlen(Greeting) + 1, MPI_CHAR, 0, 0, MPI_COMM_WORLD); /* print out the message */ printf("Process %d sent the message > %s < to process %d\n", my_rank, Greeting, 0); } else { MPI_Recv(Greeting, 100, MPI_CHAR, my_rank - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); MPI_Send(Greeting, strlen(Greeting) + 1, MPI_CHAR, my_rank + 1, 0, MPI_COMM_WORLD); /* print out the message */ printf("Process %d sent the message > %s < to process %d\n", my_rank, Greeting, my_rank + 1); } MPI_Finalize(); return 0; }

MPI-01/Ring-Pass/Ring-Pass-2/Ring-Assignment-2.c

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <mpi.h> int main(void) { char Greeting[100]; int comm_sz, my_rank; MPI_Init(NULL, NULL); MPI_Comm_size(MPI_COMM_WORLD, &comm_sz); MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); sprintf(Greeting, "Greeting from process %d!", my_rank); MPI_Send(&Greeting, strlen(Greeting) + 1, MPI_CHAR, (my_rank + 1) % comm_sz, 0, MPI_COMM_WORLD); if (my_rank != 0) { } else { } MPI_Finalize(); return 0; }

MPI-01/Ring-Pass/Ring-Pass-2/Ring-Example-2.c

///////////////////////////////////////////////////////////////// // // This is our second version of ring pass program in MPI // // Compile: mpicc Ring-Example-2.c -o Ring-Example-2 // // Run: mpiexec -n <p> ./Ring-Example-2 // // -p: the number of processes // /////////////////////////////////////////////////////////////// #include <stdio.h> #include <stdlib.h> #include <string.h> #include <mpi.h> int main(void) { char Greeting[100]; int comm_sz, my_rank; MPI_Init(NULL, NULL); MPI_Comm_size(MPI_COMM_WORLD, &comm_sz); MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); // The function 'sprintf' is very similar to the function 'print', except that // instead of writing to stdout, it writes to a string. sprintf(Greeting, "Greeting from process %d!", my_rank); MPI_Send(Greeting, strlen(Greeting) + 1, MPI_CHAR, (my_rank + 1) % comm_sz, 0, MPI_COMM_WORLD); /* print out the message */ printf("Process %d sent message to process %d\n", my_rank, (my_rank + 1) % comm_sz); if (my_rank == 0) { MPI_Recv(Greeting, 100, MPI_CHAR, comm_sz - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); /* print out the message */ printf("Process %d received message: %s\n", my_rank, Greeting); } else { MPI_Recv(Greeting, 100, MPI_CHAR, my_rank - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); /* print out the message */ printf("Process %d received message: %s\n", my_rank, Greeting); } MPI_Finalize(); return 0; }

MPI-01/Ring-Pass/Ring-Pass-1/Ring-Assignment-1.c

#include <stdio.h> #include <stdlib.h> #include <mpi.h> int main(void) { int comm_sz, my_rank; MPI_Init(NULL, NULL); MPI_Comm_size(MPI_COMM_WORLD, &comm_sz); MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); int token = 1; MPI_Send(&token, 1, MPI_INT, (my_rank + 1) % comm_sz, 0, MPI_COMM_WORLD); if (my_rank == 0) MPI_Recv(&token, 1, MPI_INT, comm_sz - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); else MPI_Recv(&token, 1, MPI_INT, my_rank - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); MPI_Finalize(); return 0; }

MPI-01/Ring-Pass/Ring-Pass-1/Ring-Example-1.c

///////////////////////////////////////////////////////////////// // // This is our first version of ring pass program in MPI // // Compile: mpicc Ring-Example-1.c -o Ring-Example-1 // // Run: mpiexec -n <p> ./Ring-Example-1 // // -p: the number of processes // /////////////////////////////////////////////////////////////// #include <stdio.h> #include <stdlib.h> #include <mpi.h> int main(void) { int comm_sz, my_rank; MPI_Init(NULL, NULL); MPI_Comm_size(MPI_COMM_WORLD, &comm_sz); MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); int token = 1; MPI_Send(&token, 1, MPI_INT, (my_rank + 1) % comm_sz, 0, MPI_COMM_WORLD); if (my_rank == 0) { MPI_Recv(&token, 1, MPI_INT, comm_sz - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); /* print out the message */ printf("Process %d received token value < %d > from process %d\n", my_rank, token, comm_sz - 1); } else { MPI_Recv(&token, 1, MPI_INT, my_rank - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); /* print out the message */ printf("Process %d received token value < %d > from process %d\n", my_rank, token, my_rank - 1); } MPI_Finalize(); return 0; }

MPI-01/Hello-World/MPI-Hello.c

//////////////////////////////////////////////////////////////// // // This is a simple hello world program in MPI // // Compile: mpicc Hello-World.c -o Hello-World // // Run: mpiexec -n <p> ./Hello-World // // -p: the number of processes // /////////////////////////////////////////////////////////////// #include <stdio.h> #include <stdlib.h> #include <mpi.h> int main(void) { int comm_sz, my_rank; MPI_Init(NULL, NULL); MPI_Comm_size(MPI_COMM_WORLD, &comm_sz); MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); /* print out the message */ printf("Hello from process %d of %d\n", my_rank, comm_sz); MPI_Finalize(); return 0; }

MPI-01/Send-Receive/Send-Receive.c

//////////////////////////////////////////////////////////////// // // This is a simple send/receive program in MPI // // Compile: mpicc Send-Receive.c -o Send-Receive // // Run: mpiexec -n 2 ./Send-Receive // /////////////////////////////////////////////////////////////// #include <stdio.h> #include <stdlib.h> #include <mpi.h> int main(void) { int my_rank, comm_sz; int token = 1; MPI_Init(NULL, NULL); MPI_Comm_size(MPI_COMM_WORLD, &comm_sz); MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); if(my_rank == 0) { MPI_Send(&token, 1, MPI_INT, 1, 0, MPI_COMM_WORLD); printf("Process %d sent token %d to process 1\n", my_rank, token); } else { MPI_Recv(&token, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); printf("Process %d received token %d from process 0\n", my_rank, token); } MPI_Finalize(); return 0; }