Skip to content

Commit

Permalink
Merge branch 'dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
evaneschneider authored Dec 12, 2023
2 parents cbf98ef + 977d04d commit e6fbb55
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
20 changes: 20 additions & 0 deletions src/global/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ int Sgn(Real x)
}
}

// global mpi-related variables (they are declared here because they are initialized even when
// the MPI_CHOLLA variable is not defined)

int procID; /*process rank*/
int nproc; /*number of processes in global comm*/
int root; /*rank of root process*/

/* Used when MPI_CHOLLA is not defined to initialize a subset of the global mpi-related variables
* that still meaningful in non-mpi simulations.
*/
void Init_Global_Parallel_Vars_No_MPI()
{
#ifdef MPI_CHOLLA
CHOLLA_ERROR("This function should not be executed when compiled with MPI");
#endif
procID = 0;
nproc = 1;
root = 0;
}

/*! \fn char Trim(char *s)
* \brief Gets rid of trailing and leading whitespace. */
char *Trim(char *s)
Expand Down
14 changes: 14 additions & 0 deletions src/global/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,20 @@ extern double Get_Time(void);
* \brief Mathematical sign function. Returns sign of x. */
extern int Sgn(Real x);

/* Global variables for mpi (but they are also initialized to sensible defaults when not using mpi)
*
* It may make sense to move these back into mpi_routines (but reorganizing the ifdef statements
* would take some work). It may make sense to also put these into their own namespace.
*/
extern int procID; /*process rank*/
extern int nproc; /*number of processes executing simulation*/
extern int root; /*rank of root process*/

/* Used when MPI_CHOLLA is not defined to initialize a subset of the global mpi-related variables
* that still meaningful in non-mpi simulations.
*/
void Init_Global_Parallel_Vars_No_MPI();

struct Parameters {
int nx;
int ny;
Expand Down
5 changes: 4 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ int main(int argc, char *argv[])
// start the total time
start_total = Get_Time();

/* Initialize MPI communication */
#ifdef MPI_CHOLLA
/* Initialize MPI communication */
InitializeChollaMPI(&argc, &argv);
#else
// Initialize subset of global parallelism variables usually managed by MPI
Init_Global_Parallel_Vars_No_MPI();
#endif /*MPI_CHOLLA*/

Real dti = 0; // inverse time step, 1.0 / dt
Expand Down
4 changes: 1 addition & 3 deletions src/mpi/mpi_routines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
#include "../utils/error_handling.h"

/*Global MPI Variables*/
int procID; /*process rank*/
int nproc; /*number of processes in global comm*/
int root; /*rank of root process*/
// note: some relevant global variables are declared in global.h

int procID_node; /*process rank on node*/
int nproc_node; /*number of MPI processes on node*/
Expand Down
6 changes: 3 additions & 3 deletions src/mpi/mpi_routines.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#endif /*FFTW*/

/*Global MPI Variables*/
extern int procID; /*process rank*/
extern int nproc; /*number of processes in global comm*/
extern int root; /*rank of root process*/
// NOTE: some variable heavily used by mpi are declared in global.h so that they are defined even
// when compiled without mpi

extern int procID_node; /*process rank on node*/
extern int nproc_node; /*number of MPI processes on node*/

Expand Down

0 comments on commit e6fbb55

Please sign in to comment.