Skip to content

Commit

Permalink
Move MPI initialisation into cable_driver_init
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanBryan51 committed Oct 25, 2024
1 parent f87dbec commit 7acdb17
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
17 changes: 17 additions & 0 deletions src/offline/cable_driver_init.F90
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
MODULE cable_driver_init_mod
!! Module for containing routines for CABLE offline driver initialisation
USE cable_namelist_util, ONLY : get_namelist_file_name
#ifdef __MPI__
USE mpi
USE cable_mpicommon, ONLY : comm, rank
#endif
IMPLICIT NONE
PRIVATE

Expand All @@ -10,6 +14,9 @@ MODULE cable_driver_init_mod

SUBROUTINE cable_driver_init()
!! Model initialisation routine for the CABLE offline driver.
#ifdef __MPI__
INTEGER :: np, ierr
#endif

!check to see if first argument passed to cable is
!the name of the namelist file
Expand All @@ -18,6 +25,16 @@ SUBROUTINE cable_driver_init()

#ifdef __MPI__
! MPI specific initialisation
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)
#else
! Serial specific initialisation
#endif
Expand Down
7 changes: 7 additions & 0 deletions src/offline/cable_mpicommon.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 2 additions & 13 deletions src/offline/cable_mpidrv.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7acdb17

Please sign in to comment.