#include #include "mpi.h" #include #include int main(int argc, char** argv) { FILE *f; int dim; int res; int nprocs, rank; double* vector; int width; int nc; int i, j; int start, size; int proc, p2; double tmp; double* result; double* presult; double data; double time_start; double time_end; MPI_Status status; /** * Init */ res = MPI_Init(&argc, &argv); if (res != MPI_SUCCESS) { printf("Error.\n"); MPI_Abort(MPI_COMM_WORLD, res); return 2; } MPI_Comm_size(MPI_COMM_WORLD, &nprocs); MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (nprocs < 2) { if (rank == 0) { printf("Requires at least 2 procs.\n"); } MPI_Abort(MPI_COMM_WORLD, res); return 1; } time_start = MPI_Wtime(); /* * Read data */ f = fopen(argv[1], "r"); fscanf(f, "%d", &dim); if (rank == 0) { printf("Matrix dimension: %d\n", dim); } vector = (double*)malloc(sizeof(double) * dim); for (i=0; i= dim) { break; } } start = -1; while (proc < nprocs) { MPI_Send(&start, 1, MPI_INT, proc, 1, MPI_COMM_WORLD); proc++; } } else { MPI_Recv(&start, 1, MPI_INT, 0, 1, MPI_COMM_WORLD, &status); if (start > -1) { MPI_Recv(&size, 1, MPI_INT, 0, 1, MPI_COMM_WORLD, &status); printf("[%d] start=%d, size=%d\n", rank, start, size); /* * read data */ // skip first 'start' lines for (i=0; i