ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/md_code/mpiSimulation.F90
(Generate patch)

Comparing trunk/mdtools/md_code/mpiSimulation.F90 (file contents):
Revision 209 by chuckv, Fri Dec 13 16:51:23 2002 UTC vs.
Revision 210 by chuckv, Fri Dec 13 18:06:58 2002 UTC

# Line 5 | Line 5
5   !!
6   !! @author Charles F. Vardeman II
7   !! @author Matthew Meineke
8 < !! @version $Id: mpiSimulation.F90,v 1.1 2002-12-13 16:51:23 chuckv Exp $, $Date: 2002-12-13 16:51:23 $, $Name: not supported by cvs2svn $, $Revision: 1.1 $
8 > !! @version $Id: mpiSimulation.F90,v 1.2 2002-12-13 18:06:58 chuckv Exp $, $Date: 2002-12-13 18:06:58 $, $Name: not supported by cvs2svn $, $Revision: 1.2 $
9  
10  
11  
# Line 57 | Line 57 | module mpiSimulation  
57   !! gs_plan contains plans for gather and scatter routines
58    type, public :: gs_plan
59       private
60 <     type (mpiComponentPlan), pointer :: gsComponentPlan
61 < !     integer ::  me, nprocs, n_datum,full_size  !n = # of datums on local proc
62 <     integer, dimension(:), pointer :: displs
63 <     integer, dimension(:), pointer :: counts
64 <     integer :: planComm !! Communicator for this plan
60 >     type (mpiComponentPlan), pointer :: gsComponentPlan => NULL()
61 >     integer :: gsPlanSize !! size of this plan (nDim*nComponents)
62 >     integer :: globalPlanSize !! size of all components in plan
63 >     integer, dimension(:), pointer :: displs !! Displacements array for mpi indexed from 0.
64 >     integer, dimension(:), pointer :: counts !! Counts array for mpi indexed from 0.
65 >     integer :: myPlanComm  !! My communicator for this plan
66 >     integer :: myPlanRank  !! My rank in this plan
67 >     integer :: planNprocs  !! Number of processors in this plan
68    end type gs_plan
69  
70   ! plans for different decompositions
# Line 96 | Line 99 | contains
99   contains
100  
101   !! Sets up mpiComponentPlan with structure passed from C++.
102 <  subroutine setupSimParallel(nDim,thisComponentPlan)
102 >  subroutine setupSimParallel(nDim,thisComponentPlan,status)
103   !  Passed Arguments
104      integer, intent(inout) :: nDim !! Number of dimensions
105      !! mpiComponentPlan struct from C
106      type (mpiComponentPlan), intent(inout) :: thisComponentPlan  
107 <    integer :: status
108 <    
109 <    if (componentPlanSet) return
110 <    
107 >    integer, intent(out) :: status
108 >    integer, intnet(out) :: localStatus
109 >
110 >    status = 0
111 >    if (componentPlanSet) then
112 >       return
113 >    endif
114 >
115      componentPlanSet = .true.
116  
117 <    call make_Force_Grid(thisComponentPlan,status)
118 <    call updateGriComponents(thisComponentPlan,status)
119 <    
117 >    call make_Force_Grid(thisComponentPlan,localStatus)
118 >    if (localStatus /= 0) then
119 >       status = -1
120 >       return
121 >    endif
122  
123 <    call plan_gather_scatter(1,thisComponentPlan,row_comm,plan_row)
124 <    call plan_gather_scatter(nDim,thisComponentPlan,row_comm,plan_row3d)
125 <    call plan_gather_scatter(1,thisComponentPlan,col_comm,plan_col)
126 <    call plan_gather_scatte(nDim,thisComponentPlan,col_comm,plan_col3d)
123 >    call updateGridComponents(thisComponentPlan,localStatus)
124 >    if (localStatus /= 0) then
125 >       status = -1
126 >       return
127 >    endif
128 >    
129 >    !! initialize gather and scatter plans used in this simulation
130 >    call plan_gather_scatter(nDim,thisComponentPlan%nComponentsRow,&
131 >         thisComponentPlan,row_comm,plan_row)
132 >    call plan_gather_scatter(nDim,thisComponentPlan%nComponentsRow,&
133 >         thisComponentPlan,row_comm,plan_row3d)
134 >    call plan_gather_scatter(nDim,thisComponentPlan%nComponentsColumn,&
135 >         thisComponentPlan,col_comm,plan_col)
136 >    call plan_gather_scatter(nDim,thisComponentPlan%nComponentsColumn,&
137 >         thisComponentPlan,col_comm,plan_col3d)
138  
139  
140  
# Line 242 | Line 262 | contains
262  
263  
264    !! initalizes a gather scatter plan
265 <  subroutine plan_gather_scatter( nDim,thisComponentPlan, &
266 <       thisComm, this_plan)  
265 >  subroutine plan_gather_scatter( nDim,nComponents,thisComponentPlan, &
266 >       thisComm, this_plan,status)  
267      integer, intent(in) :: nDim !! Number of dimensions for gather scatter plan
268 <    type (mpiComponentPlan), intent(in) :: thisComponentPlan
268 >    integer, intent(in) :: nComponents
269 >    type (mpiComponentPlan), intent(in), target :: thisComponentPlan
270      type (gs_plan), intent(out) :: this_plan !! MPI Component Plan
271 <    integer, intent(in) :: thisComm !!
272 <    integer :: sizeof_int
271 >    integer, intent(in) :: thisComm !! MPI communicator for this plan
272 >
273 >    integer :: arraySize !! size to allocate plan for
274 >    integer, intent(out), optional :: status
275      integer :: ierror
253    integer :: comm
254    integer :: me
255    integer :: comm_procs
276      integer :: i,junk
257    integer :: number_of_particles
277  
278 +    if (present(status)) status = 0
279 +  
280  
281 + !! Set gsComponetPlan pointer
282 + !! to the componet plan we want to use for this gather scatter plan.
283 + !! WARNING this could be dangerous since thisComponentPlan was origionally
284 + !! allocated in C++ and there is a significant difference between c and
285 + !! f95 pointers....  
286 +    gsComponentPlan => thisComponetPlan
287  
288 <    number_of_particles = 0
289 <    call mpi_comm_dup(orig_comm,comm,mpi_err)
263 <    call mpi_comm_rank(comm,me,mpi_err)
264 <    call mpi_comm_size(comm,comm_procs,mpi_err)
288 > ! Set this plan size for displs array.
289 >    this_plan%gsPlanSize = nDim * nComponents
290  
291 <    sizeof_int = selected_int_kind(4)
291 > ! Duplicate communicator for this plan
292 >    call mpi_comm_dup(thisComm,this_plan%myPlanComm,mpi_err)
293 >    if (mpi_err /= 0) then
294 >       if (present(status)) status = -1
295 >       return
296 >    end if
297 >    call mpi_comm_rank(this_plan%myPlanComm,this_plan%myPlanRank,mpi_err)
298 >    if (mpi_err /= 0) then
299 >       if (present(status)) status = -1
300 >       return
301 >    end if
302  
303 <    allocate (this_plan%counts(0:comm_procs-1),STAT=ierror)
269 <    if (ierror /= 0) then
303 >    call mpi_comm_size(this_plan%myPlanComm,this_plan%planNprocs,mpi_err)
304  
305 +    if (mpi_err /= 0) then
306 +       if (present(status)) status = -1
307 +       return
308      end if
309  
310 <    allocate (this_plan%displs(0:comm_procs-1),STAT=ierror)
310 >    !! counts and displacements arrays are indexed from 0 to be compatable
311 >    !! with MPI arrays.
312 >    allocate (this_plan%counts(0:this_plan%planNprocs-1),STAT=ierror)
313      if (ierror /= 0) then
314 +       if (present(status)) status = -1
315 +       return
316 +    end if
317  
318 +    allocate (this_plan%displs(0:this_plan%planNprocs-1),STAT=ierror)
319 +    if (ierror /= 0) then
320 +       if (present(status)) status = -1
321 +       return
322      end if
323  
324 <
325 <    call mpi_allgather(local_number,1,mpi_integer,this_plan%counts, &
324 >   !! gather all the local sizes into a size # processors array.
325 >    call mpi_allgather(gs_plan%gsPlanSize,1,mpi_integer,this_plan%counts, &
326           1,mpi_integer,comm,mpi_err)
327 +
328 +    if (mpi_err /= 0) then
329 +       if (present(status)) status = -1
330 +       return
331 +    end if
332    
333  
334      !! figure out the total number of particles in this plan
335 <    number_of_particles = sum(this_plan%counts)
335 >    this_plan%globalPlanSize = sum(this_plan%counts)
336    
337  
338 <    !initialize plan
338 >    !! initialize plan displacements.
339      this_plan%displs(0) = 0
340 <    do i = 1, comm_procs - 1,1
340 >    do i = 1, this_plan%planNprocs - 1,1
341         this_plan%displs(i) = this_plan%displs(i-1) + this_plan%counts(i-1)
342      end do
343  
293
294    this_plan%me = me
295    this_plan%nprocs = comm_procs
296    this_plan%full_size = number_of_particles
297    this_plan%comm = comm
298    this_plan%n_datum = local_number
299
344    end subroutine plan_gather_scatter
345  
346  
347    subroutine unplan_gather_scatter(this_plan)
304
348      type (gs_plan), intent(inout) :: this_plan
349 <
349 >    
350 >    
351 >    this_plan%gsComponentPlan => null()
352      call mpi_comm_free(this_plan%comm,mpi_err)
353  
354      deallocate(this_plan%counts)
# Line 320 | Line 365 | contains
365      integer, intent(out), optional :: status
366  
367      if (present(status)) status = 0
368 <    noffset = this_plan%displs(this_plan%me)
368 >    noffset = this_plan%displs(this_plan%myPlanRank)
369  
370 <    call mpi_allgatherv(sbuffer,this_plan%n_datum, mpi_integer, &
370 >    call mpi_allgatherv(sbuffer,this_plan%gsPlanSize, mpi_integer, &
371           rbuffer,this_plan%counts,this_plan%displs,mpi_integer, &
372 <         this_plan%comm, mpi_err)
372 >         this_plan%myPlanComm, mpi_err)
373  
374      if (mpi_err /= 0) then
375        if (present(status)) status  = -1
# Line 343 | Line 388 | contains
388      if (present(status)) status = 0
389      noffset = this_plan%displs(this_plan%me)
390  
391 <    call mpi_allgatherv(sbuffer,this_plan%n_datum, mpi_double_precision, &
391 >    call mpi_allgatherv(sbuffer,this_plan%gsPlanSize, mpi_double_precision, &
392           rbuffer,this_plan%counts,this_plan%displs,mpi_double_precision, &
393 <         this_plan%comm, mpi_err)
393 >         this_plan%myPlanComm, mpi_err)
394  
395      if (mpi_err /= 0) then
396        if (present(status)) status  = -1
# Line 367 | Line 412 | contains
412  
413   !    noffset = this_plan%displs(this_plan%me)
414      
415 <    call mpi_allgatherv(sbuffer,this_plan%n_datum, mpi_double_precision, &
415 >    call mpi_allgatherv(sbuffer,this_plan%gsPlanSize, mpi_double_precision, &
416          rbuffer,this_plan%counts,this_plan%displs,mpi_double_precision, &
417 <        this_plan%comm, mpi_err)
417 >        this_plan%myPlanComm, mpi_err)
418  
419      if (mpi_err /= 0) then
420        if (present(status)) status = -1
# Line 388 | Line 433 | contains
433     if (present(status)) status = 0
434  
435      call mpi_reduce_scatter(sbuffer,rbuffer, this_plan%counts, &
436 <         mpi_double_precision, MPI_SUM, this_plan%comm, mpi_err)
436 >         mpi_double_precision, MPI_SUM, this_plan%myPlanComm, mpi_err)
437  
438      if (mpi_err /= 0) then
439       if (present(status))  status = -1
# Line 406 | Line 451 | contains
451  
452     if (present(status)) status = 0
453      call mpi_reduce_scatter(sbuffer,rbuffer, this_plan%counts, &
454 <         mpi_double_precision, MPI_SUM, this_plan%comm, mpi_err)
454 >         mpi_double_precision, MPI_SUM, this_plan%myPlanComm, mpi_err)
455  
456      if (mpi_err /= 0) then
457        if (present(status)) status = -1

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines