!...................................................................................................................................!:.:.:
!.......................... File: mpi_04_Bcast.f90           .......................................................................!:.:.:
!===================================================================================================================================
!-----------------------------------------------------------------------------------------------------------------------------------
!
! Compile using the commands:
! mpifort mpi_04_Bcast.f90 -o m;mpirun -n 4 ./m | sort
!
! If too many processes, then:   mpirun -n 32 --host $(hostname):32 ./m
!-----------------------------------------------------------------------------------------------------------------------------------
program     mpi_introduction

 use mpi
 implicit none

 integer , parameter :: dp = 8
 integer             :: ierr, nprocs, myrank
 integer             :: nmat
 real(dp)            :: a(2)

 call mpi_init     (ierr)
 call mpi_comm_size(MPI_COMM_WORLD,nprocs,ierr)
 call mpi_comm_rank(MPI_COMM_WORLD,myrank,ierr)

 nmat  = 8   ; a = -1.0_dp  !initialize on all processes
 if(myrank == 0)then
  nmat = 128 ; a = [-99.0_dp,-98.0_dp]
 end if

 print *,'01 Before Bcast: ',myrank,nmat,a

 call mpi_bcast(nmat,1      ,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
 call mpi_bcast(a   ,size(a),MPI_REAL8  ,0,MPI_COMM_WORLD,ierr)

 print *,'02 After  Bcast: ',myrank,nmat,a

 call mpi_finalize(ierr)

end program mpi_introduction
!===================================================================================================================================
!-----------------------------------------------------------------------------------------------------------------------------------
!  Copyright by Konstantinos N. Anagnostopoulos, Physics Department, National Technical University of Athens, 2025
!  konstant@mail.ntua.gr, www.physics.ntua.gr/konstant
!  
!  This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as 
!  published by the Free Software Foundation, version 3 of the License.
!  
!  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
!  
!  You should have received a copy of the GNU General Public Liense along with this program. If not, see http://www.gnu.org/licenses
!-----------------------------------------------------------------------------------------------------------------------------------
