#include #include "mpi.h" using namespace std; int main() { const int factor = 5; int error_number; int this_process_number; int number_of_processes; int n; int i, j, k; int start; int end; int recv_start; MPI_Status* status; int* x; const void* sbuf; void* rbuf; MPI_Init(NULL, NULL); MPI_Comm_size(MPI_COMM_WORLD, &number_of_processes); MPI_Comm_rank(MPI_COMM_WORLD, &this_process_number); n = number_of_processes * factor; x = new int[n]; if (this_process_number == 0) { for (i = 0; i < n; i++) { x[i] = 0; cout << i << " " << x[i] << endl; } } start = (factor * this_process_number); end = (factor * this_process_number) + (factor - 1) ; cout << this_process_number << " " << start << " " << end << endl; for ( i = start ; i <= end ; i++) x[i] = (i+1) * factor; if (this_process_number == 0) { for (i = 1; i < number_of_processes; i++) { recv_start = (factor * i) ; rbuf = &x[recv_start]; MPI_Recv(rbuf, factor, MPI_INT, i, 1, MPI_COMM_WORLD, status); } } else { sbuf = &x[start]; MPI_Send(sbuf, factor, MPI_INT, 0, 1, MPI_COMM_WORLD); } if (this_process_number == 0) { for (i = 0; i < n; i++) cout << " i " << i << " factor " << factor << " x[i] " << x[i] << endl; } MPI_Finalize(); return(0); }