48 subroutine closer( skip_abort )
49 logical,
intent(in),
optional :: skip_abort
102 private :: prc_mpicoloring
103 private :: prc_sort_ascd
109 integer,
private,
parameter :: prc_abort_code = -1
113 procedure(closer),
pointer :: prc_file_closer => null()
123 integer,
intent(out) :: comm
134 comm = mpi_comm_world
148 integer,
intent(in) :: comm
149 integer,
intent(out) :: nprocs
150 logical,
intent(out) :: ismaster
186 logical,
intent(in) :: abortall
187 integer,
intent(in) :: comm
221 integer,
intent(in) :: comm
222 integer,
intent(out) :: myrank
223 logical,
intent(out) :: ismaster
254 integer,
intent(in) :: comm
255 integer,
intent(out) :: nprocs
256 integer,
intent(out) :: myrank
257 logical,
intent(out) :: ismaster
262 call mpi_comm_size(comm,nprocs,ierr)
263 call mpi_comm_rank(comm,myrank,ierr)
303 logical,
intent(in) :: use_fpm
304 logical,
intent(in) :: master
357 logical :: sign_status
363 sign_status = .false.
365 do while ( .NOT. sign_exit )
380 log_progress(*)
'finalize MPI...' 389 call mpi_finalize(ierr)
390 log_progress(*)
'MPI is peacefully finalized' 406 NUM_DOMAIN, & ! [in ]
407 PRC_DOMAINS, & ! [in ]
408 CONF_FILES, & ! [in ]
410 bulk_split, & ! [in ]
411 color_reorder, & ! [in ]
412 INTRA_COMM, & ! [out]
413 inter_parent, & ! [out]
414 inter_child, & ! [out]
418 integer,
intent(in) :: ORG_COMM
419 integer,
intent(in) :: NUM_DOMAIN
420 integer,
intent(in) :: PRC_DOMAINS(:)
421 character(len=*),
intent(in) :: CONF_FILES(:)
422 logical,
intent(in) :: LOG_SPLIT
423 logical,
intent(in) :: bulk_split
424 logical,
intent(in) :: color_reorder
425 integer,
intent(out) :: intra_comm
426 integer,
intent(out) :: inter_parent
427 integer,
intent(out) :: inter_child
428 character(len=H_LONG),
intent(out) :: fname_local
433 integer,
allocatable :: COLOR_LIST(:)
434 integer,
allocatable :: KEY_LIST(:)
436 integer :: total_nmax
437 integer :: ORG_myrank
442 logical :: reordering
445 character(len=4) :: col_num
448 integer :: itag, ierr
451 intra_comm = org_comm
452 inter_parent = mpi_comm_null
453 inter_child = mpi_comm_null
454 fname_local = conf_files(1)
456 if ( num_domain > 1 )
then 457 call mpi_comm_rank(org_comm,org_myrank,ierr)
458 call mpi_comm_size(org_comm,org_nmax, ierr)
459 allocate( color_list(0:org_nmax-1) )
460 allocate( key_list(0:org_nmax-1) )
464 total_nmax = total_nmax + prc_domains(i)
466 if ( total_nmax /= org_nmax )
then 468 log_error(
"PRC_MPIsplit",*)
"MPI PROCESS NUMBER is INCONSISTENT" 469 log_error_cont(*)
" REQUESTED NPROCS = ", total_nmax,
" LAUNCHED NPROCS = ", org_nmax
474 reordering = color_reorder
475 if ( bulk_split )
then 478 call prc_mpicoloring( org_comm, &
491 if ( bulk_split )
then 500 call mpi_comm_split(org_comm, &
501 color_list(org_myrank), &
502 key_list(org_myrank), &
504 if ( bulk_split )
then 505 write(col_num,
'(I4.4)') color_list(org_myrank)
506 fname_local = col_num
509 fname_local = col_file(color_list(org_myrank))
513 do_create_p(:) = .false.
514 do_create_c(:) = .false.
515 if ( .NOT. bulk_split )
then 518 do i = 1, num_domain-1
521 " <=> child color = ", child_col(i)
522 if ( color_list(org_myrank) == parent_col(i) )
then 523 do_create_p(i) = .true.
524 elseif ( color_list(org_myrank) == child_col(i) )
then 525 do_create_c(i) = .true.
531 inter_parent = mpi_comm_null
532 inter_child = mpi_comm_null
533 if ( .NOT. bulk_split )
then 534 do i = 1, num_domain-1
536 if ( do_create_p(i) )
then 538 org_comm, prc_root(child_col(i)), &
539 itag, inter_child, ierr )
540 elseif( do_create_c(i) )
then 542 org_comm, prc_root(parent_col(i)), &
543 itag, inter_parent, ierr )
545 call mpi_barrier(org_comm, ierr)
549 deallocate( color_list, key_list )
551 elseif ( num_domain == 1 )
then 555 write(*,*)
"ERROR [RPC_MPIsplit] REQUESTED DOMAIN NUMBER IS NOT ACCEPTABLE" 565 subroutine prc_mpicoloring( &
567 NUM_DOMAIN, & ! [in ]
568 PRC_DOMAINS, & ! [in ]
569 CONF_FILES, & ! [in ]
570 color_reorder, & ! [in ]
572 COLOR_LIST, & ! [out]
575 PARENT_COL, & ! [out]
580 integer,
intent(in) :: ORG_COMM
581 integer,
intent(in) :: NUM_DOMAIN
582 integer,
intent(in) :: PRC_DOMAINS(:)
583 character(len=*),
intent(in) :: CONF_FILES(:)
584 logical,
intent(in) :: color_reorder
585 logical,
intent(in) :: LOG_SPLIT
586 integer,
intent(out) :: COLOR_LIST(:)
588 integer,
intent(out) :: KEY_LIST(:)
589 integer,
intent(out) :: PARENT_COL(:)
590 integer,
intent(out) :: CHILD_COL(:)
609 integer :: dnum, nprc, order, key
616 ro_prc_domains(:) = -1
618 ro_conf_files(:) =
"" 619 ro_parent_col(:) = -1
622 call mpi_comm_size(org_comm,org_nmax, ierr)
624 if ( color_reorder )
then 629 prc_order(:) = prc_domains(:)
631 call prc_sort_ascd( prc_order(1:num_domain), 1, num_domain )
634 do j = num_domain, 1, -1
635 if ( prc_domains(i) == prc_order(j) .AND. touch(j) < 0 )
then 650 if ( 1 <= id_parent .AND. id_parent <= num_domain )
then 651 parent_col(i) = dom2col(id_parent)
653 if ( 1 <= id_child .AND. id_child <= num_domain )
then 654 child_col(i) = dom2col(id_child)
658 write(*,
'(1x,A,I2,1x,A,I2,2(2x,A,I2))') &
659 "DOMAIN: ", i,
"MY_COL: ", dom2col(i),
"PARENT: COL= ", parent_col(i),
"CHILD: COL= ", child_col(i)
669 ro_prc_domains(i) = prc_domains(dnum)
670 ro_dom2col(dnum) = dom2col(dnum)
671 ro_conf_files(i) = conf_files(dnum)
672 ro_parent_col(i) = parent_col(dnum)
673 ro_child_col(i) = child_col(dnum)
679 do i = 1, num_domain-1
680 parent_col(i) = ro_parent_col(dom2order(i+1))
681 child_col(i) = ro_child_col(dom2order(i) )
691 if ( ro_parent_col(i) >= 0 )
then 696 if ( ro_child_col(i) >= 0 )
then 705 col_file(i-1) = ro_conf_files(i)
712 ro_prc_domains(i) = prc_domains(i)
714 ro_conf_files(i) = conf_files(i)
721 if ( 1 <= id_parent .AND. id_parent <= num_domain )
then 722 ro_parent_col(i) = ro_dom2col(id_parent)
724 if ( 1 <= id_child .AND. id_child <= num_domain )
then 725 ro_child_col(i) = ro_dom2col(id_child)
730 do i = 1, num_domain-1
731 parent_col(i) = ro_parent_col(i+1)
732 child_col(i) = ro_child_col(i )
740 nprc = ro_prc_domains(order)
744 color_list(i+1) = ro_dom2col(order2dom(order))
748 prc_root(color_list(i+1)) = i
749 col_file(color_list(i+1)) = ro_conf_files(order)
753 write(*,
'(5x,4(A,I5))') &
754 "PE:", i,
" COLOR:", color_list(i+1),
" KEY:", key_list(i+1),
" PRC_ROOT:", prc_root(color_list(i+1))
758 if ( key >= nprc )
then 761 nprc = ro_prc_domains(order)
766 end subroutine prc_mpicoloring
770 recursive subroutine prc_sort_ascd(a, top, bottom)
772 integer,
intent(inout) :: a(:)
773 integer,
intent(in) :: top, bottom
774 integer :: i, j, cnt, trg
776 cnt = a( (top+bottom) / 2 )
779 do while ( a(i) > cnt )
782 do while ( cnt > a(j) )
786 trg = a(i); a(i) = a(j); a(j) = trg
790 if ( top < i-1 )
call prc_sort_ascd( a, top, i-1 )
791 if ( j+1 < bottom )
call prc_sort_ascd( a, j+1, bottom )
793 end subroutine prc_sort_ascd
819 time =
real(MPI_WTIME(), kind=
dp)
837 real(DP),
intent(out) :: avgvar(:)
838 real(DP),
intent(out) :: maxvar(:)
839 real(DP),
intent(out) :: minvar(:)
840 integer,
intent(out) :: maxidx(:)
841 integer,
intent(out) :: minidx(:)
842 real(DP),
intent(in) :: var(:)
844 real(DP),
allocatable :: statval(:,:)
855 statval(:,:) = 0.0_dp
863 call mpi_bcast( statval(1,p), &
865 mpi_double_precision, &
874 totalvar = totalvar + statval(v,p)
878 maxvar(v) = maxval(statval(v,:))
879 minvar(v) = minval(statval(v,:))
880 maxidx(v:v) = maxloc(statval(v,:))
881 minidx(v:v) = minloc(statval(v,:))
884 deallocate( statval )
891 subroutine prc_mpi_errorhandler( &
900 character(len=MPI_MAX_ERROR_STRING) :: msg
903 logical :: sign_status
911 sign_status = .false.
913 do while ( .NOT. sign_exit )
922 log_progress(*)
'abort MPI' 935 if ( errcode == prc_abort_code )
then 937 elseif( errcode <= mpi_err_lastcode )
then 938 call mpi_error_string(errcode, msg, len, ierr)
940 write(*,*)
'+++++ ', errcode, trim(msg)
942 if(
io_l )
write(
io_fid_log,*)
'+++++ Unexpected error code', errcode
943 write(*,*)
'+++++ Unexpected error code', errcode
948 write(*,*)
'+++++ Unexpected communicator' 954 if (
associated( prc_file_closer ) )
call prc_file_closer( .true. )
969 end subroutine prc_mpi_errorhandler
972 procedure(closer) :: routine
974 prc_file_closer => routine
integer, parameter, public prc_domain_nlim
max depth of domains
integer, public prc_universal_nprocs
process num in universal communicator
integer, public prc_global_domainid
my domain ID in global communicator
subroutine, public prc_mpistart(comm)
Start MPI.
subroutine, public prc_mpisplit(ORG_COMM, NUM_DOMAIN, PRC_DOMAINS, CONF_FILES, LOG_SPLIT, bulk_split, color_reorder, INTRA_COMM, inter_parent, inter_child, fname_local)
MPI Communicator Split.
subroutine, public prc_set_file_closer(routine)
subroutine, public prc_global_setup(abortall, comm)
setup MPI in global communicator
integer, public prc_abort_handler
error handler communicator for aborting
logical, public prc_global_ismaster
master process in global communicator?
integer, parameter, public prc_comm_null
subroutine, public sigvars_get_all(master)
Get signal values.
integer, public prc_global_myrank
myrank in global communicator
integer(c_int), public sigterm
integer(c_int), public sigquit
integer, public io_fid_conf
Config file ID.
logical, public prc_mpi_alive
MPI is alive?
logical, public fpm_alive
integer, public prc_universal_comm_world
original communicator
integer, public prc_nprocs
myrank in local communicator
integer(c_int), public sigint
integer, public prc_universal_myrank
myrank in universal communicator
integer(c_int), public sigabrt
integer, public prc_universal_handler
error handler in universal communicator
logical, public io_l
output log or not? (this process)
subroutine, public prc_universal_setup(comm, nprocs, ismaster)
setup MPI in universal communicator
integer, parameter, public io_fid_stdout
integer, public prc_universal_jobid
my job ID in universal communicator
real(dp) function, public prc_mpitime()
Get MPI time.
integer, parameter, public prc_masterrank
master process in each communicator
integer, public prc_global_nprocs
process num in global communicator
integer, public prc_myrank
process num in local communicator
subroutine, public fpm_polling(run_stat, stop_signal)
Main system of FPM.
subroutine, public prc_singlecom_setup(comm, nprocs, myrank, ismaster)
Setup MPI single communicator (not use universal-global-local setting)
subroutine, public prc_abort
Abort Process.
subroutine, public prc_local_setup(comm, myrank, ismaster)
Setup MPI in local communicator.
subroutine, public prc_mpibarrier
Barrier MPI.
logical, public prc_ismaster
master process in local communicator?
integer, public prc_global_comm_world
global communicator
subroutine, public prc_errhandler_setup(use_fpm, master)
Setup MPI error handler.
subroutine, public prc_mpifinish
Stop MPI peacefully.
logical, public prc_universal_ismaster
master process in universal communicator?
integer, public prc_local_comm_world
local communicator
integer, public prc_abort_comm_world
communicator for aborting
integer(c_int), public sigsegv
integer, public io_fid_log
Log file ID.
integer, dimension(prc_domain_nlim+1), public prc_global_root
root processes in global members
subroutine, public prc_mpitimestat(avgvar, maxvar, minvar, maxidx, minidx, var)
Calc global statistics for timer.
integer, parameter, public dp
integer(c_int), public sigfpe