646
647
648
658 use mpi
659 implicit none
660 type(GT_HISTORY), intent(inout):: hst
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()
665 type(GT_VARIABLE):: dimvar
666 integer:: i, j, ra, numdims, time_dimord
667 integer, pointer:: dimord(:) =>null()
668 integer:: each_index
669 integer, pointer:: idx(:) =>null()
670 integer:: moveup
671 integer:: check_dimsizes_all, check_dimsizes_each
672 character(STRING):: check_varname
673 integer:: err_mpi
674 integer:: stat
675 character(STRING):: cause_c
676 character(*), parameter:: subname = 'gtmpi_vars_mkindex'
677 character(*), parameter:: subnameup = 'HistoryPut'
678 continue
680 cause_c = ""
682
683
684
685
686
687
688
689
690
691
692
693
694
696 & hst % mpi_varinfo( v_ord ), &
697 & dims = dims )
698
699
700
701 numdims = size( dims )
702 time_dimord = -1
703 allocate( dimord(1) )
704 if ( hst % unlimited_index > 0 ) then
705 do i = 1, numdims
706 if ( hst % mpi_myrank == 0 ) then
707 dimvar = lookup_dimension( hst, dims(i), dimord(1) )
708 end if
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
711 end do
712 end if
713 if ( time_dimord > 0 ) then
714 allocate( dims_space(numdims - 1) )
715 j = 1
716 do i = 1, numdims
717 if ( i == time_dimord ) cycle
718 dims_space(j) = dims(i)
719 j = j + 1
720 end do
721 numdims = numdims - 1
722 deallocate( dims )
723 else
724 dims_space => dims
725 nullify( dims )
726 end if
727 deallocate( dimord )
728
729
730
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
738 goto 999
739 end if
740
741
742
743 allocate( dimord( numdims ) )
744 allocate( dimsizes_all( numdims ) )
745 allocate( dimsizes_each( 0:hst % mpi_nprocs - 1, numdims ) )
746
747
748
749 do i = 1, numdims
750 if ( hst % mpi_myrank == 0 ) then
751 dimvar = lookup_dimension( hst, dims_space(i), dimord(i) )
752 end if
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 )
757 end do
758 end do
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,:) )
767 end do
768 hst % mpi_vars_index(v_ord) % allcount_all = product( dimsizes_all(:) )
769
770
771
772 if ( hst % mpi_myrank /= 0 ) goto 999
773 allocate( idx(numdims) )
774 do ra = 0, hst % mpi_nprocs - 1
775 idx(:) = 1
776 idx(1) = 0
777 do i = 1, product( dimsizes_each(ra, :) )
778 idx(1) = idx(1) + 1
779 moveup = 0
780 do j = 1, numdims
781 if ( moveup > 0 ) then
782 idx(j) = idx(j) + moveup
783 moveup = 0
784 end if
785 if ( idx(j) > dimsizes_each(ra,j) ) then
786 idx(j) = 1
787 moveup = 1
788 end if
789 end do
790 each_index = hst % mpi_gthr_info(dimord(1)) % index_all (ra,idx(1))
791 do j = 2, numdims
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) )
795 end do
796 hst % mpi_vars_index(v_ord) % each2all(ra, i) = each_index
797 end do
798 end do
799 deallocate( idx )
800
801
802
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 /) )
813 end if
814999 continue
subroutine, public storeerror(number, where, err, cause_c, cause_i)
integer, parameter, public dc_noerr
Error storage variables
subroutine, public dbgmessage(fmt, i, r, d, l, n, c1, c2, c3, ca)
subroutine, public beginsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca, version)
subroutine, public endsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca)
Provides kind type parameter values.
integer, parameter, public token
Character length for word, token
integer, parameter, public string
Character length for string
Variable URL string parser.