1 |
C $Header: /u/gcmpack/MITgcm/pkg/compon_communic/coupsend_r4.F,v 1.2 2007/10/08 23:58:20 jmc Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
!======================================================================= |
5 |
subroutine coupsend_r4( component, dataname, Nx, Ny, arr ) |
6 |
implicit none |
7 |
! Predefined constants/arrays |
8 |
#include "CPLR_SIG.h" |
9 |
! MPI variables |
10 |
#include "mpif.h" |
11 |
! Arguments |
12 |
character*(*) component |
13 |
character*(*) dataname |
14 |
integer Nx,Ny |
15 |
real*4 arr(Nx,Ny) |
16 |
! Functions |
17 |
integer mitcplr_match_comp |
18 |
integer generate_tag |
19 |
external mitcplr_match_comp |
20 |
external generate_tag |
21 |
! Local |
22 |
integer count,dtype,dest,tag,comm,ierr |
23 |
integer compind,numprocs |
24 |
integer i,j,ij,n |
25 |
integer Ni,Io,Nj,Jo |
26 |
! ------------------------------------------------------------------ |
27 |
|
28 |
! Establish who I am communicating with |
29 |
compind=mitcplr_match_comp( component ) |
30 |
if (compind.le.0) stop 'coupsend_r4: Bad component id' |
31 |
comm=MPI_COMM_compcplr( compind ) |
32 |
numprocs=num_component_procs(compind) |
33 |
if (numprocs.lt.1) then |
34 |
write(LogUnit,*) 'coupsend_r4: compind = ',compind |
35 |
stop 'coupsend_r4: numprocs < 1' |
36 |
endif |
37 |
if (VERB) |
38 |
& write(LogUnit,*) 'coupsend_r4: ',component_Name(compind) |
39 |
if (VERB) |
40 |
& write(LogUnit,*) 'coupsend_r4: dataname=',dataname |
41 |
|
42 |
! Foreach component process |
43 |
do n=1,numprocs |
44 |
|
45 |
! Create header |
46 |
Io=component_tile_i0(1,n,compind) |
47 |
Jo=component_tile_j0(1,n,compind) |
48 |
Ni=component_tile_nx(1,n,compind) |
49 |
Nj=component_tile_ny(1,n,compind) |
50 |
r4buf(1)=float( Io ) |
51 |
r4buf(2)=float( Jo ) |
52 |
r4buf(3)=float( Ni ) |
53 |
r4buf(4)=float( Nj ) |
54 |
call mitcplr_char2real( dataname, r4buf(9) ) |
55 |
|
56 |
! Pack data |
57 |
do j=1,Nj |
58 |
do i=1,Ni |
59 |
ij=HEADER_SIZE+i+Ni*(j-1) |
60 |
r4buf(ij)=arr(Io+i-1,Jo+j-1) |
61 |
enddo |
62 |
enddo |
63 |
|
64 |
! Send message |
65 |
count=HEADER_SIZE+Ni*Nj |
66 |
dtype=MPI_REAL |
67 |
tag=generate_tag(121,n,dataname) |
68 |
dest=rank_component_procs(n,compind) |
69 |
|
70 |
if (VERB) then |
71 |
write(LogUnit,*) 'coupsend_r4: calling MPI_Send dest=',dest, |
72 |
& ' proc=',n,'/',numprocs |
73 |
call flush(LogUnit) |
74 |
endif |
75 |
call MPI_Send( r4buf, count, dtype, dest, tag, comm, ierr ) |
76 |
if (VERB) then |
77 |
write(LogUnit,*) 'coupsend_r4: returned ierr=',ierr |
78 |
call flush(LogUnit) |
79 |
endif |
80 |
|
81 |
if (ierr.ne.0) then |
82 |
write(LogUnit,*) 'coupsend_r4tiles: rank(W,G)=', |
83 |
& my_rank_in_world,my_rank_in_global, |
84 |
& ' ierr=',ierr |
85 |
stop 'coupsend_r4: MPI_Send failed' |
86 |
endif |
87 |
|
88 |
enddo ! n |
89 |
|
90 |
! ------------------------------------------------------------------ |
91 |
return |
92 |
end |
93 |
!======================================================================= |