Mismatch for arguments MPI_BCAST

Hi, I am using the mpi module to manage the call of the subroutines of my new observation operator in the differents ranks.
I am trying to avoid a multiple reading of a file from all the ranks(I checked that the run crashes in correspondance of the subroutine that reads the file from disk), so I am trying to set up the reading just in the rank 0, initialize the memeber of a declared object and broadcast such object memebers values to initialize the same declared object in all the other ranks(obviously for the array members I broadcast the size of the allocations etc…)

The problem I have is during the compilation, this is the beginning of the subroutine that should broadcast the variables to all the ranks:

subroutine broadcast_od(od, comm)

use mpi
use structures
use parameters
use iso_fortran_env
implicit none

type(od_dbase), intent(inout) :: od
integer, intent(in)           :: comm

integer :: ierr
integer :: rank

!========================================================
! logical flags for allocatables
!========================================================
logical :: npn_alloc
logical :: point_alloc
logical :: squad_alloc
logical :: equad_alloc
logical :: quad_alloc

logical :: cq0_alloc
logical :: cq1_alloc
logical :: cq2_alloc
logical :: cq3_alloc

logical :: npnR_alloc
logical :: pointR_alloc
logical :: squadR_alloc
logical :: equadR_alloc
logical :: quadR_alloc

logical :: cq0R_alloc
logical :: cq1R_alloc
logical :: cq2R_alloc
logical :: cq3R_alloc

logical :: Pbetaw_alloc
logical :: Pomegaw_alloc
logical :: Pbw_alloc

logical :: Pbetai_alloc
logical :: Pomegai_alloc
logical :: Pbi_alloc

logical :: Isol_alloc
!variabile temporanea per il membro od%double_precision
logical :: tmp_double_precision
real(kind=PREC) :: tmp_noi

!========================================================
! dimensions for 2D arrays
!========================================================
integer :: n1, n2

call MPI_COMM_RANK(comm, rank, ierr)
if (rank == 0) then
   tmp_double_precision = od%double_precision
end if

!========================================================
! BROADCAST SCALARS
!========================================================

call MPI_BCAST(tmp_double_precision, 1, MPI_LOGICAL, 0, comm, ierr)
od%double_precision = tmp_double_precision

call MPI_BCAST(od%noi, 1, MPI_REAL4, 0, comm, ierr)
call MPI_BCAST(od%nof, 1, MPI_REAL4, 0, comm, ierr)

call MPI_BCAST(od%v1cur, 1, MPI_DOUBLE_PRECISION, 0, comm, ierr)
call MPI_BCAST(od%v2cur, 1, MPI_DOUBLE_PRECISION, 0, comm, ierr)

call MPI_BCAST(od%wn_thresh, 1, MPI_DOUBLE_PRECISION, 0, comm, ierr)

call MPI_BCAST(od%continuum_model, 1, MPI_INTEGER, 0, comm, ierr)

call MPI_BCAST(od%nwhrbandmax, 1, MPI_INTEGER, 0, comm, ierr)
call MPI_BCAST(od%nwhrbandmaxR, 1, MPI_INTEGER, 0, comm, ierr)

during the compilation I have this kind of error, could someone suggest something to understand what is this caused from?

[ 47%] Built target qg_ControlPert.x
[ 47%] Built target qg_hofx.x
[ 47%] Built target qg_hofx3d.x
/glade/derecho/scratch/sandroni/newobsoperator_mpas_jedi/mpas_bundle_v3/code_fix/ufo/src/ufo/operators/sigma/ufo_sigma_utils_mod.f90:771:15:

768 | call MPI_BCAST(tmp_double_precision, 1, MPI_LOGICAL, 0, comm, ierr)
|               2
…
771 | call MPI_BCAST(od%noi, 1, MPI_REAL4, 0, comm, ierr)
|               1
Error: Type mismatch between actual argument at (1) and actual argument at (2) (REAL(4)/LOGICAL(4)).
/glade/derecho/scratch/sandroni/newobsoperator_mpas_jedi/mpas_bundle_v3/code_fix/ufo/src/ufo/operators/sigma/ufo_sigma_utils_mod.f90:772:15:

768 | call MPI_BCAST(tmp_double_precision, 1, MPI_LOGICAL, 0, comm, ierr)
|               2
…
772 | call MPI_BCAST(od%nof, 1, MPI_REAL4, 0, comm, ierr)
|               1
Error: Type mismatch between actual argument at (1) and actual argument at (2) (REAL(4)/LOGICAL(4)).
/glade/derecho/scratch/sandroni/newobsoperator_mpas_jedi/mpas_bundle_v3/code_fix/ufo/src/ufo/operators/sigma/ufo_sigma_utils_mod.f90:774:15:

768 | call MPI_BCAST(tmp_double_precision, 1, MPI_LOGICAL, 0, comm, ierr)
|               2
…
774 | call MPI_BCAST(od%v1cur, 1, MPI_DOUBLE_PRECISION, 0, comm, ierr)
|               1

Hi @antoniosandroni, it looks like you have inconsistencies between the data value and the specified data type. Make sure the data type of the first argument matches up with the third argument. Perhaps for the first error message you need to change MPI_LOGICAL to MPI_REAL4 on line 768?

I just adopted another solution, not using the subroutine call MPI_BCAST but instead the internal method of the MPI communicator object “comm” like this:

call comm%broadcast(tmp_double_precision, 0)

instead of

call MPI_BCAST(tmp_double_precision, 1, MPI_LOGICAL, 0, comm, ierr)

and everything works, thanks @stephenh .

1 Like