HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
MPIGetArrayDatanD.c
Go to the documentation of this file.
1 
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <basic.h>
9 #include <arrayfunctions.h>
10 #include <mpivars.h>
11 
22  double *xbuf,
23  double *x,
24  int *source,
25  int *dest,
26  int *limits,
28  int *dim,
29  int ghosts,
30  int ndims,
31  int nvars,
32  void *m
33  )
34 {
35  MPIVariables *mpi = (MPIVariables*) m;
36  int d;
37 
38  int source_rank = MPIRank1D(ndims,mpi->iproc,source);
39  int dest_rank = MPIRank1D(ndims,mpi->iproc,dest );
40 
41  int is[ndims], ie[ndims], index[ndims], bounds[ndims], size;
42  size = 1;
43  for (d=0; d<ndims; d++) {
44  is[d] = limits[2*d ];
45  ie[d] = limits[2*d+1];
46  size *= (ie[d] - is[d]);
47  }
48  _ArraySubtract1D_(bounds,ie,is,ndims);
49 
50  if (source_rank == dest_rank) {
51  /* source and dest are the same process */
52  int done = 0; _ArraySetValue_(index,ndims,0);
53  while (!done) {
54  int p1; _ArrayIndex1D_(ndims,bounds,index,0,p1);
55  int p2; _ArrayIndex1DWO_(ndims,dim,index,is,ghosts,p2);
56  _ArrayCopy1D_((x+nvars*p2),(xbuf+nvars*p1),nvars);
57  _ArrayIncrementIndex_(ndims,bounds,index,done);
58  }
59  } else {
60 #ifdef serial
61  fprintf(stderr,"Error in MPIGetArrayDatanD(): This is a serial run. Source and ");
62  fprintf(stderr,"destination ranks must be equal. Instead they are %d and %d.\n",
63  source_rank,dest_rank);
64  return(1);
65 #else
66  if (mpi->rank == source_rank) {
67  double *buf = (double*) calloc (size*nvars, sizeof(double));
68  int done = 0; _ArraySetValue_(index,ndims,0);
69  while (!done) {
70  int p1; _ArrayIndex1D_(ndims,bounds,index,0,p1);
71  int p2; _ArrayIndex1DWO_(ndims,dim,index,is,ghosts,p2);
72  _ArrayCopy1D_((x+nvars*p2),(buf+nvars*p1),nvars);
73  _ArrayIncrementIndex_(ndims,bounds,index,done);
74  }
75  MPI_Send(buf,size*nvars,MPI_DOUBLE,dest_rank,2211,mpi->world);
76  free(buf);
77  } else if (mpi->rank == dest_rank) {
78  MPI_Status status;
79  MPI_Recv(xbuf,size*nvars,MPI_DOUBLE,source_rank,2211,mpi->world,&status);
80  } else {
81  fprintf(stderr,"Error in MPIGetArrayData3D(): Process %d shouldn't have entered this function.\n",
82  mpi->rank);
83  return(1);
84  }
85 #endif
86  }
87  return(0);
88 }
89 
MPI related function definitions.
Some basic definitions and macros.
#define _ArraySubtract1D_(x, a, b, size)
int MPIRank1D(int, int *, int *)
Definition: MPIRank1D.c:26
int MPIGetArrayDatanD(double *xbuf, double *x, int *source, int *dest, int *limits, int *dim, int ghosts, int ndims, int nvars, void *m)
MPI_Comm world
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ArrayIndex1DWO_(N, imax, i, offset, ghost, index)
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
Structure of MPI-related variables.
#define _ArrayCopy1D_(x, y, size)
Contains macros and function definitions for common array operations.