source: CPL/oasis3/trunk/src/lib/mpp_io/include/mpp_reduce.h @ 1677

Last change on this file since 1677 was 1677, checked in by aclsce, 12 years ago

Imported oasis3 (tag ipslcm5a) from cvs server to svn server (igcmg project).

File size: 1.7 KB
Line 
1    subroutine MPP_REDUCE_( a, pelist )
2!find the max of scalar a the PEs in pelist (all PEs if this argument is omitted)
3!result is also automatically broadcast to all PEs
4      MPP_TYPE_, intent(inout) :: a
5      integer, intent(in), optional :: pelist(0:)
6      integer :: n
7#ifdef use_libSMA
8!work holds pWrk array + 1 word for symmetric copy of a
9      MPP_TYPE_ :: work(SHMEM_REDUCE_MIN_WRKDATA_SIZE+1)
10      pointer( ptr, work )
11      integer :: words
12      character(len=8) :: text
13#endif /* use_libSMA */
14#ifdef use_libMPI
15      MPP_TYPE_ :: work
16#endif
17      if( .NOT.module_is_initialized )call mpp_error( FATAL, 'MPP_REDUCE: You must first call mpp_init.' )
18      n = get_peset(pelist); if( peset(n)%count.EQ.1 )return
19
20      if( current_clock.NE.0 )call SYSTEM_CLOCK(start_tick)
21#ifdef use_libSMA
22!allocate space from the stack for pwrk and b
23      ptr = LOC(mpp_stack)
24      words = size(work)*size(transfer(work(1),word))
25      if( words.GT.mpp_stack_size )then
26          write( text, '(i8)' )words
27          call mpp_error( FATAL, 'MPP_REDUCE user stack overflow: call mpp_set_stack_size('//text//') from all PEs.' )
28      end if
29      mpp_stack_hwm = max( words, mpp_stack_hwm )
30     
31      work(1) = a
32      call SHMEM_REDUCE_( work, work, 1, peset(n)%start, peset(n)%log2stride, peset(n)%count, work(2), sync )
33      call mpp_sync(pelist)
34      a = work(1)
35#endif /* use_libSMA */
36#ifdef use_libMPI
37      if( verbose )call mpp_error( NOTE, 'MPP_REDUCE_: using MPI_ALLREDUCE...' )
38      call MPI_ALLREDUCE( a, work, 1, MPI_TYPE_, MPI_REDUCE_, peset(n)%id, error )
39      a = work
40#endif
41      if( current_clock.NE.0 )call increment_current_clock( EVENT_ALLREDUCE, MPP_TYPE_BYTELEN_ )
42      return
43    end subroutine MPP_REDUCE_
Note: See TracBrowser for help on using the repository browser.