1 |
C $Header: /u/gcmpack/MITgcm/eesupp/src/gather_vector.F,v 1.4 2006/10/19 06:54:23 dimitri Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "CPP_OPTIONS.h" |
5 |
|
6 |
SUBROUTINE GATHER_VECTOR( lprint, length, global, local, myThid ) |
7 |
C Gather elements of a vector from all mpi processes to process 0. |
8 |
IMPLICIT NONE |
9 |
#include "SIZE.h" |
10 |
#include "EEPARAMS.h" |
11 |
#include "EESUPPORT.h" |
12 |
C mythid - thread number for this instance of the routine. |
13 |
C global,local - working arrays used to transfer 2-D fields |
14 |
logical lprint |
15 |
INTEGER mythid |
16 |
INTEGER length |
17 |
Real*8 global(length*nPx*nPy) |
18 |
_RL local(length) |
19 |
|
20 |
INTEGER iG,jG,lG, l |
21 |
#ifdef ALLOW_USE_MPI |
22 |
_RL temp(length) |
23 |
INTEGER istatus(MPI_STATUS_SIZE), ierr |
24 |
INTEGER lbuff, idest, itag, npe, ready_to_receive |
25 |
#endif /* ALLOW_USE_MPI */ |
26 |
|
27 |
C-- Make everyone wait except for master thread. |
28 |
_BARRIER |
29 |
_BEGIN_MASTER( myThid ) |
30 |
|
31 |
#ifndef ALLOW_USE_MPI |
32 |
|
33 |
DO l=1,length |
34 |
iG=1+(myXGlobalLo-1)/sNx ! Kludge until unstructered tiles |
35 |
jG=1+(myYGlobalLo-1)/sNy ! Kludge until unstructered tiles |
36 |
lG= (jG-1)*nPx*length + (iG-1)*length + l |
37 |
global(lG) = local(l) |
38 |
ENDDO |
39 |
|
40 |
#else /* ALLOW_USE_MPI */ |
41 |
|
42 |
lbuff = length |
43 |
idest = 0 |
44 |
itag = 0 |
45 |
ready_to_receive = 0 |
46 |
|
47 |
IF( mpiMyId .EQ. 0 ) THEN |
48 |
|
49 |
C-- Process 0 fills-in its local data |
50 |
npe = 0 |
51 |
iG=mpi_myXGlobalLo(npe+1)/sNx+1 |
52 |
jG=mpi_myYGlobalLo(npe+1)/sNy+1 |
53 |
DO l=1,length |
54 |
lG= (jG-1)*nPx*length + (iG-1)*length + l |
55 |
global(lG) = local(l) |
56 |
ENDDO |
57 |
|
58 |
C-- Process 0 polls and receives data from each process in turn |
59 |
DO npe = 1, numberOfProcs-1 |
60 |
#ifndef DISABLE_MPI_READY_TO_RECEIVE |
61 |
CALL MPI_SEND (ready_to_receive, 1, MPI_INTEGER, |
62 |
& npe, itag, MPI_COMM_MODEL, ierr) |
63 |
#endif |
64 |
CALL MPI_RECV (temp, lbuff, MPI_DOUBLE_PRECISION, |
65 |
& npe, itag, MPI_COMM_MODEL, istatus, ierr) |
66 |
|
67 |
C-- Process 0 gathers the local arrays into a global array. |
68 |
iG=mpi_myXGlobalLo(npe+1)/sNx+1 |
69 |
jG=mpi_myYGlobalLo(npe+1)/sNy+1 |
70 |
cph( |
71 |
cph if (lprint) then |
72 |
cph print *, 'ph-gather A ', npe, |
73 |
cph & mpi_myXGlobalLo(npe+1), mpi_myYGlobalLo(npe+1) |
74 |
cph print *, 'ph-gather B ', npe, iG, jG |
75 |
cph endif |
76 |
cph) |
77 |
DO l=1,length |
78 |
lG= (jG-1)*nPx*length + (iG-1)*length + l |
79 |
global(lG) = temp(l) |
80 |
ENDDO |
81 |
|
82 |
|
83 |
ENDDO |
84 |
|
85 |
ELSE |
86 |
|
87 |
C-- All proceses except 0 wait to be polled then send local array |
88 |
#ifndef DISABLE_MPI_READY_TO_RECEIVE |
89 |
CALL MPI_RECV (ready_to_receive, 1, MPI_INTEGER, |
90 |
& idest, itag, MPI_COMM_MODEL, istatus, ierr) |
91 |
#endif |
92 |
CALL MPI_SEND (local, lbuff, MPI_DOUBLE_PRECISION, |
93 |
& idest, itag, MPI_COMM_MODEL, ierr) |
94 |
|
95 |
ENDIF |
96 |
|
97 |
#endif /* ALLOW_USE_MPI */ |
98 |
|
99 |
_END_MASTER( myThid ) |
100 |
_BARRIER |
101 |
|
102 |
RETURN |
103 |
END |