Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <mpi.h>
- #include <stdio.h>
- #include <string>
- #include <iostream>
- using namespace std;
- int main(int argc, char** argv) {
- // Initialize the MPI environment
- MPI_Init(&argc, &argv);
- // Get the number of processes
- int world_size;
- MPI_Comm_size(MPI_COMM_WORLD, &world_size);
- // Get the rank of the process
- int world_rank;
- MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
- char processor_name[MPI_MAX_PROCESSOR_NAME];
- int name_len;
- MPI_Get_processor_name(processor_name, &name_len);
- //// Print off a hello world message
- //printf("Hello world from processor %s, rank %d out of %d processors\n",
- // processor_name, world_rank, world_size);
- switch (world_rank) {
- case 0: {
- int n = 123;
- MPI_Send(&n, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
- printf("The rank of the sending process: %d, The value being sent: %d\n", world_rank,n);
- break;
- }
- case 1: {
- int rec=2;
- cout << "Variable before receiving:" << rec << endl;
- MPI_Recv(&rec, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
- printf("The rank of the recipient process: %d, Variable after receiving: %d\n", world_rank, rec);
- break;
- }
- default: {
- break;
- }
- }
- // Finalize the MPI environment.
- MPI_Finalize();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement