From ebbc7e29822497cd5d52b5d01b157ba6cfdaa67d Mon Sep 17 00:00:00 2001 From: Antoine Cyril David Hoffmann <ahoffman@spcpc606.epfl.ch> Date: Tue, 15 Jun 2021 14:11:39 +0200 Subject: [PATCH] displacement of manual bcast to utility module --- Makefile | 2 +- src/basic_mod.F90 | 38 -------------------------------------- src/diagnose.F90 | 2 +- src/poisson.F90 | 3 ++- src/processing_mod.F90 | 1 + src/utility_mod.F90 | 39 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 44 insertions(+), 41 deletions(-) diff --git a/Makefile b/Makefile index 1362e117..3c520eab 100644 --- a/Makefile +++ b/Makefile @@ -59,7 +59,7 @@ $(OBJDIR)/stepon.o $(OBJDIR)/tesend.o $(OBJDIR)/time_integration_mod.o $(OBJDIR) $(EXEC): $(FOBJ) $(F90) $(LDFLAGS) $(OBJDIR)/*.o $(EXTMOD) $(EXTINC) $(EXTLIBS) -o $@ - $(OBJDIR)/advance_field.o : src/advance_field.F90 $(OBJDIR)/grid_mod.o $(OBJDIR)/array_mod.o $(OBJDIR)/prec_const_mod.o $(OBJDIR)/time_integration_mod.o $(OBJDIR)/basic_mod.o $(OBJDIR)/fields_mod.o + $(OBJDIR)/advance_field.o : src/advance_field.F90 $(OBJDIR)/grid_mod.o $(OBJDIR)/array_mod.o $(OBJDIR)/prec_const_mod.o $(OBJDIR)/time_integration_mod.o $(OBJDIR)/basic_mod.o $(OBJDIR)/fields_mod.o $(F90) -c $(F90FLAGS) $(FPPFLAGS) $(EXTMOD) $(EXTINC) src/advance_field.F90 -o $@ $(OBJDIR)/array_mod.o : src/array_mod.F90 $(OBJDIR)/prec_const_mod.o diff --git a/src/basic_mod.F90 b/src/basic_mod.F90 index 868747c8..4516673b 100644 --- a/src/basic_mod.F90 +++ b/src/basic_mod.F90 @@ -125,44 +125,6 @@ CONTAINS ENDIF END SUBROUTINE display_h_min_s - !================================================================================ - - !!!!! This is a manual way to do MPI_BCAST !!!!!!!!!!! -SUBROUTINE manual_2D_bcast(field_) - USE grid - IMPLICIT NONE - COMPLEX(dp), INTENT(INOUT) :: field_(ikrs:ikre,ikzs:ikze) - COMPLEX(dp) :: buffer(ikrs:ikre,ikzs:ikze) - INTEGER :: i_, root, world_rank, world_size - root = 0; - CALL MPI_COMM_RANK(comm_p,world_rank,ierr) - CALL MPI_COMM_SIZE(comm_p,world_size,ierr) - IF (world_size .GT. 1) THEN - !! Broadcast phi to the other processes on the same k range (communicator along p) - IF (world_rank .EQ. root) THEN - ! Fill the buffer - DO ikr = ikrs,ikre - DO ikz = ikzs,ikze - buffer(ikr,ikz) = field_(ikr,ikz) - ENDDO - ENDDO - ! Send it to all the other processes - DO i_ = 0,num_procs_p-1 - IF (i_ .NE. world_rank) & - CALL MPI_SEND(buffer, local_nkr * nkz , MPI_DOUBLE_COMPLEX, i_, 0, comm_p, ierr) - ENDDO - ELSE - ! Recieve buffer from root - CALL MPI_RECV(buffer, local_nkr * nkz , MPI_DOUBLE_COMPLEX, root, 0, comm_p, MPI_STATUS_IGNORE, ierr) - ! Write it in phi - DO ikr = ikrs,ikre - DO ikz = ikzs,ikze - field_(ikr,ikz) = buffer(ikr,ikz) - ENDDO - ENDDO - ENDIF - ENDIF -END SUBROUTINE manual_2D_bcast !================================================================================ ! To allocate arrays of doubles, integers, etc. at run time diff --git a/src/diagnose.F90 b/src/diagnose.F90 index 21f0a64f..d4ecfcce 100644 --- a/src/diagnose.F90 +++ b/src/diagnose.F90 @@ -9,7 +9,7 @@ SUBROUTINE diagnose(kstep) USE initial_par USE fields USE time_integration - + USE utility USE prec_const IMPLICIT NONE diff --git a/src/poisson.F90 b/src/poisson.F90 index 8a1178c6..b4d39180 100644 --- a/src/poisson.F90 +++ b/src/poisson.F90 @@ -6,6 +6,7 @@ SUBROUTINE poisson USE array USE fields USE grid + USE utility use model, ONLY : qe2_taue, qi2_taui, q_e, q_i, lambdaD USE prec_const @@ -69,7 +70,7 @@ SUBROUTINE poisson ! Transfer phi to all the others process along p CALL manual_2D_bcast(phi(ikrs:ikre,ikzs:ikze)) - + ! Execution time end CALL cpu_time(t1_poisson) tc_poisson = tc_poisson + (t1_poisson - t0_poisson) diff --git a/src/processing_mod.F90 b/src/processing_mod.F90 index 0833d3f7..dcf41218 100644 --- a/src/processing_mod.F90 +++ b/src/processing_mod.F90 @@ -3,6 +3,7 @@ MODULE processing USE basic USE prec_const USE grid + USE utility implicit none REAL(dp), PUBLIC, PROTECTED :: pflux_ri, gflux_ri diff --git a/src/utility_mod.F90 b/src/utility_mod.F90 index 0d98a599..b044ce6d 100644 --- a/src/utility_mod.F90 +++ b/src/utility_mod.F90 @@ -4,6 +4,7 @@ MODULE utility use prec_const IMPLICIT NONE + PUBLIC :: manual_2D_bcast CONTAINS @@ -69,4 +70,42 @@ CONTAINS .OR. is_nan(AIMAG(sumfield),str).OR.is_inf(AIMAG(sumfield),str) END FUNCTION checkfield + + !!!!! This is a manual way to do MPI_BCAST !!!!!!!!!!! + SUBROUTINE manual_2D_bcast(field_) + USE grid + IMPLICIT NONE + COMPLEX(dp), INTENT(INOUT) :: field_(ikrs:ikre,ikzs:ikze) + COMPLEX(dp) :: buffer(ikrs:ikre,ikzs:ikze) + INTEGER :: i_, root, world_rank, world_size + root = 0; + CALL MPI_COMM_RANK(comm_p,world_rank,ierr) + CALL MPI_COMM_SIZE(comm_p,world_size,ierr) + IF (world_size .GT. 1) THEN + !! Broadcast phi to the other processes on the same k range (communicator along p) + IF (world_rank .EQ. root) THEN + ! Fill the buffer + DO ikr = ikrs,ikre + DO ikz = ikzs,ikze + buffer(ikr,ikz) = field_(ikr,ikz) + ENDDO + ENDDO + ! Send it to all the other processes + DO i_ = 0,num_procs_p-1 + IF (i_ .NE. world_rank) & + CALL MPI_SEND(buffer, local_nkr * nkz , MPI_DOUBLE_COMPLEX, i_, 0, comm_p, ierr) + ENDDO + ELSE + ! Recieve buffer from root + CALL MPI_RECV(buffer, local_nkr * nkz , MPI_DOUBLE_COMPLEX, root, 0, comm_p, MPI_STATUS_IGNORE, ierr) + ! Write it in phi + DO ikr = ikrs,ikre + DO ikz = ikzs,ikze + field_(ikr,ikz) = buffer(ikr,ikz) + ENDDO + ENDDO + ENDIF + ENDIF + END SUBROUTINE manual_2D_bcast + END MODULE utility -- GitLab