/* Solution of hw1 with MPI */ #include "mpi.h" #include "math.h" #include /* All this is part of the student's work */ void power_distribute(double *A, double *b, long n); void power_method(long k); double power_answer(void); int main(int argc, char *argv[]) { int i=0, n=4; int rank, size, allocated; double *A, *b, norm_b; long my_chunk; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); /* Create the matrix on the first node */ if (0 == rank){ allocated = size*(ceil((1.0*n)/size)); A = (double *) malloc (allocated * n * sizeof(double)); b = (double *) malloc (allocated * sizeof(double)); if (NULL == A || NULL == b){ printf ("Rank 0 has a problem with allocating memory\n"); MPI_Finalize(); return 0; } for (i=0; i