//Coolapse Program // p. 28 Tutorial slides #include #include "mpi.h" #include int main(int argc, char **argv) { int numbers[1000]; int slice=10; int* sliceArr; int rank, size, newint; int count = 0; int temp, x, sum, totalsum=0; int N, K; FILE* in; // int *ptr; MPI_Init(&argc, &argv); MPI_Comm_rank( MPI_COMM_WORLD, &rank ); MPI_Comm_size( MPI_COMM_WORLD, &size ); K = size; N = 12; slice = size; sliceArr = (int* )malloc(sizeof(int) * size); if (rank == 0) { if ((in = fopen("numbers12", "r")) == NULL) { printf("Error opening file\n"); exit(0); } while (fscanf(in, "%d", &temp) != EOF) { numbers[count]=temp; count++; printf("Count %d, value= %d\n", count, temp); } fclose(in); } MPI_Scatter(numbers, N/K, MPI_INT, sliceArr, N/K, MPI_INT, 0, MPI_COMM_WORLD); sum = 0; printf("Node %d, Slice:\n", rank); for (x=0; x 9) newint = (newint/10) + (newint%10); sum = sum + newint; } printf(", Collapse = %d\n", sum); MPI_Reduce(&sum, &totalsum, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); if (rank == 0) { printf("Total sum = %d\n", totalsum); } MPI_Finalize(); return 0; } /*int MPI_Scatter ( void *sendbuf, int sendcnt, MPI_Datatype sendtype, void *recvbuf, int recvcnt, MPI_Datatype recvtype, int root, MPI_Comm comm ) Input Parameters -sendbuf address of send buffer (choice, significant only at root) -sendcount number of elements sent to each process (integer, significant only at root) -sendtype data type of send buffer elements (significant only at root) (handle) -recvcount number of elements in receive buffer (integer) -recvtype data type of receive buffer elements (handle) -root rank of sending process (integer) -comm communicator (handle) */