1 /***********************************************************************
5 The following is a notice of limited availability of the code and
6 Government license and disclaimer which must be included in the
7 prologue of the code and in all source listings of the code.
10 (c) 1977 University of Chicago
12 Permission is hereby granted to use, reproduce, prepare
13 derivative works, and to redistribute to others at no charge. If
14 you distribute a copy or copies of the Software, or you modify a
15 copy or copies of the Software or any portion of it, thus forming
16 a work based on the Software and make and/or distribute copies of
17 such work, you must meet the following conditions:
19 a) If you make a copy of the Software (modified or verbatim)
20 it must include the copyright notice and Government
21 license and disclaimer.
23 b) You must cause the modified Software to carry prominent
24 notices stating that you changed specified portions of
27 This software was authored by:
29 Argonne National Laboratory
30 J. Michalakes: (630) 252-6646; email: michalak@mcs.anl.gov
31 Mathematics and Computer Science Division
32 Argonne National Laboratory, Argonne, IL 60439
34 ARGONNE NATIONAL LABORATORY (ANL), WITH FACILITIES IN THE STATES
35 OF ILLINOIS AND IDAHO, IS OWNED BY THE UNITED STATES GOVERNMENT,
36 AND OPERATED BY THE UNIVERSITY OF CHICAGO UNDER PROVISION OF A
37 CONTRACT WITH THE DEPARTMENT OF ENERGY.
39 GOVERNMENT LICENSE AND DISCLAIMER
41 This computer code material was prepared, in part, as an account
42 of work sponsored by an agency of the United States Government.
43 The Government is granted for itself and others acting on its
44 behalf a paid-up, nonexclusive, irrevocable worldwide license in
45 this data to reproduce, prepare derivative works, distribute
46 copies to the public, perform publicly and display publicly, and
47 to permit others to do so. NEITHER THE UNITED STATES GOVERNMENT
48 NOR ANY AGENCY THEREOF, NOR THE UNIVERSITY OF CHICAGO, NOR ANY OF
49 THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR
50 ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
51 COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS,
52 PRODUCT, OR PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD
53 NOT INFRINGE PRIVATELY OWNED RIGHTS.
55 ***************************************************************************/
66 typedef struct bufdesc
{
71 /* buftab[RSL_SENDBUF] is send buffer descriptor,
72 buftab[RSL_RECVBUF] is recv buffer descriptor. */
73 static bufdesc_t buftab
[2][RSL_MAXPROC
] ;
74 static int first
= 1 ;
79 returns a pointer to a buffer already allocated for processor P if
80 it is big enough; otherwise, it frees the existing buffer, if there
81 is one and then allocates a new one that is big enough. If RSL_FREEBUF
82 is called for a P, the two buffers (send and recv) are truncated and
83 freed and NULL is returned.
85 You are guaranteed to get back the same buffer as the previous call
86 for a given P, as long as the size is less than the size passed to
87 the previous call. Thus, you can use this routine to manage the
88 pointers to the buffers for P and avoid having to set up arrays
89 of pointers in the routines that use these buffers.
94 buffer_for_proc( P
, size
, code
)
95 int P
; /* processor number */
96 int size
, /* requested size */
97 code
; /* RSL_SENDBUF, RSL_RECVBUF, or RSL_FREEBUF */
107 for ( p
= 0 ; p
< RSL_MAXPROC
; p
++ )
109 buftab
[0][p
].buf
= NULL
;
110 buftab
[1][p
].buf
= NULL
;
111 buftab
[0][p
].size
= 0 ;
112 buftab
[1][p
].size
= 0 ;
116 if ( P
< 0 || P
>= RSL_MAXPROC
)
118 sprintf(mess
,"Bad P argument to buffer_for_proc. P = %d. Has RSL_MESH been called?\n",P
) ;
119 RSL_TEST_ERR( 1, mess
) ;
121 if ( code
== RSL_FREEBUF
)
123 /* fprintf(stderr,"buffer_for_proc freeing buffer %d\n",P) ; */
124 if ( buftab
[0][P
].buf
!= NULL
) RSL_FREE( buftab
[0][P
].buf
) ;
125 if ( buftab
[1][P
].buf
!= NULL
) RSL_FREE( buftab
[1][P
].buf
) ;
126 buftab
[0][P
].buf
= NULL
;
127 buftab
[1][P
].buf
= NULL
;
128 buftab
[0][P
].size
= 0 ;
129 buftab
[1][P
].size
= 0 ;
130 /* show_tot_size() ; */
132 else if ( code
== RSL_SENDBUF
|| code
== RSL_RECVBUF
)
134 if ( buftab
[code
][P
].size
< size
)
137 fprintf(stderr
,"buffer_for_proc %s %d : was %d, increasing to %d\n",
138 (code
== RSL_SENDBUF
)?"RSL_SENDBUF":"RSL_RECVBUF",
139 P
,buftab
[code
][P
].size
, size
+512) ;
141 if ( buftab
[code
][P
].buf
!= NULL
) RSL_FREE( buftab
[code
][P
].buf
) ;
142 buftab
[code
][P
].buf
= RSL_MALLOC(char,size
+512) ;
143 buftab
[code
][P
].size
= size
+512 ;
144 /* show_tot_size() ; */
146 ret
= buftab
[code
][P
].buf
;
157 for ( P
= 0 ; P
< RSL_MAXPROC
; P
++ )
159 acc
+= buftab
[0][P
].size
;
160 acc
+= buftab
[1][P
].size
;
163 fprintf(stderr
,"Total bytes allocated for buffers: %d\n", acc
) ;
168 buffer_size_for_proc( int P
, int code
)
170 return( buftab
[code
][P
].size
) ;