MUHAMMAD ALI LAB 3
02-235162-021
PARALLEL PROGRAMMING
TASK 1: Execute and study the above sample code and display the output. Code: #include ; #include <mpi.h>; using namespace std; int main(int argc, char** argv) { int mynode, totalnodes; MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &totalnodes); MPI_Comm_rank(MPI_COMM_WORLD, &mynode); cout << "Hello world from process " << mynode; cout << " of " << totalnodes << endl; MPI_Finalize(); std::getchar(); } OUTPUT:
TASK2:
MUHAMMAD ALI LAB 3
02-235162-021
PARALLEL PROGRAMMING
Write a program find whether a process is an even process or an odd process. Code: #include ; #include <mpi.h>; using namespace std; int main(int argc, char** argv) { int mynode, totalnodes; MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &totalnodes); MPI_Comm_rank(MPI_COMM_WORLD, &mynode); cout << "Hello world from process " << mynode; cout << " of " << totalnodes << endl; if (mynode %2 == 0) { cout << "process is even"; } else { cout << "processor is odd"; } MPI_Finalize(); std::getchar(); } OUTPUT:
MUHAMMAD ALI LAB 3
02-235162-021
PARALLEL PROGRAMMING