diff --git a/src/offline/cable_driver_init.F90 b/src/offline/cable_driver_init.F90 index f7fafa903..87b99b9ce 100644 --- a/src/offline/cable_driver_init.F90 +++ b/src/offline/cable_driver_init.F90 @@ -1,5 +1,9 @@ MODULE cable_driver_init_mod USE cable_namelist_util, ONLY : get_namelist_file_name +#ifdef __MPI__ + USE mpi + USE cable_mpicommon, ONLY : comm, rank +#endif IMPLICIT NONE PRIVATE @@ -9,6 +13,9 @@ MODULE cable_driver_init_mod SUBROUTINE cable_driver_init() ! Model initialisation routine for the offline driver. +#ifdef __MPI__ + INTEGER :: np, ierr +#endif !check to see if first argument passed to cable is !the name of the namelist file @@ -16,6 +23,17 @@ SUBROUTINE cable_driver_init() CALL get_namelist_file_name() #ifdef __MPI__ + CALL MPI_Init(ierr) + CALL MPI_Comm_dup(MPI_COMM_WORLD, comm, ierr) + CALL MPI_Comm_size(comm, np, ierr) + + IF (np < 2) THEN + WRITE (*,*) 'This program needs at least 2 processes to run!' + CALL MPI_Abort(comm, 0, ierr) + END IF + + CALL MPI_Comm_rank(comm, rank, ierr) + print*, "MPI" #else print*, "SERIAL" diff --git a/src/offline/cable_mpicommon.F90 b/src/offline/cable_mpicommon.F90 index ddd0e5785..a048401cd 100644 --- a/src/offline/cable_mpicommon.F90 +++ b/src/offline/cable_mpicommon.F90 @@ -27,6 +27,13 @@ MODULE cable_mpicommon PUBLIC + ! MPI commicator and rank are declared as global variables (see + ! cable_driver_init_mod for their initialisation). This is done so that the comm + ! and rank variables are only accessible in cable_driver_init_mod when MPI + ! compilation is enabled. + ! TODO(Sean): revise which module to declare these variables in + INTEGER :: comm, rank + ! base number of input fields: must correspond to CALLS to ! MPI_address (field ) in *_mpimaster/ *_mpiworker INTEGER, PARAMETER :: nparam = 330 diff --git a/src/offline/cable_mpidrv.F90 b/src/offline/cable_mpidrv.F90 index 296f2b989..fab9b5b06 100644 --- a/src/offline/cable_mpidrv.F90 +++ b/src/offline/cable_mpidrv.F90 @@ -22,28 +22,17 @@ PROGRAM mpi_driver USE mpi USE cable_driver_init_mod - USE cable_mpicommon + USE cable_mpicommon, ONLY : comm, rank USE cable_mpimaster USE cable_mpiworker IMPLICIT NONE - INTEGER :: comm, np, rank, ierr + INTEGER :: ierr REAL :: etime ! Declare the type of etime() CALL cable_driver_init() - CALL MPI_Init (ierr) - CALL MPI_Comm_dup (MPI_COMM_WORLD, comm, ierr) - CALL MPI_Comm_size (comm, np, ierr) - - IF (np < 2) THEN - WRITE (*,*) 'This program needs at least 2 processes to run!' - CALL MPI_Abort (comm, 0, ierr) - END IF - - CALL MPI_Comm_rank (comm, rank, ierr) - IF (rank == 0) THEN CALL mpidrv_master (comm) ELSE