ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/mpiSimulation_module.F90
(Generate patch)

Comparing trunk/OOPSE/libmdtools/mpiSimulation_module.F90 (file contents):
Revision 432 by chuckv, Thu Mar 27 23:33:40 2003 UTC vs.
Revision 1150 by gezelter, Fri May 7 21:35:05 2004 UTC

# Line 1 | Line 1
1 #ifdef IS_MPI
1  
2 +
3   !! MPI support for long range forces using force decomposition
4   !! on a square grid of processors.
5   !! Corresponds to mpiSimunation.cpp for C++
# Line 7 | Line 7
7   !!
8   !! @author Charles F. Vardeman II
9   !! @author Matthew Meineke
10 < !! @version $Id: mpiSimulation_module.F90,v 1.3 2003-03-27 23:33:40 chuckv Exp $, $Date: 2003-03-27 23:33:40 $, $Name: not supported by cvs2svn $, $Revision: 1.3 $
10 > !! @version $Id: mpiSimulation_module.F90,v 1.12 2004-05-07 21:35:04 gezelter Exp $, $Date: 2004-05-07 21:35:04 $, $Name: not supported by cvs2svn $, $Revision: 1.12 $
11  
12   module mpiSimulation  
13    use definitions
14 <  use mpi
14 > #ifdef IS_MPI
15 >  use oopseMPI
16    implicit none
17    PRIVATE
18  
# Line 24 | Line 25 | module mpiSimulation  
25    public :: replanSimParallel
26    public :: getNcol
27    public :: getNrow
28 +  public :: getNcolGroup
29 +  public :: getNrowGroup
30    public :: isMPISimSet
31    public :: printComponentPlan
32    public :: getMyNode
# Line 31 | Line 34 | module mpiSimulation  
34   !! PUBLIC  Subroutines contained in MPI module
35    public :: mpi_bcast
36    public :: mpi_allreduce
37 <  public :: mpi_reduce
37 > !  public :: mpi_reduce
38    public :: mpi_send
39    public :: mpi_recv
40    public :: mpi_get_processor_name
# Line 47 | Line 50 | module mpiSimulation  
50    public :: mpi_status_size
51    public :: mpi_any_source
52  
53 +
54 +
55   !! Safety logical to prevent access to ComponetPlan until
56   !! set by C++.
57 <  logical :: ComponentPlanSet = .false.
57 >  logical, save :: ComponentPlanSet = .false.
58  
59  
60   !! generic mpi error declaration.
61 <  integer,public  :: mpi_err
61 >  integer, public :: mpi_err
62  
63 <  
63 > #ifdef PROFILE
64 >  public :: printCommTime
65 >  public :: getCommTime
66 >  real,save   :: commTime = 0.0
67 >  real   :: commTimeInitial,commTimeFinal
68 > #endif
69  
70   !! Include mpiComponentPlan type. mpiComponentPlan is a
71   !! dual header file for both c and fortran.
# Line 63 | Line 73 | module mpiSimulation  
73   #include "mpiComponentPlan.h"
74  
75  
66
76   !! Tags used during force loop for parallel simulation
77 <  integer, allocatable, dimension(:) :: tagLocal
77 >  integer, public, allocatable, dimension(:) :: tagLocal
78    integer, public, allocatable, dimension(:) :: tagRow
79    integer, public, allocatable, dimension(:) :: tagColumn
80  
81   !! Logical set true if mpiSimulation has been initialized
82 <  logical :: isSimSet = .false.
82 >  logical, save :: isSimSet = .false.
83  
84  
85 <  type (mpiComponentPlan) :: mpiSim
85 >  type (mpiComponentPlan), save :: mpiSim
86  
87   !! gs_plan contains plans for gather and scatter routines
88    type, public :: gs_plan
# Line 89 | Line 98 | module mpiSimulation  
98    end type gs_plan
99  
100   ! plans for different decompositions
101 <  type (gs_plan), public :: plan_row
102 <  type (gs_plan), public :: plan_row3d
103 <  type (gs_plan), public :: plan_col
104 <  type (gs_plan), public :: plan_col3d
105 <  type(gs_plan),  public :: plan_row_Rotation
106 <  type(gs_plan),  public :: plan_col_Rotation
101 >  type (gs_plan), public, save :: plan_row
102 >  type (gs_plan), public, save :: plan_row3d
103 >  type (gs_plan), public, save :: plan_col
104 >  type (gs_plan), public, save :: plan_col3d
105 >  type (gs_plan),  public, save :: plan_row_Rotation
106 >  type (gs_plan),  public, save :: plan_col_Rotation
107 >  type (gs_plan),  public, save :: plan_row_Group
108 >  type (gs_plan),  public, save :: plan_col_Group
109 >  type (gs_plan),  public, save :: plan_row_Group_3d
110 >  type (gs_plan),  public, save :: plan_col_Group_3d
111  
112    type (mpiComponentPlan), pointer :: simComponentPlan
113  
# Line 137 | Line 150 | contains
150   !! Global reference tag for local particles
151      integer, dimension(ntags),intent(inout) :: tags
152  
153 +    write(*,*) 'mpiSim_mod thinks node', thisComponentPlan%myNode, ' has tags(1) = ', tags(1)
154  
155      status = 0
156      if (componentPlanSet) then
# Line 170 | Line 184 | contains
184           mpiSim,mpiSim%rowComm,plan_row3d)
185      call plan_gather_scatter(9,mpiSim%myNlocal,&
186           mpiSim,mpiSim%rowComm,plan_row_Rotation)
187 +    call plan_gather_scatter(1,mpiSim%myNgroup,&
188 +         mpiSim,mpiSim%rowComm,plan_row_Group)
189 +    call plan_gather_scatter(nDim,mpiSim%myNgroup,&
190 +         mpiSim,mpiSim%rowComm,plan_row_Group_3d)
191 +        
192      call plan_gather_scatter(1,mpiSim%myNlocal,&
193           mpiSim,mpiSim%columnComm,plan_col)
194      call plan_gather_scatter(nDim,mpiSim%myNlocal,&
195           mpiSim,mpiSim%columnComm,plan_col3d)
196 <   call plan_gather_scatter(9,mpiSim%myNlocal,&
196 >    call plan_gather_scatter(9,mpiSim%myNlocal,&
197           mpiSim,mpiSim%columnComm,plan_col_Rotation)
198 <
199 <
200 <
198 >    call plan_gather_scatter(1,mpiSim%myNgroup,&
199 >         mpiSim,mpiSim%columnComm,plan_col_Group)
200 >    call plan_gather_scatter(nDim,mpiSim%myNgroup,&
201 >         mpiSim,mpiSim%columnComm,plan_col_Group_3d)
202 >    
203   !  Initialize tags    
204      call setTags(tags,localStatus)
205      if (localStatus /= 0) then
# Line 209 | Line 230 | contains
230      call unplan_gather_scatter(plan_row)
231      call unplan_gather_scatter(plan_row3d)
232      call unplan_gather_scatter(plan_row_Rotation)
233 +    call unplan_gather_scatter(plan_row_Group)
234 +    call unplan_gather_scatter(plan_row_Group_3d)
235 +
236      call unplan_gather_scatter(plan_col)
237      call unplan_gather_scatter(plan_col3d)
238      call unplan_gather_scatter(plan_col_Rotation)
239 +    call unplan_gather_scatter(plan_col_Group)
240 +    call unplan_gather_scatter(plan_col_Group_3d)
241  
242      !! initialize gather and scatter plans used in this simulation
243      call plan_gather_scatter(1,thisComponentPlan%myNlocal,&
# Line 220 | Line 246 | contains
246           thisComponentPlan,thisComponentPlan%rowComm,plan_row3d)
247      call plan_gather_scatter(9,thisComponentPlan%myNlocal,&
248           thisComponentPlan,thisComponentPlan%rowComm,plan_row_Rotation)
249 +    call plan_gather_scatter(1,thisComponentPlan%myNgroup,&
250 +         thisComponentPlan,thisComponentPlan%rowComm,plan_row_Group)
251 +    call plan_gather_scatter(nDim,thisComponentPlan%myNgroup,&
252 +         thisComponentPlan,thisComponentPlan%rowComm,plan_row_Group_3d)
253 +
254      call plan_gather_scatter(1,thisComponentPlan%myNlocal,&
255           thisComponentPlan,thisComponentPlan%columnComm,plan_col)
256      call plan_gather_scatter(nDim,thisComponentPlan%myNlocal,&
257 <         thisComponentPlan,thisComponentPlan%rowComm,plan_col3d)
257 >         thisComponentPlan,thisComponentPlan%columnComm,plan_col3d)
258      call plan_gather_scatter(9,thisComponentPlan%myNlocal,&
259 <         thisComponentPlan,thisComponentPlan%rowComm,plan_col_Rotation)
259 >         thisComponentPlan,thisComponentPlan%columnComm,plan_col_Rotation)
260 >    call plan_gather_scatter(1,thisComponentPlan%myNgroup,&
261 >         thisComponentPlan,thisComponentPlan%columnComm,plan_col_Group)
262 >    call plan_gather_scatter(nDim,thisComponentPlan%myNgroup,&
263 >         thisComponentPlan,thisComponentPlan%columnComm,plan_col_Group_3d)
264  
230
231
265    end subroutine replanSimParallel
266  
267   !! Updates number of row and column components for long range forces.
# Line 460 | Line 493 | contains
493  
494    subroutine gather_integer( sbuffer, rbuffer, this_plan, status)
495  
496 <    type (gs_plan), intent(in) :: this_plan
497 <    integer, dimension(:), intent(in) :: sbuffer
498 <    integer, dimension(:), intent(in) :: rbuffer
496 >    type (gs_plan), intent(inout) :: this_plan
497 >    integer, dimension(:), intent(inout) :: sbuffer
498 >    integer, dimension(:), intent(inout) :: rbuffer
499      integer :: noffset
500      integer, intent(out), optional :: status
501      integer :: i
# Line 492 | Line 525 | contains
525    subroutine gather_double( sbuffer, rbuffer, this_plan, status)
526  
527      type (gs_plan), intent(in) :: this_plan
528 <    real( kind = DP ), dimension(:), intent(in) :: sbuffer
529 <    real( kind = DP ), dimension(:), intent(in) :: rbuffer
528 >    real( kind = DP ), dimension(:), intent(inout) :: sbuffer
529 >    real( kind = DP ), dimension(:), intent(inout) :: rbuffer
530      integer :: noffset
531      integer, intent(out), optional :: status
532  
533  
534      if (present(status)) status = 0
535      noffset = this_plan%displs(this_plan%myPlanRank)
536 <
536 > #ifdef PROFILE
537 >    call cpu_time(commTimeInitial)
538 > #endif
539      call mpi_allgatherv(sbuffer,this_plan%gsPlanSize, mpi_double_precision, &
540           rbuffer,this_plan%counts,this_plan%displs,mpi_double_precision, &
541           this_plan%myPlanComm, mpi_err)
542 + #ifdef PROFILE
543 +    call cpu_time(commTimeFinal)
544 +    commTime = commTime + commTimeFinal - commTimeInitial
545 + #endif
546  
547      if (mpi_err /= 0) then
548        if (present(status)) status  = -1
# Line 514 | Line 553 | contains
553    subroutine gather_double_2d( sbuffer, rbuffer, this_plan, status)
554  
555      type (gs_plan), intent(in) :: this_plan
556 <    real( kind = DP ), dimension(:,:), intent(in) :: sbuffer
557 <    real( kind = DP ), dimension(:,:), intent(in) :: rbuffer
556 >    real( kind = DP ), dimension(:,:), intent(inout) :: sbuffer
557 >    real( kind = DP ), dimension(:,:), intent(inout) :: rbuffer
558      integer :: noffset,i,ierror
559      integer, intent(out), optional :: status
560      
# Line 524 | Line 563 | contains
563     if (present(status)) status = 0
564  
565   !    noffset = this_plan%displs(this_plan%me)
566 <    
566 > #ifdef PROFILE
567 >   call cpu_time(commTimeInitial)
568 > #endif
569 >
570      call mpi_allgatherv(sbuffer,this_plan%gsPlanSize, mpi_double_precision, &
571          rbuffer,this_plan%counts,this_plan%displs,mpi_double_precision, &
572          this_plan%myPlanComm, mpi_err)
573  
574 + #ifdef PROFILE
575 +    call cpu_time(commTimeFinal)
576 +    commTime = commTime + commTimeFinal - commTimeInitial
577 + #endif
578 +
579      if (mpi_err /= 0) then
580        if (present(status)) status = -1
581      endif
# Line 538 | Line 585 | contains
585    subroutine scatter_double( sbuffer, rbuffer, this_plan, status)
586  
587      type (gs_plan), intent(in) :: this_plan
588 <    real( kind = DP ), dimension(:), intent(in) :: sbuffer
589 <    real( kind = DP ), dimension(:), intent(in) :: rbuffer
588 >    real( kind = DP ), dimension(:), intent(inout) :: sbuffer
589 >    real( kind = DP ), dimension(:), intent(inout) :: rbuffer
590      integer, intent(out), optional :: status
591      external mpi_reduce_scatter
592  
593     if (present(status)) status = 0
594  
595 + #ifdef PROFILE
596 +   call cpu_time(commTimeInitial)
597 + #endif
598      call mpi_reduce_scatter(sbuffer,rbuffer, this_plan%counts, &
599           mpi_double_precision, MPI_SUM, this_plan%myPlanComm, mpi_err)
600 + #ifdef PROFILE
601 +    call cpu_time(commTimeFinal)
602 +    commTime = commTime + commTimeFinal - commTimeInitial
603 + #endif
604  
605      if (mpi_err /= 0) then
606       if (present(status))  status = -1
# Line 557 | Line 611 | contains
611    subroutine scatter_double_2d( sbuffer, rbuffer, this_plan, status)
612  
613      type (gs_plan), intent(in) :: this_plan
614 <    real( kind = DP ), dimension(:,:), intent(in) :: sbuffer
615 <    real( kind = DP ), dimension(:,:), intent(in) :: rbuffer
614 >    real( kind = DP ), dimension(:,:), intent(inout) :: sbuffer
615 >    real( kind = DP ), dimension(:,:), intent(inout) :: rbuffer
616      integer, intent(out), optional :: status
617      external mpi_reduce_scatter
618  
619     if (present(status)) status = 0
620 + #ifdef PROFILE
621 +   call cpu_time(commTimeInitial)
622 + #endif
623 +
624      call mpi_reduce_scatter(sbuffer,rbuffer, this_plan%counts, &
625           mpi_double_precision, MPI_SUM, this_plan%myPlanComm, mpi_err)
626 + #ifdef PROFILE
627 +    call cpu_time(commTimeFinal)
628 +    commTime = commTime + commTimeFinal - commTimeInitial
629 + #endif
630  
631      if (mpi_err /= 0) then
632        if (present(status)) status = -1
# Line 586 | Line 648 | contains
648   ! allocate row arrays
649      nrow = getNrow(plan_row)
650      ncol = getNcol(plan_col)
651 +    
652 +    if(.not. allocated(tagLocal)) then
653 +       allocate(tagLocal(size(tags)),STAT=alloc_stat)
654 +        if (alloc_stat /= 0 ) then
655 +          status = -1
656 +          return
657 +       endif
658 +    else
659 +       deallocate(tagLocal)
660 +       allocate(tagLocal(size(tags)),STAT=alloc_stat)
661 +       if (alloc_stat /= 0 ) then
662 +          status = -1
663 +          return
664 +       endif
665  
666 +    endif
667 +
668 +    tagLocal = tags
669 +
670 +    
671      if (.not. allocated(tagRow)) then
672         allocate(tagRow(nrow),STAT=alloc_stat)
673         if (alloc_stat /= 0 ) then
# Line 621 | Line 702 | contains
702      call gather(tags,tagRow,plan_row)
703      call gather(tags,tagColumn,plan_col)
704  
705 +  
706    end subroutine setTags
707  
708 <  pure function getNcol(thisplan) result(ncol)
708 > !  pure function getNcol(thisplan) result(ncol)
709 >  function getNcol(thisplan) result(ncol)
710      type (gs_plan), intent(in) :: thisplan
711      integer :: ncol
712      ncol = thisplan%gsComponentPlan%nComponentsColumn
713    end function getNcol
714  
715 <  pure function getNrow(thisplan) result(nrow)
715 > !  pure function getNrow(thisplan) result(nrow)
716 >  function getNrow(thisplan) result(nrow)
717      type (gs_plan), intent(in) :: thisplan
718      integer :: nrow
719      nrow = thisplan%gsComponentPlan%nComponentsRow
720    end function getNrow
721  
722 +  function getNcolGroup(thisplan) result(ncol_group)
723 +    type (gs_plan), intent(in) :: thisplan
724 +    integer :: ncol_group
725 +    ncol_group = thisplan%gsComponentPlan%nGroupColumn
726 +  end function getNcolGroup
727 +
728 +  function getNrowGroup(thisplan) result(nrow_group)
729 +    type (gs_plan), intent(in) :: thisplan
730 +    integer :: nrow_group
731 +    nrow_group = thisplan%gsComponentPlan%nGroupRow
732 +  end function getNrowGroup
733 +
734    function isMPISimSet() result(isthisSimSet)
735      logical :: isthisSimSet
736      if (isSimSet) then
# Line 685 | Line 781 | contains
781      myNode = mpiSim%myNode
782    end function getMyNode
783  
784 + #ifdef PROFILE
785 +  subroutine printCommTime()
786 +    write(*,*) "MPI communication time is: ", commTime
787 +  end subroutine printCommTime
788  
789 < end module mpiSimulation
789 >  function getCommTime() result(comm_time)
790 >    real :: comm_time
791 >    comm_time = commTime
792 >  end function getCommTime
793  
794 + #endif
795 +
796   #endif // is_mpi
797 + end module mpiSimulation
798 +
799 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines