Parallel-Port-Example-Computer-Science-2004-7-7-The-Point-Jacobi-Iteration - PRG Örnekleri
Parallel-Port-Example-Computer-Science-2004-7-7-The-Point-Jacobi-Iteration - PRG Örnekleri
If we want to solve T for [1000, 1000] points, the grid itself needs to be of
dimension 1002 x 1002; since the algorithm to calculate T9i,j) requires
values of T at I-1, I+1, j-1, and j+1.
C:
#include "mpi.h"
/* Initialization and clean up (always check error codes): */
Parallel version:
Just for simplicity, we will distribute rows in C and columns in Fortran; this is easier because data
is stored in rows C and in columns Fortran.
We need to know MYPE number and how many PEs we are using.
Each processor will work on different data depending on MYPE.
Here are the boundary conditions in the serial code, where
NRL-local number of rows, NRL=NPROC
We need to know MYPE number and how many PEs we are using. Each processor will work on
different data depending on MYPE.
Here are the boundary conditions in the serial code, where
NRL=local number of rows, NRL=NR/NPROC
Here number of elements is how many values we are passing, in this case
only one: niter.
C:
Send values up
This is where we use MPI communication calls: need to exchange data between processors
Receive values from above
Synchronize
Example: PE1 receives 2 messages – there is no guarantee of the order in which they will be
received.
April 24, 2002
Parallel Template (C)
if ( mype != 0 ){
up = mype - 1
MPI_Send( t, NC, MPI_FLOAT, up, UP_TAG, comm, ierr
); }
Alternatively
up = mype - 1
if ( mype == 0 ) up = MPI_PROC_NULL;
MPI_Send( t, NC, MPI_FLOAT, up, UP_TAG, comm,ierr );
2. These are template files; your job is to go into the sections marked "<<<<<<" in the source code
and add the necessary statements so that the code will run on 4 PEs.
laplace_mpi_f.f