Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RFLU_ModRegionMapping.F90
Go to the documentation of this file.
1 ! *********************************************************************
2 ! * Rocstar Simulation Suite *
3 ! * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4 ! * *
5 ! * Illinois Rocstar LLC *
6 ! * Champaign, IL *
7 ! * www.illinoisrocstar.com *
8 ! * sales@illinoisrocstar.com *
9 ! * *
10 ! * License: See LICENSE file in top level of distribution package or *
11 ! * http://opensource.org/licenses/NCSA *
12 ! *********************************************************************
13 ! *********************************************************************
14 ! * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15 ! * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16 ! * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17 ! * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18 ! * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19 ! * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20 ! * Arising FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21 ! * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22 ! *********************************************************************
23 ! ******************************************************************************
24 !
25 ! Purpose: Collection of routines relating to mapping of regions to processes.
26 !
27 ! Description: None.
28 !
29 ! Input: None.
30 !
31 ! Output: None.
32 !
33 ! Notes: None.
34 !
35 ! ******************************************************************************
36 !
37 ! $Id: RFLU_ModRegionMapping.F90,v 1.7 2008/12/06 08:44:23 mtcampbe Exp $
38 !
39 ! Copyright: (c) 2004-2005 by the University of Illinois
40 !
41 ! ******************************************************************************
42 
44 
45  USE modparameters
46  USE moddatatypes
47  USE moderror
48  USE modglobal, ONLY: t_global
49  USE moddatastruct, ONLY: t_level
50  USE modmpi
51 
53 
54  IMPLICIT NONE
55 
56  PRIVATE
57  PUBLIC :: rflu_applyregionmapping, &
69 
70 ! ******************************************************************************
71 ! Declarations and definitions
72 ! ******************************************************************************
73 
74  CHARACTER(CHRLEN) :: RCSIdentString = &
75  '$RCSfile: RFLU_ModRegionMapping.F90,v $ $Revision: 1.7 $'
76 
77  INTEGER, PARAMETER, PUBLIC :: MAPTYPE_REG = 1, &
78  MAPTYPE_PROC2REG = 2
79 
80 ! ******************************************************************************
81 ! Routines
82 ! ******************************************************************************
83 
84  CONTAINS
85 
86 
87 
88 
89 
90 
91 
92 
93 
94 ! ******************************************************************************
95 !
96 ! Purpose: Apply region mapping.
97 !
98 ! Description: None.
99 !
100 ! Input:
101 ! global Pointer to global type
102 !
103 ! Output: None.
104 !
105 ! Notes: None.
106 !
107 ! ******************************************************************************
108 
109 SUBROUTINE rflu_applyregionmapping(global,levels)
110 
111  IMPLICIT NONE
112 
113 ! ******************************************************************************
114 ! Declarations and definitions
115 ! ******************************************************************************
116 
117 ! ==============================================================================
118 ! Arguments
119 ! ==============================================================================
120 
121  TYPE(t_level), POINTER :: levels(:)
122  TYPE(t_global), POINTER :: global
123 
124 ! ==============================================================================
125 ! Local variables
126 ! ==============================================================================
127 
128  INTEGER :: errorflag,ilev,ireg
129 
130 ! ******************************************************************************
131 ! Start
132 ! ******************************************************************************
133 
134  CALL registerfunction(global,'RFLU_ApplyRegionMapping',&
135  'RFLU_ModRegionMapping.F90')
136 
137  IF ( global%myProcid == masterproc .AND. &
138  global%verbLevel >= verbose_high ) THEN
139  WRITE(stdout,'(A,1X,A)') solver_name,'Applying region mapping...'
140  END IF ! global%verbLevel
141 
142 ! ******************************************************************************
143 ! Copy global region number into region type
144 ! ******************************************************************************
145 
146  ilev = 1
147 
148  DO ireg = 0,global%nRegionsLocal
149  levels(ilev)%regions(ireg)%iRegionGlobal = global%regMap(ireg)
150  END DO ! iReg
151 
152  DO ilev = 2,global%nLevels
153  DO ireg = 1,global%nRegionsLocal
154  levels(ilev)%regions(ireg)%iRegionGlobal = global%regMap(ireg)
155  END DO ! iReg
156  END DO ! iLev
157 
158 ! ******************************************************************************
159 ! End
160 ! ******************************************************************************
161 
162  IF ( global%myProcid == masterproc .AND. &
163  global%verbLevel >= verbose_high ) THEN
164  WRITE(stdout,'(A,1X,A)') solver_name,'Applying region mapping done.'
165  END IF ! global%verbLevel
166 
167  CALL deregisterfunction(global)
168 
169 END SUBROUTINE rflu_applyregionmapping
170 
171 
172 
173 
174 
175 
176 
177 ! ******************************************************************************
178 !
179 ! Purpose: Build simple region mapping.
180 !
181 ! Description: None.
182 !
183 ! Input:
184 ! global Pointer to global data
185 !
186 ! Output: None.
187 !
188 ! Notes:
189 ! 1. This mapping simply maps an equal number of regions to each process
190 ! without looking at the dimensions of each region.
191 ! 2. If the number of regions is not divisible by the number of processes,
192 ! the last process gets the remainder of regions.
193 !
194 ! ******************************************************************************
195 
197 
198 ! ******************************************************************************
199 ! Declarations and definitions
200 ! ******************************************************************************
201 
202 ! ==============================================================================
203 ! Arguments
204 ! ==============================================================================
205 
206  TYPE(t_global), POINTER :: global
207 
208 ! ==============================================================================
209 ! Locals
210 ! ==============================================================================
211 
212  INTEGER :: i,ibeg,iend,ioffset,iproc,nregsperproc
213 
214 ! ******************************************************************************
215 ! Start
216 ! ******************************************************************************
217 
218  CALL registerfunction(global,'RFLU_BuildRegionMappingSimple',&
219  'RFLU_ModRegionMapping.F90')
220 
221  IF ( global%myProcid == masterproc .AND. &
222  global%verbLevel >= verbose_med) THEN
223  WRITE(stdout,'(A,1X,A)') solver_name,'Building region mapping...'
224  WRITE(stdout,'(A,3X,A)') solver_name,'Method: Simple'
225  END IF ! global%verbLevel
226 
227 ! ******************************************************************************
228 ! Build simple region mapping
229 ! ******************************************************************************
230 
231  nregsperproc = global%nRegions/global%nProcs ! NOTE integer division
232 
233  IF ( global%nRegions > 1 ) THEN
234  ioffset = 0
235  ELSE
236  ioffset = 1
237  END IF ! global%nRegions
238 
239  DO iproc = 1,global%nProcs
240  IF ( iproc > 1 ) THEN
241  ibeg = global%proc2RegMapInfo(2,iproc-1) + 1
242  ELSE
243  ibeg = 1
244  END IF ! iProc
245 
246  IF ( iproc /= global%nProcs ) THEN
247  iend = ibeg + nregsperproc - 1
248  ELSE ! Add remainder to last process
249  iend = global%nRegions
250  END IF ! iProc
251 
252  global%proc2RegMapInfo(1,iproc) = ibeg
253  global%proc2RegMapInfo(2,iproc) = iend
254 
255  DO i = ibeg,iend
256  global%proc2RegMap(i) = i - ioffset
257  END DO ! i
258  END DO ! iProc
259 
260 ! ******************************************************************************
261 ! End
262 ! ******************************************************************************
263 
264  IF ( global%myProcid == masterproc .AND. &
265  global%verbLevel >= verbose_high ) THEN
266  WRITE(stdout,'(A,1X,A)') solver_name,'Building region mapping done.'
267  END IF ! global%verbLevel
268 
269  CALL deregisterfunction(global)
270 
271 END SUBROUTINE rflu_buildregionmappingsimple
272 
273 
274 
275 
276 
277 
278 
279 
280 ! ******************************************************************************
281 !
282 ! Purpose: Check region mapping.
283 !
284 ! Description: None.
285 !
286 ! Input:
287 ! global Pointer to global data
288 !
289 ! Output: None.
290 !
291 ! Notes: None.
292 !
293 ! ******************************************************************************
294 
295 SUBROUTINE rflu_checkregionmapping(global)
296 
297  USE modsortsearch, ONLY: quicksortinteger
298 
299 ! ******************************************************************************
300 ! Declarations and definitions
301 ! ******************************************************************************
302 
303 ! ==============================================================================
304 ! Arguments
305 ! ==============================================================================
306 
307  TYPE(t_global), POINTER :: global
308 
309 ! ==============================================================================
310 ! Locals
311 ! ==============================================================================
312 
313  INTEGER :: checksum,errorflag,i
314  INTEGER, DIMENSION(:), ALLOCATABLE :: proc2regmaptemp
315 
316 ! ******************************************************************************
317 ! Start
318 ! ******************************************************************************
319 
320  CALL registerfunction(global,'RFLU_CheckRegionMapping',&
321  'RFLU_ModRegionMapping.F90')
322 
323  IF ( global%myProcid == masterproc .AND. &
324  global%verbLevel >= verbose_high ) THEN
325  WRITE(stdout,'(A,1X,A)') solver_name,'Checking region mapping...'
326  END IF ! global%verbLevel
327 
328 ! ******************************************************************************
329 ! Check region mapping
330 ! ******************************************************************************
331 
332  IF ( global%nRegions > 1 ) THEN
333  ALLOCATE(proc2regmaptemp(global%nRegions),stat=errorflag)
334  global%error = errorflag
335  IF ( global%error /= err_none ) THEN
336  CALL errorstop(global,err_allocate,__line__,'proc2RegMapTemp')
337  END IF ! global%error
338 
339  DO i = 1,global%nRegions
340  proc2regmaptemp(i) = global%proc2RegMap(i)
341  END DO ! i
342 
343  CALL quicksortinteger(proc2regmaptemp,global%nRegions)
344 
345  checksum = 0
346 
347  DO i = 1,global%nRegions
348  checksum = checksum + proc2regmaptemp(i)
349  END DO ! i
350 
351  IF ( checksum /= global%nRegions*(global%nRegions+1)/2 ) THEN
352  CALL errorstop(global,err_proc2reg_mapping,__line__)
353  END IF ! checkSum
354 
355  DEALLOCATE(proc2regmaptemp,stat=errorflag)
356  global%error = errorflag
357  IF ( global%error /= err_none ) THEN
358  CALL errorstop(global,err_deallocate,__line__,'proc2RegMapTemp')
359  END IF ! global%error
360  END IF ! global%nRegions
361 
362 ! ******************************************************************************
363 ! End
364 ! ******************************************************************************
365 
366  IF ( global%myProcid == masterproc .AND. &
367  global%verbLevel >= verbose_high ) THEN
368  WRITE(stdout,'(A,1X,A)') solver_name,'Checking region mapping done.'
369  END IF ! global%verbLevel
370 
371  CALL deregisterfunction(global)
372 
373 END SUBROUTINE rflu_checkregionmapping
374 
375 
376 
377 
378 
379 
380 
381 
382 ! ******************************************************************************
383 !
384 ! Purpose: Close region mapping file.
385 !
386 ! Description: None.
387 !
388 ! Input:
389 ! global Pointer to global data
390 !
391 ! Output: None.
392 !
393 ! Notes: None.
394 !
395 ! ******************************************************************************
396 
397 SUBROUTINE rflu_closeregionmappingfile(global)
398 
399 ! ******************************************************************************
400 ! Declarations and definitions
401 ! ******************************************************************************
402 
403 ! ==============================================================================
404 ! Arguments
405 ! ==============================================================================
406 
407  TYPE(t_global), POINTER :: global
408 
409 ! ==============================================================================
410 ! Locals
411 ! ==============================================================================
412 
413  CHARACTER(CHRLEN) :: ifilename
414  INTEGER :: errorflag
415 
416 ! ******************************************************************************
417 ! Start
418 ! ******************************************************************************
419 
420  CALL registerfunction(global,'RFLU_CloseRegionMappingFile',&
421  'RFLU_ModRegionMapping.F90')
422 
423  IF ( global%myProcid == masterproc .AND. &
424  global%verbLevel >= verbose_high ) THEN
425  WRITE(stdout,'(A,1X,A)') solver_name,'Closing region mapping file...'
426  END IF ! global%verbLevel
427 
428 ! ******************************************************************************
429 ! Close file
430 ! ******************************************************************************
431 
432  CALL buildfilenameplain(global,filedest_indir,'.map',ifilename)
433 
434  CLOSE(if_regmap,iostat=errorflag)
435  global%error = errorflag
436  IF ( global%error /= err_none ) THEN
437  CALL errorstop(global,err_file_close,__line__,ifilename)
438  END IF ! global%error
439 
440 ! ******************************************************************************
441 ! End
442 ! ******************************************************************************
443 
444  IF ( global%myProcid == masterproc .AND. &
445  global%verbLevel >= verbose_high ) THEN
446  WRITE(stdout,'(A,1X,A)') solver_name,'Closing region mapping file done.'
447  END IF ! global%verbLevel
448 
449  CALL deregisterfunction(global)
450 
451 END SUBROUTINE rflu_closeregionmappingfile
452 
453 
454 
455 
456 
457 
458 
459 
460 ! ******************************************************************************
461 !
462 ! Purpose: Create region mapping.
463 !
464 ! Description: None.
465 !
466 ! Input:
467 ! global Pointer to global data
468 !
469 ! Output: None.
470 !
471 ! Notes: None.
472 !
473 ! ******************************************************************************
474 
475 SUBROUTINE rflu_createregionmapping(global,mapType)
476 
477 ! ******************************************************************************
478 ! Declarations and definitions
479 ! ******************************************************************************
480 
481 ! ==============================================================================
482 ! Arguments
483 ! ==============================================================================
484 
485  INTEGER, INTENT(IN) :: maptype
486  TYPE(t_global), POINTER :: global
487 
488 ! ==============================================================================
489 ! Locals
490 ! ==============================================================================
491 
492  INTEGER :: errorflag
493 
494 ! ******************************************************************************
495 ! Start
496 ! ******************************************************************************
497 
498  CALL registerfunction(global,'RFLU_CreateRegionMapping',&
499  'RFLU_ModRegionMapping.F90')
500 
501  IF ( global%myProcid == masterproc .AND. &
502  global%verbLevel >= verbose_high ) THEN
503  WRITE(stdout,'(A,1X,A)') solver_name,'Creating region mapping...'
504  END IF ! global%verbLevel
505 
506 ! ******************************************************************************
507 ! Create region mapping
508 ! ******************************************************************************
509 
510  IF ( maptype == maptype_reg ) THEN
511  ALLOCATE(global%regMap(0:global%nRegionsLocal),stat=errorflag)
512  global%error = errorflag
513  IF ( global%error /= err_none ) THEN
514  CALL errorstop(global,err_allocate,__line__,'global%regMap')
515  END IF ! global%error
516  ELSE IF ( maptype == maptype_proc2reg ) THEN
517  ALLOCATE(global%proc2RegMap(global%nRegions),stat=errorflag)
518  global%error = errorflag
519  IF ( global%error /= err_none ) THEN
520  CALL errorstop(global,err_allocate,__line__,'global%proc2RegMap')
521  END IF ! global%error
522 
523  ALLOCATE(global%proc2RegMapInfo(2,global%nProcs),stat=errorflag)
524  global%error = errorflag
525  IF ( global%error /= err_none ) THEN
526  CALL errorstop(global,err_allocate,__line__,'global%proc2RegMapInfo')
527  END IF ! global%error
528  ELSE
529  CALL errorstop(global,err_reached_default,__line__)
530  END IF ! mapType
531 
532 ! ******************************************************************************
533 ! End
534 ! ******************************************************************************
535 
536  IF ( global%myProcid == masterproc .AND. &
537  global%verbLevel >= verbose_high ) THEN
538  WRITE(stdout,'(A,1X,A)') solver_name,'Creating region mapping done.'
539  END IF ! global%verbLevel
540 
541  CALL deregisterfunction(global)
542 
543 END SUBROUTINE rflu_createregionmapping
544 
545 
546 
547 
548 
549 
550 
551 
552 ! ******************************************************************************
553 !
554 ! Purpose: Destroy region mapping.
555 !
556 ! Description: None.
557 !
558 ! Input:
559 ! global Pointer to global data
560 !
561 ! Output: None.
562 !
563 ! Notes: None.
564 !
565 ! ******************************************************************************
566 
567 SUBROUTINE rflu_destroyregionmapping(global,mapType)
568 
569 ! ******************************************************************************
570 ! Declarations and definitions
571 ! ******************************************************************************
572 
573 ! ==============================================================================
574 ! Arguments
575 ! ==============================================================================
576 
577  INTEGER, INTENT(IN) :: maptype
578  TYPE(t_global), POINTER :: global
579 
580 ! ==============================================================================
581 ! Locals
582 ! ==============================================================================
583 
584  INTEGER :: errorflag
585 
586 ! ******************************************************************************
587 ! Start
588 ! ******************************************************************************
589 
590  CALL registerfunction(global,'RFLU_DestroyRegionMapping',&
591  'RFLU_ModRegionMapping.F90')
592 
593  IF ( global%myProcid == masterproc .AND. &
594  global%verbLevel >= verbose_high ) THEN
595  WRITE(stdout,'(A,1X,A)') solver_name,'Destroying region mapping...'
596  END IF ! global%verbLevel
597 
598 ! ******************************************************************************
599 ! Create region mapping
600 ! ******************************************************************************
601 
602  IF ( maptype == maptype_reg ) THEN
603  DEALLOCATE(global%regMap,stat=errorflag)
604  global%error = errorflag
605  IF ( global%error /= err_none ) THEN
606  CALL errorstop(global,err_deallocate,__line__,'global%regMap')
607  END IF ! global%error
608  ELSE IF ( maptype == maptype_proc2reg ) THEN
609  DEALLOCATE(global%proc2RegMap,stat=errorflag)
610  global%error = errorflag
611  IF ( global%error /= err_none ) THEN
612  CALL errorstop(global,err_deallocate,__line__,'global%proc2RegMap')
613  END IF ! global%error
614 
615  DEALLOCATE(global%proc2RegMapInfo,stat=errorflag)
616  global%error = errorflag
617  IF ( global%error /= err_none ) THEN
618  CALL errorstop(global,err_deallocate,__line__,'global%proc2RegMapInfo')
619  END IF ! global%error
620  ELSE
621  CALL errorstop(global,err_reached_default,__line__)
622  END IF ! mapType
623 
624 ! ******************************************************************************
625 ! End
626 ! ******************************************************************************
627 
628  IF ( global%myProcid == masterproc .AND. &
629  global%verbLevel >= verbose_high ) THEN
630  WRITE(stdout,'(A,1X,A)') solver_name,'Destroying region mapping done.'
631  END IF ! global%verbLevel
632 
633  CALL deregisterfunction(global)
634 
635 END SUBROUTINE rflu_destroyregionmapping
636 
637 
638 
639 
640 
641 
642 
643 ! ******************************************************************************
644 !
645 ! Purpose: Get process and local region ids given a set of global region ids.
646 !
647 ! Description: None.
648 !
649 ! Input:
650 ! global Pointer to global type
651 ! regIds Set of region ids
652 ! nRegIds Number of region ids
653 !
654 ! Output:
655 ! procIds Set of process ids
656 ! locRegIds Set of local region ids
657 !
658 ! Notes: None.
659 !
660 ! ******************************************************************************
661 
662 SUBROUTINE rflu_getproclocregids(global,regIds,nRegIds,procIds,locRegIds)
663 
664  IMPLICIT NONE
665 
666 ! ******************************************************************************
667 ! Definitions and declarations
668 ! ******************************************************************************
669 
670 ! ==============================================================================
671 ! Parameters
672 ! ==============================================================================
673 
674  INTEGER, INTENT(IN) :: nregids
675  INTEGER, INTENT(IN) :: regids(nregids)
676  INTEGER, INTENT(OUT) :: locregids(nregids),procids(nregids)
677  TYPE(t_global), POINTER :: global
678 
679 ! ==============================================================================
680 ! Locals
681 ! ==============================================================================
682 
683  CHARACTER(CHRLEN) :: sectionstring,targetstring
684  INTEGER :: errorflag,ifile,iproc,ireg,iregid,iregid2,nprocs,nregionsglobal, &
685  nregionslocal
686 
687 ! ******************************************************************************
688 ! Start
689 ! ******************************************************************************
690 
691  CALL registerfunction(global,'RFLU_GetProcLocRegIds',&
692  'RFLU_ModRegionMapping.F90')
693 
694 ! ******************************************************************************
695 ! Set pointers and variables
696 ! ******************************************************************************
697 
698  ifile = if_regmap
699 
700 ! ******************************************************************************
701 ! Initialize output arrays
702 ! ******************************************************************************
703 
704  DO iregid = 1,nregids
705  procids(iregid) = crazy_value_int
706  locregids(iregid) = crazy_value_int
707  END DO ! iRegIds
708 
709 ! ******************************************************************************
710 ! Loop over region ids
711 ! ******************************************************************************
712 
713  DO iregid = 1,nregids
714  rewind(ifile)
715 
716 ! ==============================================================================
717 ! Read header
718 ! ==============================================================================
719 
720  READ(ifile,'(A)') sectionstring
721  IF ( trim(sectionstring) /= '# ROCFLU region mapping file' ) THEN
722  CALL errorstop(global,err_invalid_marker,__line__,trim(sectionstring))
723  END IF ! TRIM
724 
725 ! ==============================================================================
726 ! Read number of regions and processors
727 ! ==============================================================================
728 
729  READ(ifile,'(A)') sectionstring
730  IF ( trim(sectionstring) /= '# Number of regions' ) THEN
731  CALL errorstop(global,err_invalid_marker,__line__,trim(sectionstring))
732  END IF ! TRIM
733 
734  READ(ifile,*) nregionsglobal
735 
736  IF ( nregionsglobal /= global%nRegions ) THEN
737  CALL errorstop(global,err_nregions_mismatch,__line__)
738  END IF ! nRegionsGlobal
739 
740  READ(ifile,'(A)') sectionstring
741  IF ( trim(sectionstring) /= '# Number of processes' ) THEN
742  CALL errorstop(global,err_invalid_marker,__line__,trim(sectionstring))
743  END IF ! TRIM
744 
745  READ(ifile,*) nprocs
746 
747  IF ( nprocs /= global%nProcs ) THEN
748  CALL errorstop(global,err_nprocs_mismatch,__line__)
749  END IF ! nProcs
750 
751 ! ==============================================================================
752 ! Loop over processes and look for region id
753 ! ==============================================================================
754 
755  procloop: DO iproc = 0,global%nProcs-1
756  WRITE(targetstring,'(A,1X,I6.6)') '# Process',iproc+1
757 
758  READ(ifile,'(A)') sectionstring
759 
760  IF ( trim(sectionstring) /= trim(targetstring) ) THEN
761  CALL errorstop(global,err_invalid_marker,__line__,trim(sectionstring))
762  END IF ! TRIM
763 
764  READ(ifile,*) nregionslocal
765 
766  DO ireg = 1,nregionslocal
767  READ(ifile,*) iregid2
768 
769  IF ( iregid2 == regids(iregid) ) THEN
770  procids(iregid) = iproc+1
771  locregids(iregid) = ireg
772 
773  EXIT procloop
774  END IF ! iRegId
775  END DO ! iReg
776  END DO procloop
777  END DO ! iRegId
778 
779 ! ******************************************************************************
780 ! End
781 ! ******************************************************************************
782 
783  CALL deregisterfunction(global)
784 
785 END SUBROUTINE rflu_getproclocregids
786 
787 
788 
789 
790 
791 
792 
793 
794 ! ******************************************************************************
795 !
796 ! Purpose: Impose serial region mapping.
797 !
798 ! Description: None.
799 !
800 ! Input:
801 ! global Pointer to global type
802 !
803 ! Output: None.
804 !
805 ! Notes:
806 ! 1. This routine must only be called if RFLU_ReadRegionMappingFile
807 ! was called with readMode equal to MAPFILE_READMODE_PEEK. There is no
808 ! check for this here, so it is up to the user to make sure this is so.
809 !
810 ! ******************************************************************************
811 
813 
814  IMPLICIT NONE
815 
816 ! ******************************************************************************
817 ! Definitions and declarations
818 ! ******************************************************************************
819 
820 ! ==============================================================================
821 ! Parameters
822 ! ==============================================================================
823 
824  TYPE(t_global), POINTER :: global
825 
826 ! ==============================================================================
827 ! Locals
828 ! ==============================================================================
829 
830  INTEGER :: errorflag,ireg
831 
832 ! ******************************************************************************
833 ! Start
834 ! ******************************************************************************
835 
836  CALL registerfunction(global,'RFLU_ImposeRegionMappingSerial',&
837  'RFLU_ModRegionMapping.F90')
838 
839  IF ( global%myProcid == masterproc .AND. &
840  global%verbLevel >= verbose_high ) THEN
841  WRITE(stdout,'(A,1X,A)') solver_name,'Imposing serial region mapping...'
842  END IF ! global%myProcid
843 
844 ! ******************************************************************************
845 ! Set region mapping
846 ! ******************************************************************************
847 
848  DO ireg = 0,global%nRegionsLocal
849  global%regMap(ireg) = ireg
850  END DO ! iReg
851 
852  IF ( global%nRegionsLocal == 1 ) THEN ! for single-processor jobs
853  global%regMap(1) = 0
854  END IF ! global%nRegionsLocal
855 
856 ! ******************************************************************************
857 ! End
858 ! ******************************************************************************
859 
860  IF ( global%myProcid == masterproc .AND. &
861  global%verbLevel >= verbose_high ) THEN
862  WRITE(stdout,'(A,1X,A)') solver_name,'Imposing serial region mapping done.'
863  END IF ! global%verbLevel
864 
865  CALL deregisterfunction(global)
866 
867 END SUBROUTINE rflu_imposeregionmappingserial
868 
869 
870 
871 
872 
873 
874 
875 
876 ! ******************************************************************************
877 !
878 ! Purpose: Open region mapping file.
879 !
880 ! Description: None.
881 !
882 ! Input:
883 ! global Pointer to global data
884 !
885 ! Output: None.
886 !
887 ! Notes: None.
888 !
889 ! ******************************************************************************
890 
891 SUBROUTINE rflu_openregionmappingfile(global)
892 
893 ! ******************************************************************************
894 ! Declarations and definitions
895 ! ******************************************************************************
896 
897 ! ==============================================================================
898 ! Arguments
899 ! ==============================================================================
900 
901  TYPE(t_global), POINTER :: global
902 
903 ! ==============================================================================
904 ! Locals
905 ! ==============================================================================
906 
907  CHARACTER(CHRLEN) :: ifilename
908  INTEGER :: errorflag
909 
910 ! ******************************************************************************
911 ! Start
912 ! ******************************************************************************
913 
914  CALL registerfunction(global,'RFLU_OpenRegionMappingFile',&
915  'RFLU_ModRegionMapping.F90')
916 
917  IF ( global%myProcid == masterproc .AND. &
918  global%verbLevel >= verbose_high ) THEN
919  WRITE(stdout,'(A,1X,A)') solver_name,'Opening region mapping file...'
920  END IF ! global%verbLevel
921 
922 ! ******************************************************************************
923 ! Open file
924 ! ******************************************************************************
925 
926  CALL buildfilenameplain(global,filedest_indir,'.map',ifilename)
927 
928  OPEN(if_regmap,file=ifilename,form="FORMATTED",status="UNKNOWN", &
929  iostat=errorflag)
930  global%error = errorflag
931  IF ( global%error /= err_none ) THEN
932  CALL errorstop(global,err_file_open,__line__,ifilename)
933  END IF ! global%error
934 
935 ! ******************************************************************************
936 ! End
937 ! ******************************************************************************
938 
939  IF ( global%myProcid == masterproc .AND. &
940  global%verbLevel >= verbose_high ) THEN
941  WRITE(stdout,'(A,1X,A)') solver_name,'Opening region mapping file done.'
942  END IF ! global%verbLevel
943 
944  CALL deregisterfunction(global)
945 
946 END SUBROUTINE rflu_openregionmappingfile
947 
948 
949 
950 
951 
952 
953 
954 
955 
956 ! ******************************************************************************
957 !
958 ! Purpose: Read region mapping file for parallel processing
959 !
960 ! Description: None.
961 !
962 ! Input:
963 ! global Pointer to global type
964 ! readMode Reading mode of file, can take only two values:
965 ! MAPFILE_READMODE_ALL: Read whole file
966 ! MAPFILE_READMODE_PEEK: Read only number of regions
967 ! myProcId Processor id
968 !
969 ! Output: None.
970 !
971 ! Notes:
972 ! 1. The complete file is only read if the readMode argument is set to
973 ! MAPFILE_READMODE_ALL. If the readMode argument is set to
974 ! MAPFILE_READMODE_PEEK, then only the number of regions is read, and
975 ! the rest of the file is ignored.
976 !
977 ! ******************************************************************************
978 
979 SUBROUTINE rflu_readregionmappingfile(global,readMode,myProcId)
980 
982 
983  IMPLICIT NONE
984 
985 ! ******************************************************************************
986 ! Definitions and declarations
987 ! ******************************************************************************
988 
989 ! ==============================================================================
990 ! Parameters
991 ! ==============================================================================
992 
993  INTEGER, INTENT(IN) :: myprocid,readmode
994  TYPE(t_global), POINTER :: global
995 
996 ! ==============================================================================
997 ! Locals
998 ! ==============================================================================
999 
1000  LOGICAL :: fileexists,foundentry
1001  CHARACTER(CHRLEN) :: dummystring,ifilename,sectionstring,targetstring
1002  INTEGER :: errorflag,ifile,iproc,ireg,nregions
1003 
1004 ! ******************************************************************************
1005 ! Start
1006 ! ******************************************************************************
1007 
1008  CALL registerfunction(global,'RFLU_ReadRegionMappingFile',&
1009  'RFLU_ModRegionMapping.F90')
1010 
1011  IF ( global%myProcid == masterproc ) THEN
1012  IF ( global%verbLevel >= verbose_high ) THEN
1013  WRITE(stdout,'(A,1X,A)') solver_name,'Reading region mapping file...'
1014 
1015  IF ( global%verbLevel >= verbose_med ) THEN
1016  IF ( readmode == mapfile_readmode_all ) THEN
1017  WRITE(stdout,'(A,3X,A)') solver_name,'Read mode: All'
1018  ELSE IF ( readmode == mapfile_readmode_peek ) THEN
1019  WRITE(stdout,'(A,3X,A)') solver_name,'Read mode: Peek'
1020  ELSE
1021  CALL errorstop(global,err_reached_default,__line__)
1022  END IF ! readMode
1023  END IF ! global%verbLevel
1024  END IF ! global%verbLevel
1025  END IF ! global%myProcid
1026 
1027 ! ******************************************************************************
1028 ! Test for existence of mapping file
1029 ! ******************************************************************************
1030 
1031  ifile = if_regmap
1032 
1033  CALL buildfilenameplain(global,filedest_indir,'.map',ifilename)
1034 
1035  INQUIRE(file=ifilename,exist=fileexists)
1036 
1037 ! ==============================================================================
1038 ! File exists
1039 ! ==============================================================================
1040 
1041  IF ( fileexists .EQV. .true. ) THEN
1042  IF ( global%myProcid == masterproc .AND. &
1043  global%verbLevel >= verbose_high ) THEN
1044  WRITE(stdout,'(A,3X,A)') solver_name,'Mapping file found.'
1045  END IF ! global%verbLevel
1046 
1047 ! ------------------------------------------------------------------------------
1048 ! Open file and read header
1049 ! ------------------------------------------------------------------------------
1050 
1051  CALL rflu_openregionmappingfile(global)
1052 
1053  READ(ifile,'(A)') sectionstring
1054  IF ( trim(sectionstring) /= '# ROCFLU region mapping file' ) THEN
1055  CALL errorstop(global,err_invalid_marker,__line__,trim(sectionstring))
1056  END IF ! TRIM
1057 
1058 ! ------------------------------------------------------------------------------
1059 ! Read number of regions and processors
1060 ! ------------------------------------------------------------------------------
1061 
1062  READ(ifile,'(A)') sectionstring
1063  IF ( trim(sectionstring) /= '# Number of regions' ) THEN
1064  CALL errorstop(global,err_invalid_marker,__line__,trim(sectionstring))
1065  END IF ! TRIM
1066 
1067  READ(ifile,*) global%nRegions
1068 
1069  READ(ifile,'(A)') sectionstring
1070  IF ( trim(sectionstring) /= '# Number of processes' ) THEN
1071  CALL errorstop(global,err_invalid_marker,__line__,trim(sectionstring))
1072  END IF ! TRIM
1073 
1074  READ(ifile,*) global%nProcs
1075 
1076 ! ------------------------------------------------------------------------------
1077 ! Read rest of file
1078 ! ------------------------------------------------------------------------------
1079 
1080  DO iproc = 0,global%nProcs-1
1081  foundentry = .false.
1082 
1083  WRITE(targetstring,'(A,1X,I6.6)') '# Process',iproc+1
1084  READ(ifile,'(A)') sectionstring
1085 
1086  IF ( trim(sectionstring) /= trim(targetstring) ) THEN
1087  CALL errorstop(global,err_invalid_marker,__line__,trim(sectionstring))
1088  END IF ! TRIM
1089 
1090  READ(ifile,*) nregions
1091 
1092  IF ( iproc == myprocid ) THEN ! Found entry for my processor
1093  foundentry = .true.
1094 
1095  global%nRegionsLocal = nregions
1096  END IF ! iProc
1097 
1098  IF ( (foundentry .EQV. .true.) .AND. &
1099  (readmode == mapfile_readmode_all) ) THEN
1100  global%regMap(0) = 0
1101 
1102  DO ireg = 1,global%nRegionsLocal
1103  READ(ifile,*) global%regMap(ireg)
1104  END DO ! iReg
1105  ELSE
1106  DO ireg = 1,nregions
1107  READ(ifile,'(A)') dummystring ! Read irrelevant lines
1108  END DO ! iReg
1109  END IF ! readMode
1110  END DO ! iProc
1111 
1112  READ(ifile,'(A)') sectionstring
1113  IF ( trim(sectionstring) /= '# End' ) THEN
1114  CALL errorstop(global,err_invalid_marker,__line__,trim(sectionstring))
1115  END IF ! TRIM
1116 
1117  CALL rflu_closeregionmappingfile(global)
1118 
1119 ! ==============================================================================
1120 ! File does not exist, initialize for single-processor run
1121 ! ==============================================================================
1122 
1123  ELSE IF ( (fileexists .EQV. .false.) .AND. (global%nProcAlloc == 1) ) THEN
1124  global%warnCounter = global%warnCounter + 1
1125 
1126  IF ( global%myProcid == masterproc .AND. &
1127  global%verbLevel >= verbose_none ) THEN
1128  WRITE(stdout,'(A,3X,A,1X,A)') solver_name,'*** WARNING ***', &
1129  'Mapping file not found.'
1130  WRITE(stdout,'(A,3X,A,1X,A)') solver_name,'Initializing for', &
1131  'single-process run.'
1132  END IF ! global%verbLevel
1133 
1134  global%nProcs = 1
1135  global%nRegions = 1
1136  global%nRegionsLocal = 1
1137 
1138 ! ==============================================================================
1139 ! File should exist but does not
1140 ! ==============================================================================
1141 
1142  ELSE
1143  CALL errorstop(global,err_file_exist,__line__,trim(ifilename))
1144  END IF ! fileExists
1145 
1146 ! ******************************************************************************
1147 ! End
1148 ! ******************************************************************************
1149 
1150  IF ( global%myProcid == masterproc .AND. &
1151  global%verbLevel >= verbose_high ) THEN
1152  WRITE(stdout,'(A,1X,A)') solver_name,'Reading region mapping file done.'
1153  END IF ! global%verbLevel
1154 
1155  CALL deregisterfunction(global)
1156 
1157 END SUBROUTINE rflu_readregionmappingfile
1158 
1159 
1160 
1161 
1162 
1163 
1164 
1165 
1166 
1167 ! ******************************************************************************
1168 !
1169 ! Purpose: Set serial region mapping.
1170 !
1171 ! Description: None.
1172 !
1173 ! Input:
1174 ! global Pointer to global type
1175 !
1176 ! Output: None.
1177 !
1178 ! Notes:
1179 ! 1. This routine must only be called if RFLU_ReadRegionMappingFile
1180 ! was called with readMode equal to MAPFILE_READMODE_PEEK. There is no
1181 ! check for this here, so it is up to the user to make sure this is so.
1182 !
1183 ! ******************************************************************************
1184 
1186 
1187  IMPLICIT NONE
1188 
1189 ! ******************************************************************************
1190 ! Definitions and declarations
1191 ! ******************************************************************************
1192 
1193 ! ==============================================================================
1194 ! Parameters
1195 ! ==============================================================================
1196 
1197  TYPE(t_global), POINTER :: global
1198 
1199 ! ==============================================================================
1200 ! Locals
1201 ! ==============================================================================
1202 
1203 ! ******************************************************************************
1204 ! Start
1205 ! ******************************************************************************
1206 
1207  CALL registerfunction(global,'RFLU_SetRegionMappingSerial',&
1208  'RFLU_ModRegionMapping.F90')
1209 
1210  IF ( global%myProcid == masterproc .AND. &
1211  global%verbLevel >= verbose_high ) THEN
1212  WRITE(stdout,'(A,1X,A)') solver_name,'Setting serial region mapping...'
1213  END IF ! global%myProcid
1214 
1215 ! ******************************************************************************
1216 ! Set serial region mapping
1217 ! ******************************************************************************
1218 
1219  global%nRegionsLocal = global%nRegions
1220 
1221 ! ******************************************************************************
1222 ! End
1223 ! ******************************************************************************
1224 
1225  IF ( global%myProcid == masterproc .AND. &
1226  global%verbLevel >= verbose_high ) THEN
1227  WRITE(stdout,'(A,1X,A)') solver_name,'Setting serial region mapping done.'
1228  END IF ! global%verbLevel
1229 
1230  CALL deregisterfunction(global)
1231 
1232 END SUBROUTINE rflu_setregionmappingserial
1233 
1234 
1235 
1236 
1237 
1238 
1239 
1240 
1241 
1242 ! ******************************************************************************
1243 !
1244 ! Purpose: Write region mapping file.
1245 !
1246 ! Description: None.
1247 !
1248 ! Input:
1249 ! global Pointer to global data
1250 !
1251 ! Output: None.
1252 !
1253 ! Notes: None.
1254 !
1255 ! ******************************************************************************
1256 
1258 
1259 ! ******************************************************************************
1260 ! Declarations and definitions
1261 ! ******************************************************************************
1262 
1263 ! ==============================================================================
1264 ! Arguments
1265 ! ==============================================================================
1266 
1267  TYPE(t_global), POINTER :: global
1268 
1269 ! ==============================================================================
1270 ! Locals
1271 ! ==============================================================================
1272 
1273  INTEGER :: i,ibeg,iend,iproc,nregions
1274 
1275 ! ******************************************************************************
1276 ! Start
1277 ! ******************************************************************************
1278 
1279  CALL registerfunction(global,'RFLU_WriteRegionMappingFile',&
1280  'RFLU_ModRegionMapping.F90')
1281 
1282  IF ( global%myProcid == masterproc .AND. &
1283  global%verbLevel >= verbose_high ) THEN
1284  WRITE(stdout,'(A,1X,A)') solver_name,'Writing region mapping file...'
1285  END IF ! global%verbLevel
1286 
1287 ! ******************************************************************************
1288 ! Write mapping file
1289 ! ******************************************************************************
1290 
1291  WRITE(if_regmap,'(A)') '# ROCFLU region mapping file'
1292 
1293  WRITE(if_regmap,'(A)') '# Number of regions'
1294  WRITE(if_regmap,'(I7)') global%nRegions
1295 
1296  WRITE(if_regmap,'(A)') '# Number of processes'
1297  WRITE(if_regmap,'(I7)') global%nProcs
1298 
1299  DO iproc = 1,global%nProcs
1300  WRITE(if_regmap,'(A,1X,I6.6)') '# Process',iproc
1301 
1302  ibeg = global%proc2RegMapInfo(1,iproc)
1303  iend = global%proc2RegMapInfo(2,iproc)
1304 
1305  WRITE(if_regmap,'(I7)') iend - ibeg + 1
1306 
1307  DO i = ibeg,iend
1308  WRITE(if_regmap,'(I7)') global%proc2RegMap(i)
1309  END DO ! i
1310  END DO ! iProc
1311 
1312  WRITE(if_regmap,'(A)') '# End'
1313 
1314 ! ******************************************************************************
1315 ! End
1316 ! ******************************************************************************
1317 
1318  IF ( global%myProcid == masterproc .AND. &
1319  global%verbLevel >= verbose_high ) THEN
1320  WRITE(stdout,'(A,1X,A)') solver_name,'Writing region mapping file done.'
1321  END IF ! global%verbLevel
1322 
1323  CALL deregisterfunction(global)
1324 
1325 END SUBROUTINE rflu_writeregionmappingfile
1326 
1327 
1328 
1329 
1330 
1331 
1332 
1333 ! ******************************************************************************
1334 ! End
1335 ! ******************************************************************************
1336 
1337 END MODULE rflu_modregionmapping
1338 
1339 ! ******************************************************************************
1340 !
1341 ! RCS Revision history:
1342 !
1343 ! $Log: RFLU_ModRegionMapping.F90,v $
1344 ! Revision 1.7 2008/12/06 08:44:23 mtcampbe
1345 ! Updated license.
1346 !
1347 ! Revision 1.6 2008/11/19 22:17:34 mtcampbe
1348 ! Added Illinois Open Source License/Copyright
1349 !
1350 ! Revision 1.5 2007/03/31 23:53:13 haselbac
1351 ! Changed global region index for region 0 in parallel jobs
1352 !
1353 ! Revision 1.4 2006/04/07 15:19:20 haselbac
1354 ! Removed tabs
1355 !
1356 ! Revision 1.3 2005/04/15 15:07:01 haselbac
1357 ! Modified routine to get local proc ids
1358 !
1359 ! Revision 1.2 2005/01/14 21:25:53 haselbac
1360 ! Added routine to get pid given regid, changed reading of map file
1361 !
1362 ! Revision 1.1 2004/10/19 19:26:57 haselbac
1363 ! Initial revision
1364 !
1365 ! ******************************************************************************
1366 
1367 
1368 
1369 
1370 
1371 
1372 
1373 
1374 
1375 
1376 
1377 
1378 
1379 
1380 
1381 
1382 
1383 
**********************************************************************Rocstar Simulation Suite Illinois Rocstar LLC All rights reserved ****Illinois Rocstar LLC IL **www illinoisrocstar com **sales illinoisrocstar com WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **Arising OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE **********************************************************************INTERFACE SUBROUTINE ibeg
subroutine, public rflu_openregionmappingfile(global)
subroutine, public rflu_destroyregionmapping(global, mapType)
subroutine registerfunction(global, funName, fileName)
Definition: ModError.F90:449
int status() const
Obtain the status of the attribute.
Definition: Attribute.h:240
subroutine quicksortinteger(a, n)
subroutine, public rflu_setregionmappingserial(global)
subroutine buildfilenameplain(global, dest, ext, fileName)
**********************************************************************Rocstar Simulation Suite Illinois Rocstar LLC All rights reserved ****Illinois Rocstar LLC IL **www illinoisrocstar com **sales illinoisrocstar com WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **Arising OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE **********************************************************************INTERFACE SUBROUTINE knode iend
subroutine, public rflu_closeregionmappingfile(global)
subroutine, public rflu_buildregionmappingsimple(global)
blockLoc i
Definition: read.cpp:79
**********************************************************************Rocstar Simulation Suite Illinois Rocstar LLC All rights reserved ****Illinois Rocstar LLC IL **www illinoisrocstar com **sales illinoisrocstar com WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **Arising OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE **********************************************************************INTERFACE SUBROUTINE form
subroutine, public rflu_readregionmappingfile(global, readMode, myProcId)
subroutine, public rflu_writeregionmappingfile(global)
subroutine, public rflu_getproclocregids(global, regIds, nRegIds, procIds, locRegIds)
subroutine, public rflu_checkregionmapping(global)
subroutine errorstop(global, errorCode, errorLine, addMessage)
Definition: ModError.F90:483
subroutine deregisterfunction(global)
Definition: ModError.F90:469
subroutine, public rflu_applyregionmapping(global, levels)
subroutine, public rflu_imposeregionmappingserial(global)
subroutine, public rflu_createregionmapping(global, mapType)