5 #if defined( DM_PARALLEL ) && ! defined( STUBMPI )
11 # define COLLECT_ON_COMM collect_on_comm
12 # define COLLECT_ON_COMM0 collect_on_comm0
13 # define DIST_ON_COMM dist_on_comm
14 # define DIST_ON_COMM0 dist_on_comm0
15 # define INT_PACK_DATA int_pack_data
16 # define INT_GET_TI_HEADER_C int_get_ti_header_c
17 # define INT_GEN_TI_HEADER_C int_gen_ti_header_c
20 # define COLLECT_ON_COMM collect_on_comm__
21 # define COLLECT_ON_COMM0 collect_on_comm0__
22 # define DIST_ON_COMM dist_on_comm__
23 # define DIST_ON_COMM0 dist_on_comm0__
24 # define INT_PACK_DATA int_pack_data__
25 # define INT_GET_TI_HEADER_C int_get_ti_header_c__
26 # define INT_GEN_TI_HEADER_C int_gen_ti_header_c__
28 # define COLLECT_ON_COMM collect_on_comm_
29 # define COLLECT_ON_COMM0 collect_on_comm0_
30 # define DIST_ON_COMM dist_on_comm_
31 # define DIST_ON_COMM0 dist_on_comm0_
32 # define INT_PACK_DATA int_pack_data_
33 # define INT_GET_TI_HEADER_C int_get_ti_header_c_
34 # define INT_GEN_TI_HEADER_C int_gen_ti_header_c_
40 int col_on_comm ( int *, int *, void *, int *, void *, int *, int);
41 int dst_on_comm ( int *, int *, void *, int *, void *, int *, int);
44 COLLECT_ON_COMM ( int * comm
, int * typesize
,
45 void * inbuf
, int *ninbuf
, void * outbuf
, int * noutbuf
)
47 col_on_comm ( comm
, typesize
,
48 inbuf
, ninbuf
, outbuf
, noutbuf
, 1 ) ;
51 /* collect on node 0*/
53 COLLECT_ON_COMM0 ( int * comm
, int * typesize
,
54 void * inbuf
, int *ninbuf
, void * outbuf
, int * noutbuf
)
56 col_on_comm ( comm
, typesize
,
57 inbuf
, ninbuf
, outbuf
, noutbuf
, 0 ) ;
61 col_on_comm ( int * Fcomm
, int * typesize
,
62 void * inbuf
, int *ninbuf
, void * outbuf
, int * noutbuf
, int sw
)
64 #if defined( DM_PARALLEL ) && ! defined(STUBMPI)
65 int mytask
, ntasks
, p
;
70 MPI_Comm
*comm
, dummy_comm
;
74 *comm
= MPI_Comm_f2c( *Fcomm
) ;
75 MPI_Comm_size ( *comm
, &ntasks
) ;
76 MPI_Comm_rank ( *comm
, &mytask
) ;
77 recvcounts
= (int *) malloc( ntasks
* sizeof(int)) ;
78 displace
= (int *) malloc( ntasks
* sizeof(int)) ;
79 root_task
= ( sw
== 0 ) ? 0 : ntasks
-1 ;
81 /* collect up recvcounts */
82 ierr
= MPI_Gather( ninbuf
, 1 , MPI_INT
, recvcounts
, 1 , MPI_INT
, root_task
, *comm
) ;
84 if ( ierr
!= 0 ) fprintf(stderr
,"%s %d MPI_Gather returns %d\n",__FILE__
,__LINE__
,ierr
) ;
87 if ( mytask
== root_task
) {
89 /* figure out displacements */
90 for ( p
= 1 , displace
[0] = 0 , noutbuf_loc
= recvcounts
[0] ; p
< ntasks
; p
++ ) {
91 displace
[p
] = displace
[p
-1]+recvcounts
[p
-1] ;
92 noutbuf_loc
= noutbuf_loc
+ recvcounts
[p
] ;
95 if ( noutbuf_loc
> * noutbuf
)
98 fprintf(stderr
,"FATAL ERROR: collect_on_comm: noutbuf_loc (%d) > noutbuf (%d)\n",
99 noutbuf_loc
, * noutbuf
) ;
100 fprintf(stderr
,"WILL NOT perform the collection operation\n") ;
102 MPI_Abort(MPI_COMM_WORLD
,1) ;
105 /* multiply everything by the size of the type */
106 for ( p
= 0 ; p
< ntasks
; p
++ ) {
107 displace
[p
] *= *typesize
;
108 recvcounts
[p
] *= *typesize
;
112 ierr
= MPI_Gatherv( inbuf
, *ninbuf
* *typesize
, MPI_CHAR
,
113 outbuf
, recvcounts
, displace
, MPI_CHAR
,
114 root_task
, *comm
) ;
116 if ( ierr
!= 0 ) fprintf(stderr
,"%s %d MPI_Gatherv returns %d\n",__FILE__
,__LINE__
,ierr
) ;
126 dst_on_comm ( int * Fcomm
, int * typesize
,
127 void * inbuf
, int *ninbuf
, void * outbuf
, int * noutbuf
, int sw
) ;
130 DIST_ON_COMM ( int * comm
, int * typesize
,
131 void * inbuf
, int *ninbuf
, void * outbuf
, int * noutbuf
)
133 dst_on_comm ( comm
, typesize
,
134 inbuf
, ninbuf
, outbuf
, noutbuf
, 1 ) ;
138 DIST_ON_COMM0 ( int * comm
, int * typesize
,
139 void * inbuf
, int *ninbuf
, void * outbuf
, int * noutbuf
)
141 dst_on_comm ( comm
, typesize
,
142 inbuf
, ninbuf
, outbuf
, noutbuf
, 0 ) ;
146 dst_on_comm ( int * Fcomm
, int * typesize
,
147 void * inbuf
, int *ninbuf
, void * outbuf
, int * noutbuf
, int sw
)
149 #if defined(DM_PARALLEL) && ! defined(STUBMPI)
150 int mytask
, ntasks
, p
;
155 MPI_Comm
*comm
, dummy_comm
;
158 *comm
= MPI_Comm_f2c( *Fcomm
) ;
159 MPI_Comm_size ( *comm
, &ntasks
) ;
160 MPI_Comm_rank ( *comm
, &mytask
) ;
161 sendcounts
= (int *) malloc( ntasks
* sizeof(int)) ;
162 displace
= (int *) malloc( ntasks
* sizeof(int)) ;
163 root_task
= ( sw
== 0 ) ? 0 : ntasks
-1 ;
165 /* collect up sendcounts */
166 MPI_Gather( noutbuf
, 1 , MPI_INT
, sendcounts
, 1 , MPI_INT
, root_task
, *comm
) ;
168 if ( mytask
== root_task
) {
170 /* figure out displacements */
171 for ( p
= 1 , displace
[0] = 0 , noutbuf_loc
= sendcounts
[0] ; p
< ntasks
; p
++ ) {
172 displace
[p
] = displace
[p
-1]+sendcounts
[p
-1] ;
173 noutbuf_loc
= noutbuf_loc
+ sendcounts
[p
] ;
176 /* multiply everything by the size of the type */
177 for ( p
= 0 ; p
< ntasks
; p
++ ) {
178 displace
[p
] *= *typesize
;
179 sendcounts
[p
] *= *typesize
;
183 MPI_Scatterv( inbuf
, sendcounts
, displace
, MPI_CHAR
,
184 outbuf
, *noutbuf
* *typesize
, MPI_CHAR
,
185 root_task
, *comm
) ;
196 # include <sys/resource.h>
202 struct rusage
*r_usage
);
207 extern int maxstug
, nouty
, maxouty
;
212 #include <sys/times.h>
213 /* used internally for chasing memory leaks on ibm */
218 struct rusage r_usage
;
219 struct mallinfo minf
;
223 tick
= sysconf( _SC_CLK_TCK
) ;
225 tock
= (tm
.tms_utime
+ tm
.tms_stime
)*tick
;
227 getrusage ( RUSAGE_SELF
, &r_usage
) ;
230 fprintf(stderr
,"sm %ld d %ld s %ld maxrss %ld %d %d %ld\n",r_usage
.ru_ixrss
/tock
,r_usage
.ru_idrss
/tock
,r_usage
.ru_isrss
/tock
, r_usage
.ru_maxrss
,tick
,tock
,r_usage
.ru_ixrss
) ;
235 fprintf(stderr
,"a %ld usm %ld fsm %ld uord %ld ford %ld hblkhd %d\n",minf
.arena
,minf
.usmblks
,minf
.fsmblks
,minf
.uordblks
,minf
.fordblks
,minf
.hblkhd
) ;
238 fprintf(stderr
," outy %d nouty %d maxstug %d maxouty %d \n", outy
, nouty
, maxstug
, maxouty
) ;