Parallel Jacobi

In order to parallelize the Jacobi method we need to introduce to new MPI functions, namely MPIGather and MPIAllgather.

Here we present a parallel implementation of the Jacobi method without an explicit link to the diffusion equation. Let us go back to the plain Jacobi method and implement it in parallel.

//  Main program first
#include <mpi.h>

//  Omitted statements
int main(int argc, char * argv[]){
  int i,j, N = 20;
  double **A,*x,*q;
  int totalnodes,mynode;

  MPI_Init(&argc,&argv);
  MPI_Comm_size(MPI_COMM_WORLD, &totalnodes);
  MPI_Comm_rank(MPI_COMM_WORLD, &mynode);

  if(mynode==0){

  }
  ParallelJacobi(mynode,totalnodes,N,A,x,q,1.0e-14);
  if(mynode==0){
    for(int i = 0; i < N; i++)
      cout << x[i] << endl;

  }
  MPI_Finalize();
}