5 |
|
!! |
6 |
|
!! @author Charles F. Vardeman II |
7 |
|
!! @author Matthew Meineke |
8 |
< |
!! @version $Id: mpiSimulation_module.F90,v 1.4 2003-01-30 15:20:21 chuckv Exp $, $Date: 2003-01-30 15:20:21 $, $Name: not supported by cvs2svn $, $Revision: 1.4 $ |
8 |
> |
!! @version $Id: mpiSimulation_module.F90,v 1.7 2003-01-31 21:04:27 chuckv Exp $, $Date: 2003-01-31 21:04:27 $, $Name: not supported by cvs2svn $, $Revision: 1.7 $ |
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
module mpiSimulation |
14 |
< |
#ifdef IS_MPI |
14 |
> |
use definitions |
15 |
|
use mpi |
16 |
|
implicit none |
17 |
|
PRIVATE |
26 |
|
public :: getNcol |
27 |
|
public :: getNrow |
28 |
|
public :: isMPISimSet |
29 |
+ |
public :: printComponentPlan |
30 |
+ |
public :: getMyNode |
31 |
|
|
30 |
– |
|
32 |
|
!! PUBLIC Subroutines contained in MPI module |
33 |
|
public :: mpi_bcast |
34 |
|
public :: mpi_allreduce |
56 |
|
!! generic mpi error declaration. |
57 |
|
integer,public :: mpi_err |
58 |
|
|
59 |
+ |
|
60 |
|
|
59 |
– |
|
61 |
|
!! Include mpiComponentPlan type. mpiComponentPlan is a |
62 |
|
!! dual header file for both c and fortran. |
63 |
|
#define __FORTRAN90 |
73 |
|
!! Logical set true if mpiSimulation has been initialized |
74 |
|
logical :: isSimSet = .false. |
75 |
|
|
76 |
+ |
|
77 |
+ |
type (mpiComponentPlan) :: mpiSim |
78 |
+ |
|
79 |
|
!! gs_plan contains plans for gather and scatter routines |
80 |
|
type, public :: gs_plan |
81 |
|
private |
135 |
|
!! Global reference tag for local particles |
136 |
|
integer, dimension(ntags),intent(inout) :: tags |
137 |
|
|
138 |
+ |
|
139 |
|
status = 0 |
140 |
|
if (componentPlanSet) then |
141 |
|
return |
142 |
|
endif |
138 |
– |
|
143 |
|
componentPlanSet = .true. |
144 |
+ |
|
145 |
+ |
!! copy c component plan to fortran |
146 |
+ |
mpiSim = thisComponentPlan |
147 |
+ |
write(*,*) "Seting up simParallel" |
148 |
|
|
149 |
< |
call make_Force_Grid(thisComponentPlan,localStatus) |
149 |
> |
call make_Force_Grid(mpiSim,localStatus) |
150 |
|
if (localStatus /= 0) then |
151 |
+ |
write(default_error,*) "Error creating force grid" |
152 |
|
status = -1 |
153 |
|
return |
154 |
|
endif |
155 |
|
|
156 |
< |
call updateGridComponents(thisComponentPlan,localStatus) |
156 |
> |
call updateGridComponents(mpiSim,localStatus) |
157 |
|
if (localStatus /= 0) then |
158 |
+ |
write(default_error,*) "Error updating grid components" |
159 |
|
status = -1 |
160 |
|
return |
161 |
|
endif |
162 |
|
|
163 |
+ |
|
164 |
|
!! initialize gather and scatter plans used in this simulation |
165 |
< |
call plan_gather_scatter(1,thisComponentPlan%nComponentsRow,& |
166 |
< |
thisComponentPlan,row_comm,plan_row) |
167 |
< |
call plan_gather_scatter(nDim,thisComponentPlan%nComponentsRow,& |
168 |
< |
thisComponentPlan,row_comm,plan_row3d) |
169 |
< |
call plan_gather_scatter(1,thisComponentPlan%nComponentsColumn,& |
170 |
< |
thisComponentPlan,col_comm,plan_col) |
171 |
< |
call plan_gather_scatter(nDim,thisComponentPlan%nComponentsColumn,& |
172 |
< |
thisComponentPlan,col_comm,plan_col3d) |
165 |
> |
call plan_gather_scatter(1,mpiSim%myNlocal,& |
166 |
> |
mpiSim,mpiSim%rowComm,plan_row) |
167 |
> |
call plan_gather_scatter(nDim,mpiSim%myNlocal,& |
168 |
> |
mpiSim,mpiSim%rowComm,plan_row3d) |
169 |
> |
call plan_gather_scatter(1,mpiSim%myNlocal,& |
170 |
> |
mpiSim,mpiSim%columnComm,plan_col) |
171 |
> |
call plan_gather_scatter(nDim,mpiSim%myNlocal,& |
172 |
> |
mpiSim,mpiSim%columnComm,plan_col3d) |
173 |
|
|
174 |
|
! Initialize tags |
175 |
|
call setTags(tags,localStatus) |
178 |
|
return |
179 |
|
endif |
180 |
|
isSimSet = .true. |
181 |
+ |
|
182 |
+ |
! call printComponentPlan(mpiSim,0) |
183 |
|
end subroutine setupSimParallel |
184 |
|
|
185 |
|
subroutine replanSimParallel(thisComponentPlan,status) |
187 |
|
!! mpiComponentPlan struct from C |
188 |
|
type (mpiComponentPlan), intent(inout) :: thisComponentPlan |
189 |
|
integer, intent(out) :: status |
190 |
< |
integer, intent(out) :: localStatus |
191 |
< |
|
190 |
> |
integer :: localStatus |
191 |
> |
integer :: mpierror |
192 |
|
status = 0 |
193 |
|
|
194 |
|
call updateGridComponents(thisComponentPlan,localStatus) |
205 |
|
|
206 |
|
|
207 |
|
!! initialize gather and scatter plans used in this simulation |
208 |
< |
call plan_gather_scatter(1,thisComponentPlan%nComponentsRow,& |
209 |
< |
thisComponentPlan,row_comm,plan_row) |
210 |
< |
call plan_gather_scatter(nDim,thisComponentPlan%nComponentsRow,& |
211 |
< |
thisComponentPlan,row_comm,plan_row3d) |
212 |
< |
call plan_gather_scatter(1,thisComponentPlan%nComponentsColumn,& |
213 |
< |
thisComponentPlan,col_comm,plan_col) |
214 |
< |
call plan_gather_scatter(nDim,thisComponentPlan%nComponentsColumn,& |
215 |
< |
thisComponentPlan,col_comm,plan_col3d) |
208 |
> |
call plan_gather_scatter(1,thisComponentPlan%myNlocal,& |
209 |
> |
thisComponentPlan,thisComponentPlan%rowComm,plan_row) |
210 |
> |
call plan_gather_scatter(nDim,thisComponentPlan%myNlocal,& |
211 |
> |
thisComponentPlan,thisComponentPlan%rowComm,plan_row3d) |
212 |
> |
call plan_gather_scatter(1,thisComponentPlan%myNlocal,& |
213 |
> |
thisComponentPlan,thisComponentPlan%columnComm,plan_col) |
214 |
> |
call plan_gather_scatter(nDim,thisComponentPlan%myNlocal,& |
215 |
> |
thisComponentPlan,thisComponentPlan%rowComm,plan_col3d) |
216 |
|
|
217 |
|
|
218 |
|
|
228 |
|
integer, intent(out) :: status |
229 |
|
integer :: nComponentsLocal |
230 |
|
integer :: nComponentsRow = 0 |
231 |
< |
integer :: nComponensColumn = 0 |
231 |
> |
integer :: nComponentsColumn = 0 |
232 |
|
integer :: mpiErrors |
233 |
|
|
234 |
|
status = 0 |
242 |
|
nComponentsLocal = thisComponentPlan%myNlocal |
243 |
|
|
244 |
|
call mpi_allreduce(nComponentsLocal,nComponentsRow,1,mpi_integer,& |
245 |
< |
mpi_sum,thisComponentPlan%rowComm,mpiError) |
245 |
> |
mpi_sum,thisComponentPlan%rowComm,mpiErrors) |
246 |
|
if (mpiErrors /= 0) then |
247 |
|
status = -1 |
248 |
|
return |
249 |
|
endif |
250 |
|
|
251 |
|
call mpi_allreduce(nComponentsLocal,nComponentsColumn,1,mpi_integer, & |
252 |
< |
mpi_sum,thisComponentPlan%columnComm,mpiError) |
252 |
> |
mpi_sum,thisComponentPlan%columnComm,mpiErrors) |
253 |
|
if (mpiErrors /= 0) then |
254 |
|
status = -1 |
255 |
|
return |
282 |
|
|
283 |
|
if (.not. ComponentPlanSet) return |
284 |
|
status = 0 |
285 |
< |
|
285 |
> |
|
286 |
|
!! We make a dangerous assumption here that if numberProcessors is |
287 |
|
!! zero, then we need to get the information from MPI. |
288 |
|
if (thisComponentPlan%numberProcessors == 0 ) then |
314 |
|
nRows = nWorldProcessors/nColumns |
315 |
|
|
316 |
|
rowIndex = myWorldRank/nColumns |
317 |
< |
call mpi_comm_split(mpi_comm_world,rowIndex,0,rowCommunicator,mpiError) |
317 |
> |
|
318 |
> |
|
319 |
> |
|
320 |
> |
call mpi_comm_split(mpi_comm_world,rowIndex,0,rowCommunicator,mpiErrors) |
321 |
|
if ( mpiErrors /= 0 ) then |
322 |
+ |
write(default_error,*) "MPI comm split failed at row communicator" |
323 |
|
status = -1 |
324 |
|
return |
325 |
|
endif |
326 |
|
|
327 |
|
columnIndex = mod(myWorldRank,nColumns) |
328 |
< |
call mpi_comm_split(mpi_comm_world,columnIndex,0,columnCommunicator,mpiError) |
328 |
> |
call mpi_comm_split(mpi_comm_world,columnIndex,0,columnCommunicator,mpiErrors) |
329 |
|
if ( mpiErrors /= 0 ) then |
330 |
+ |
write(default_error,*) "MPI comm split faild at columnCommunicator" |
331 |
|
status = -1 |
332 |
|
return |
333 |
|
endif |
359 |
|
integer :: i,junk |
360 |
|
|
361 |
|
if (present(status)) status = 0 |
362 |
+ |
|
363 |
|
|
364 |
|
|
365 |
|
!! Set gsComponetPlan pointer |
367 |
|
!! WARNING this could be dangerous since thisComponentPlan was origionally |
368 |
|
!! allocated in C++ and there is a significant difference between c and |
369 |
|
!! f95 pointers.... |
370 |
< |
gsComponentPlan => thisComponetPlan |
370 |
> |
this_plan%gsComponentPlan => thisComponentPlan |
371 |
|
|
372 |
|
! Set this plan size for displs array. |
373 |
|
this_plan%gsPlanSize = nDim * nComponents |
407 |
|
|
408 |
|
!! gather all the local sizes into a size # processors array. |
409 |
|
call mpi_allgather(this_plan%gsPlanSize,1,mpi_integer,this_plan%counts, & |
410 |
< |
1,mpi_integer,comm,mpi_err) |
410 |
> |
1,mpi_integer,thisComm,mpi_err) |
411 |
|
|
412 |
|
if (mpi_err /= 0) then |
413 |
|
if (present(status)) status = -1 |
425 |
|
this_plan%displs(i) = this_plan%displs(i-1) + this_plan%counts(i-1) |
426 |
|
end do |
427 |
|
|
428 |
+ |
|
429 |
|
end subroutine plan_gather_scatter |
430 |
|
|
431 |
|
|
448 |
|
integer, dimension(:), intent(in) :: rbuffer |
449 |
|
integer :: noffset |
450 |
|
integer, intent(out), optional :: status |
451 |
+ |
integer :: i |
452 |
|
|
453 |
+ |
|
454 |
+ |
|
455 |
|
if (present(status)) status = 0 |
456 |
|
noffset = this_plan%displs(this_plan%myPlanRank) |
457 |
|
|
458 |
+ |
! if (getmyNode() == 1) then |
459 |
+ |
! write(*,*) "Node 0 printing allgatherv vars" |
460 |
+ |
! write(*,*) "Noffset: ", noffset |
461 |
+ |
! write(*,*) "PlanSize: ", this_plan%gsPlanSize |
462 |
+ |
! write(*,*) "PlanComm: ", this_plan%myPlanComm |
463 |
+ |
! end if |
464 |
+ |
|
465 |
|
call mpi_allgatherv(sbuffer,this_plan%gsPlanSize, mpi_integer, & |
466 |
|
rbuffer,this_plan%counts,this_plan%displs,mpi_integer, & |
467 |
|
this_plan%myPlanComm, mpi_err) |
480 |
|
integer :: noffset |
481 |
|
integer, intent(out), optional :: status |
482 |
|
|
483 |
+ |
|
484 |
|
if (present(status)) status = 0 |
485 |
|
noffset = this_plan%displs(this_plan%myPlanRank) |
486 |
|
|
586 |
|
|
587 |
|
endif |
588 |
|
! allocate column arrays |
589 |
< |
if (.not. allocated(tagCol)) then |
589 |
> |
if (.not. allocated(tagColumn)) then |
590 |
|
allocate(tagColumn(ncol),STAT=alloc_stat) |
591 |
|
if (alloc_stat /= 0 ) then |
592 |
|
status = -1 |
629 |
|
end function isMPISimSet |
630 |
|
|
631 |
|
|
632 |
< |
|
633 |
< |
#endif |
632 |
> |
|
633 |
> |
subroutine printComponentPlan(this_plan,printNode) |
634 |
> |
|
635 |
> |
type (mpiComponentPlan), intent(in) :: this_plan |
636 |
> |
integer, optional :: printNode |
637 |
> |
logical :: print_me = .false. |
638 |
> |
|
639 |
> |
if (present(printNode)) then |
640 |
> |
if (printNode == mpiSim%myNode) print_me = .true. |
641 |
> |
else |
642 |
> |
print_me = .true. |
643 |
> |
endif |
644 |
> |
|
645 |
> |
if (print_me) then |
646 |
> |
write(default_error,*) "SetupSimParallel: writing component plan" |
647 |
> |
|
648 |
> |
write(default_error,*) "nMolGlobal: ", mpiSim%nMolGlobal |
649 |
> |
write(default_error,*) "nAtomsGlobal: ", mpiSim%nAtomsGlobal |
650 |
> |
write(default_error,*) "nBondGlobal: ", mpiSim%nBondsGlobal |
651 |
> |
write(default_error,*) "nTorsionsGlobal: ", mpiSim%nTorsionsGlobal |
652 |
> |
write(default_error,*) "nSRIGlobal: ", mpiSim%nSRIGlobal |
653 |
> |
write(default_error,*) "myMolStart: ", mpiSim%myMolStart |
654 |
> |
write(default_error,*) "myMolEnd: ", mpiSim%myMolEnd |
655 |
> |
write(default_error,*) "myMol: ", mpiSim%myMol |
656 |
> |
write(default_error,*) "myNlocal: ", mpiSim%myNlocal |
657 |
> |
write(default_error,*) "myNode: ", mpiSim%myNode |
658 |
> |
write(default_error,*) "numberProcessors: ", mpiSim%numberProcessors |
659 |
> |
write(default_error,*) "rowComm: ", mpiSim%rowComm |
660 |
> |
write(default_error,*) "columnComm: ", mpiSim%columnComm |
661 |
> |
write(default_error,*) "numberRows: ", mpiSim%numberRows |
662 |
> |
write(default_error,*) "numberColumns: ", mpiSim%numberColumns |
663 |
> |
write(default_error,*) "nComponentsRow: ", mpiSim%nComponentsRow |
664 |
> |
write(default_error,*) "nComponentsColumn: ", mpiSim%nComponentsColumn |
665 |
> |
write(default_error,*) "rowIndex: ", mpiSim%rowIndex |
666 |
> |
write(default_error,*) "columnIndex: ", mpiSim%columnIndex |
667 |
> |
endif |
668 |
> |
end subroutine printComponentPlan |
669 |
> |
|
670 |
> |
function getMyNode() result(myNode) |
671 |
> |
integer :: myNode |
672 |
> |
myNode = mpiSim%myNode |
673 |
> |
end function getMyNode |
674 |
> |
|
675 |
> |
|
676 |
|
end module mpiSimulation |
677 |
|
|