/********************************************************** File: main.cc Description: Functions to find the minimum in an array that is split among the processes Author: Dana Vrajitoru Class: B424 Date: September 21, 2004 ***********************************************************/ #include #include #include #include #include using namespace std; #include "find_min.h" // The main function int main(int argc, char **argv) { double time; int proc_id, nb_proc; int *array, size, my_min; /* Initialize MPI */ MPI_Init (&argc, &argv); /* Get the rank of this process */ MPI_Comm_rank (MPI_COMM_WORLD, &proc_id); /* Get nb of processes */ MPI_Comm_size (MPI_COMM_WORLD, &nb_proc); srand(100 + 15*proc_id); /* Each process writes hello and then waits for all of the others */ Initialize_array(array, size, proc_id, nb_proc); time = MPI_Wtime(); my_min = Find_min(array, size); MPI_Barrier(MPI_COMM_WORLD); Find_global_min(my_min, proc_id, nb_proc); time = MPI_Wtime() - time; if (proc_id==0) cout << "This program has run on " << nb_proc << " processes in " << time << " seconds." << endl; /* Finalize MPI */ MPI_Finalize (); return 0; } // End of the program