The FARGO_THORIN code developer's guide
 All Data Structures Files Functions Variables Typedefs Macros
mpiTasks.c
Go to the documentation of this file.
1 /** \file mpiTasks.c
2  *
3  * Contains the function to create a 1D azimuthally-averaged
4  * array from a polar array. Works also for a MPI-split
5  * grid.
6  *
7  * @author Taken from FARGO-ADSG by ClĂ©ment Baruteau.
8  * */
9 
10 #include "fargo.h"
11 
12 void mpi_make1Dprofile (gridfield, axifield)
13  real* gridfield;
14  real* axifield;
15 {
16  MPI_Request req1;
17  int i, j, l;
18  real *localaxifield;
19  localaxifield = (real*) malloc(sizeof(real) * NRAD);
20  if ( localaxifield == NULL ) {
21  mastererr ("Error: Not enough memory in mpi_make1Dprofile().");
22  prs_exit (1);
23  }
24  for ( i = 0; i < NRAD; i++ )
25  localaxifield[i] = 0.;
26  for (i = Zero_or_active; i < Max_or_active; i++) {
27  for( j = 0; j < NSEC; j++ ) {
28  l = i*NSEC + j;
29  localaxifield[i] += gridfield[l];
30  }
31  localaxifield[i] /= (real)NSEC;
32  }
33  if ( CPU_Number == 1 ) {
34  for ( i = 0; i < GLOBALNRAD; i++ )
35  axifield[i] = localaxifield[i];
36  }
37  if ( CPU_Number > 1 ) {
38  if ( CPU_Rank == 0 ) {
39  for ( i = 0; i < GLOBALNRAD; i++ ) {
40  if ( i < Max_or_active )
41  axifield[i] = localaxifield[i];
42  else
43  axifield[i] = 0.;
44  }
45  MPI_Isend (axifield, GLOBALNRAD, MPI_DOUBLE, CPU_Rank+1, 0, MPI_COMM_WORLD, &req1);
46  MPI_Wait (&req1, &fargostat);
47  }
48  if ( CPU_Rank != 0 ) {
49  MPI_Irecv (axifield, GLOBALNRAD, MPI_DOUBLE, CPU_Rank-1, 0, MPI_COMM_WORLD, &req1);
50  MPI_Wait (&req1, &fargostat);
51  for (i = Zero_or_active; i < Max_or_active; i++)
52  axifield[i+IMIN] = localaxifield[i];
53  if ( CPU_Rank != (CPU_Number - 1) ) {
54  MPI_Isend (axifield, GLOBALNRAD, MPI_DOUBLE, CPU_Rank+1, 0, MPI_COMM_WORLD, &req1);
55  MPI_Wait (&req1, &fargostat);
56  }
57  }
60  }
61  free (localaxifield);
62 }
double real
Definition of the type 'real' used throughout the code.
Definition: types.h:20
MPI_Status fargostat
Definition: global.h:32
int CPU_Number
Definition: global.h:2
#define MPI_DOUBLE
Definition: mpi_dummy.h:11
int Zero_or_active
Definition: global.h:6
void MPI_Barrier()
Definition: mpi_dummy.c:64
int IMIN
Definition: global.h:4
int GLOBALNRAD
Definition: global.h:10
void MPI_Irecv()
Definition: mpi_dummy.c:52
int NSEC
Definition: param_noex.h:19
int Max_or_active
Definition: global.h:7
void MPI_Isend()
Definition: mpi_dummy.c:48
void mastererr(const char *template,...)
Definition: LowTasks.c:49
int MPI_Request
Definition: mpi_dummy.h:19
int NRAD
Definition: param_noex.h:18
Contains all the include directives requested by the code.
int CPU_Rank
Definition: global.h:1
void MPI_Wait()
Definition: mpi_dummy.c:68
void mpi_make1Dprofile(real *gridfield, real *axifield)
Definition: mpiTasks.c:12
#define MPI_COMM_WORLD
Definition: mpi_dummy.h:10
void prs_exit(int numb)
Definition: LowTasks.c:33
void MPI_Bcast()
Definition: mpi_dummy.c:44