114 character(*),
intent(in):: varname
116 type(
gt_history),
intent(inout),
target,
optional:: history
119 character(*),
parameter:: subname =
"append_attrs"
121 call beginsub(subname,
'varname=<%c>, size(attrs(:))=<%d>', &
122 & c1=trim(varname), i=(/
size(attrs(:))/))
123 if (
present(history))
then
129 do i = 1,
size( attrs(:) )
131 if (
strhead(
'char', trim(
lchar(attrs(i)%attrtype))) )
then
133 & varname, attrs(i)%attrname, &
134 & trim(attrs(i)%Charvalue), hst )
135 elseif (
strhead(
'int', trim(
lchar(attrs(i)%attrtype))) )
then
136 if ( attrs(i)%array )
then
139 & varname, attrs(i)%attrname , &
140 & attrs(i)%Intarray, hst )
144 & varname, attrs(i)%attrname , &
145 & attrs(i)%Intvalue, hst )
147 elseif (
strhead(
'real', trim(
lchar(attrs(i)%attrtype))) )
then
148 if ( attrs(i)%array )
then
151 & varname, attrs(i)%attrname, attrs(i)%Realarray, hst)
155 & varname, attrs(i)%attrname, attrs(i)%Realvalue, hst)
157 elseif (
strhead(
'double', trim(
lchar(attrs(i)%attrtype))) )
then
158 if ( attrs(i)%array )
then
159 call dbgmessage(
'Doublearray(:) is selected.')
161 & varname, attrs(i)%attrname, attrs(i)%Doublearray, hst)
165 & varname, attrs(i)%attrname, attrs(i)%Doublevalue, hst)
167 elseif (
strhead(
'logical', trim(
lchar(attrs(i)%attrtype))) )
then
169 & varname, attrs(i)%attrname, attrs(i)%Logicalvalue, hst)
171 call dbgmessage(
'attrtype=<%c>=<%c>is Invalid.' , &
172 & c1=trim(attrs(i)%attrtype) , &
173 & c2=trim(
lchar(attrs(i)%attrtype)) )
467 logical,
intent(out),
optional:: err
468 integer:: i, j, k, ra, numdims
469 integer:: err_mpi, st_mpi(MPI_STATUS_SIZE)
470 integer,
allocatable:: index_all_buf(:)
471 character(STRING):: url, dimname
473 real(DP):: zero_limit
475 real(DP),
pointer:: large =>null(), small =>null()
477 character(STRING):: cause_c
478 character(*),
parameter:: subname =
'gtmpi_axis_register'
479 character(*),
parameter:: subnameup =
'HistoryPut'
484 numdims =
size( hst % dimvars )
486 zero_limit = 1.0e-6_dp
487 allocate( hst % mpi_gthr_info(numdims) )
492 if ( hst % unlimited_index == i ) cycle
493 if ( hst % time_nv_index == i ) cycle
494 if ( hst % mpi_myrank == 0 )
then
495 call inquire( hst % dimvars(i), &
499 call mpi_bcast( dimname,
string, mpi_character, 0, mpi_comm_world, err_mpi )
501 call mpi_bcast( dimname,
string, mpi_character, 0, mpi_comm_world, err_mpi )
503 if ( hst % mpi_myrank == 0 )
then
504 if ( hst % mpi_dimdata_all(i) % length < 0 )
then
506 &
'data of axis (%c) in whole area is lack. ' // &
507 &
'Specify the data by "HistoryPutAxisMPI" explicitly.', &
508 & c1 = trim(dimname) )
514 if ( hst % mpi_dimdata_each(i) % length < 0 )
then
516 &
'data of axis (%c) on node (%d) is lack. ' // &
517 &
'Specify the data by "HistoryPut" explicitly.', &
518 & c1 = trim(dimname), i = (/ hst % mpi_myrank /) )
528 if ( hst % unlimited_index == i ) cycle
529 if ( hst % time_nv_index == i ) cycle
531 & hst % mpi_gthr_info(i) % length( 0: hst % mpi_nprocs - 1 ) )
533 & hst % mpi_gthr_info(i) % &
534 & index_all( 0: hst % mpi_nprocs - 1, &
535 & hst % mpi_dimdata_all(i) % length ) )
536 hst % mpi_gthr_info(i) % index_all(:,:) = -1
537 hst % mpi_gthr_info(i) % length( hst % mpi_myrank ) = &
538 & hst % mpi_dimdata_each(i) % length
540 do j = 1, hst % mpi_dimdata_all(i) % length
542 if ( abs( hst % mpi_dimdata_all(i) % a_Axis(j) ) > &
543 & abs( hst % mpi_dimdata_each(i) % a_Axis(k) ) )
then
544 large => hst % mpi_dimdata_all(i) % a_Axis(j)
545 small => hst % mpi_dimdata_each(i) % a_Axis(k)
547 large => hst % mpi_dimdata_each(i) % a_Axis(k)
548 small => hst % mpi_dimdata_all(i) % a_Axis(j)
550 if ( large > 0.0_dp .and. small < 0.0_dp &
551 & .or. large < 0.0_dp .and. small > 0.0_dp )
then
554 if ( abs( large ) < zero_limit .and. abs( small ) < zero_limit )
then
557 if ( .not. flag_hit .and. &
558 & abs( ( large / small ) - 1.0_dp ) < accuracy )
then
562 hst % mpi_gthr_info(i) % index_all ( hst % mpi_myrank, k ) = j
565 if ( k > hst % mpi_gthr_info(i) % length( hst % mpi_myrank ) )
exit
571 if ( hst % mpi_myrank == 0 )
then
573 if ( hst % unlimited_index == i ) cycle
574 if ( hst % time_nv_index == i ) cycle
575 allocate( index_all_buf( hst % mpi_dimdata_all(i) % length ) )
576 do ra = 1, hst % mpi_nprocs - 1
579 & hst % mpi_dimdata_all(i) % length, &
580 & mpi_integer, ra, 0, mpi_comm_world, st_mpi, err_mpi )
581 hst % mpi_gthr_info(i) % index_all (ra,:) = index_all_buf(:)
583 deallocate( index_all_buf )
584 do ra = 1, hst % mpi_nprocs - 1
586 & hst % mpi_gthr_info(i) % length (ra), &
588 & mpi_integer, ra, 0, mpi_comm_world, st_mpi, err_mpi )
593 if ( hst % unlimited_index == i ) cycle
594 if ( hst % time_nv_index == i ) cycle
595 allocate( index_all_buf( hst % mpi_dimdata_all(i) % length ) )
596 index_all_buf(:) = hst % mpi_gthr_info(i) % index_all (hst % mpi_myrank,:)
599 & hst % mpi_dimdata_all(i) % length, &
600 & mpi_integer, 0, 0, mpi_comm_world, err_mpi )
601 deallocate( index_all_buf )
603 & hst % mpi_gthr_info(i) % length (hst % mpi_myrank), &
605 & mpi_integer, 0, 0, mpi_comm_world, err_mpi )
611 if ( hst % mpi_myrank == 0 )
then
612 do ra = 0, hst % mpi_nprocs - 1
614 if ( hst % unlimited_index == i ) cycle
615 if ( hst % time_nv_index == i ) cycle
618 do ra = 0, hst % mpi_nprocs - 1
620 if ( hst % unlimited_index == i ) cycle
621 if ( hst % time_nv_index == i ) cycle
622 do j = 1, hst % mpi_gthr_info(i) % length (ra)
623 if ( hst % mpi_gthr_info(i) % index_all (ra,j) < 1 )
then
624 call inquire( hst % dimvars(i), &
629 &
'data of axis (%c) on node (%d) or ' // &
630 &
'in whole area are lack. ' // &
631 &
'Specify the data by "HistoryPut" or "HistoryPutAxisMPI" explicitly.', &
632 & c1 = trim(dimname), i = (/ ra /) )
661 integer,
intent(in):: v_ord
662 logical,
intent(out),
optional:: err
663 character(TOKEN),
pointer:: dims(:) =>null(), dims_space(:) =>null()
664 integer,
pointer:: dimsizes_each(:,:) =>null(), dimsizes_all(:) =>null()
666 integer:: i, j, ra, numdims, time_dimord
667 integer,
pointer:: dimord(:) =>null()
669 integer,
pointer:: idx(:) =>null()
671 integer:: check_dimsizes_all, check_dimsizes_each
672 character(STRING):: check_varname
675 character(STRING):: cause_c
676 character(*),
parameter:: subname =
'gtmpi_vars_mkindex'
677 character(*),
parameter:: subnameup =
'HistoryPut'
696 & hst % mpi_varinfo( v_ord ), &
701 numdims =
size( dims )
703 allocate( dimord(1) )
704 if ( hst % unlimited_index > 0 )
then
706 if ( hst % mpi_myrank == 0 )
then
709 call mpi_bcast( dimord(1), 1, mpi_integer, 0, mpi_comm_world, err_mpi )
710 if ( hst % unlimited_index == dimord(1) ) time_dimord = i
713 if ( time_dimord > 0 )
then
714 allocate( dims_space(numdims - 1) )
717 if ( i == time_dimord ) cycle
718 dims_space(j) = dims(i)
721 numdims = numdims - 1
731 if ( numdims < 1 )
then
732 allocate( hst % mpi_vars_index(v_ord) % &
733 & each2all( 0: hst % mpi_nprocs - 1, 1 ) )
734 allocate( hst % mpi_vars_index(v_ord) % &
735 & allcount( 0: hst % mpi_nprocs - 1 ) )
736 hst % mpi_vars_index(v_ord) % each2all(:,:) = 1
737 hst % mpi_vars_index(v_ord) % allcount(:) = 1
743 allocate( dimord( numdims ) )
744 allocate( dimsizes_all( numdims ) )
745 allocate( dimsizes_each( 0:hst % mpi_nprocs - 1, numdims ) )
750 if ( hst % mpi_myrank == 0 )
then
753 call mpi_bcast( dimord(i), 1, mpi_integer, 0, mpi_comm_world, err_mpi )
754 dimsizes_all(i) = hst % mpi_dimdata_all ( dimord(i) ) % length
755 do ra = 0, hst % mpi_nprocs - 1
756 dimsizes_each(ra, i) = hst % mpi_gthr_info( dimord(i) ) % length( ra )
759 allocate( hst % mpi_vars_index(v_ord) % &
760 & each2all( 0: hst % mpi_nprocs - 1, product(dimsizes_all) ) )
761 allocate( hst % mpi_vars_index(v_ord) % &
762 & allcount( 0: hst % mpi_nprocs - 1 ) )
763 hst % mpi_vars_index(v_ord) % each2all(:,:) = -1
764 do ra = 0, hst % mpi_nprocs - 1
765 hst % mpi_vars_index(v_ord) % allcount(ra) = &
766 & product( dimsizes_each(ra,:) )
768 hst % mpi_vars_index(v_ord) % allcount_all = product( dimsizes_all(:) )
772 if ( hst % mpi_myrank /= 0 )
goto 999
773 allocate( idx(numdims) )
774 do ra = 0, hst % mpi_nprocs - 1
777 do i = 1, product( dimsizes_each(ra, :) )
781 if ( moveup > 0 )
then
782 idx(j) = idx(j) + moveup
785 if ( idx(j) > dimsizes_each(ra,j) )
then
790 each_index = hst % mpi_gthr_info(dimord(1)) % index_all (ra,idx(1))
792 each_index = each_index + &
793 & ( hst % mpi_gthr_info(dimord(j)) % index_all (ra,idx(j)) - 1 ) &
794 & * product( dimsizes_all(1:j-1) )
796 hst % mpi_vars_index(v_ord) % each2all(ra, i) = each_index
803 check_dimsizes_all = product( dimsizes_all(:) )
804 check_dimsizes_each = sum( hst % mpi_vars_index(v_ord) % allcount(:) )
805 if ( check_dimsizes_all > check_dimsizes_each )
then
806 call inquire( hst % vars(v_ord), &
807 & name = check_varname )
809 &
'collected data (%c) from each node is lack. ' // &
810 &
'collected data size=<%d>, but needed whole data size=<%d>.', &
811 & c1 = trim(check_varname), &
812 & i = (/ check_dimsizes_each, check_dimsizes_all /) )