1 /*****************************************************************************
2  *                                                                           *
3  * Copyright (c) 2003-2006 Intel Corporation.                                *
4  * All rights reserved.                                                      *
5  *                                                                           *
6  *****************************************************************************
7 
8 This code is covered by the Community Source License (CPL), version
9 1.0 as published by IBM and reproduced in the file "license.txt" in the
10 "license" subdirectory. Redistribution in source and binary form, with
11 or without modification, is permitted ONLY within the regulations
12 contained in above mentioned license.
13 
14 Use of the name and trademark "Intel(R) MPI Benchmarks" is allowed ONLY
15 within the regulations of the "License for Use of "Intel(R) MPI
16 Benchmarks" Name and Trademark" as reproduced in the file
17 "use-of-trademark-license.txt" in the "license" subdirectory.
18 
19 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
20 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
21 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
22 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
23 solely responsible for determining the appropriateness of using and
24 distributing the Program and assumes all risks associated with its
25 exercise of rights under this Agreement, including but not limited to
26 the risks and costs of program errors, compliance with applicable
27 laws, damage to or loss of data, programs or equipment, and
28 unavailability or interruption of operations.
29 
30 EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR
31 ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT,
32 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING
33 WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
34 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR
36 DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
37 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
38 
39 EXPORT LAWS: THIS LICENSE ADDS NO RESTRICTIONS TO THE EXPORT LAWS OF
40 YOUR JURISDICTION. It is licensee's responsibility to comply with any
41 export regulations applicable in licensee's jurisdiction. Under
42 CURRENT U.S. export regulations this software is eligible for export
43 from the U.S. and can be downloaded by or otherwise exported or
44 reexported worldwide EXCEPT to U.S.  embargoed destinations which
45 include Cuba, Iraq, Libya, North Korea, Iran, Syria, Sudan,
46 Afghanistan and any other country to which the U.S. has embargoed
47 goods and services.
48 
49  ***************************************************************************
50 
51 For more documentation than found here, see
52 
53 [1] doc/ReadMe_IMB.txt
54 
55 [2] Intel (R) MPI Benchmarks
56     Users Guide and Methodology Description
57     In
58     doc/IMB_ug.pdf
59 
60  File: IMB_init_transfer.c
61 
62  Implemented functions:
63 
64  IMB_init_transfer;
65  IMB_close_transfer;
66 
67  ***************************************************************************/
68 
69 
70 
71 
72 
73 #include "mpi.h"
74 #include "IMB_declare.h"
75 #include "IMB_benchmark.h"
76 
77 #include "IMB_prototypes.h"
78 
79 
80 
81 
IMB_init_transfer(struct comm_info * c_info,struct Bench * Bmark,int size)82 void IMB_init_transfer(struct comm_info* c_info, struct Bench* Bmark, int size)
83 /*
84 
85 
86                       For IO  case: file splitting/view is set, file is opened
87                       For EXT case: window is created and synchronized (MPI_Win_fence)
88 
89 
90 
91 Input variables:
92 
93 -Bmark                (type struct Bench*)
94                       (For explanation of struct Bench type:
95                       describes all aspects of modes of a benchmark;
96                       see [1] for more information)
97 
98                       Given benchmark
99 
100 
101 -size                 (type int)
102                       (Only IO case): used to determine file view
103 
104 
105 
106 In/out variables:
107 
108 -c_info               (type struct comm_info*)
109                       Collection of all base data for MPI;
110                       see [1] for more information
111 
112                       Corresponding components (File or Window related) are set
113 
114 
115 
116 */
117 {
118 
119 
120 #ifdef MPIIO
121 
122 int ne, baslen, mod;
123 int ierr;
124 int pos1, pos2;
125 
126 if( c_info->File_rank < 0 || Bmark->access == no ) return;
127 
128 IMB_get_rank_portion(c_info->File_rank, c_info->all_io_procs, size, asize,
129                  &pos1, &pos2);
130 baslen = max(0,pos2-pos1+1);
131 
132 if( c_info->view != MPI_DATATYPE_NULL )
133     MPI_Type_free(&c_info->view);
134 
135 if( Bmark->fpointer == private )
136   {
137 
138   c_info->split.Locsize = baslen;
139   c_info->split.Offset = 0;
140   c_info->split.Totalsize = baslen;
141 
142   if( Bmark->access == put )
143     IMB_set_buf(c_info, c_info->File_rank, 0, baslen-1, 1, 0);
144   if( Bmark->access == get )
145     IMB_set_buf(c_info, c_info->File_rank, 1, 0, 0, baslen-1);
146 
147   }
148 if( Bmark->fpointer == indv_block || Bmark->fpointer == shared ||
149     Bmark->fpointer == explicit )
150   {
151   int bllen[3];
152 
153   MPI_Aint displ[3];
154   MPI_Datatype types[3];
155 
156   bllen[0]=1; displ[0] = 0; types[0] = MPI_LB;
157 
158   bllen[1] = baslen;
159   displ[1] = pos1;
160   types[1] = c_info->etype;
161 
162   bllen[2] = 1;
163   displ[2] = size;
164   types[2] = MPI_UB;
165 
166   if( Bmark->fpointer == indv_block )
167   {
168 /* July 2002 fix V2.2.1: handle empty view case separately */
169   if( baslen>0 ){
170 /* end change */
171   ierr=MPI_Type_struct(3,bllen,displ,types,&c_info->view);
172   IMB_err_hand(1,ierr);
173   ierr=MPI_Type_commit(&c_info->view);
174   IMB_err_hand(1,ierr);
175   c_info->filetype = c_info->view;
176 
177 /* July 2002 fix V2.2.1: handle empty case */
178   }
179   else c_info->filetype = c_info->etype;
180 /* end change */
181 
182   }
183 
184   if( Bmark->access == put )
185      IMB_set_buf(c_info, c_info->File_rank, 0, baslen-1, 1, 0 );
186 
187   if( Bmark->access == get )
188      IMB_set_buf(c_info, c_info->File_rank, 1, 0, 0, baslen-1 );
189 
190   c_info->split.Locsize = bllen[1];
191   c_info->split.Offset  = pos1;
192   c_info->split.Totalsize = size;
193 
194   }
195 
196   ierr = IMB_open_file(c_info);
197 
198 #else
199 
200 #ifdef EXT
201 int sz, s_size, r_size, maxlen;
202 int ierr;
203 
204 ierr=0;
205 
206 if( Bmark->reduction )
207 {
208 MPI_Type_size(c_info->red_data_type,&s_size);
209 r_size=s_size;
210 }
211 else
212 {
213 MPI_Type_size(c_info->s_data_type,&s_size);
214 MPI_Type_size(c_info->r_data_type,&r_size);
215 }
216 
217 if( c_info -> rank >= 0 )
218 {
219 IMB_user_set_info(&c_info->info);
220 
221 maxlen = 1<<MAXMSGLOG;
222 sz = max(maxlen,OVERALL_VOL);
223 if( OVERALL_VOL/MSGSPERSAMPLE > maxlen ) sz = maxlen*MSGSPERSAMPLE;
224 
225 if( Bmark->access == put)
226 {
227   ierr = MPI_Win_create(c_info->r_buffer,sz,r_size,c_info->info,
228                         c_info->communicator, &c_info->WIN);
229   MPI_ERRHAND(ierr);
230   ierr = MPI_Win_fence(0, c_info->WIN);
231   MPI_ERRHAND(ierr);
232 }
233 else if( Bmark->access == get)
234 {
235   ierr = MPI_Win_create(c_info->s_buffer,sz,s_size,c_info->info,
236                         c_info->communicator, &c_info->WIN);
237   MPI_ERRHAND(ierr);
238   ierr = MPI_Win_fence(0, c_info->WIN);
239   MPI_ERRHAND(ierr);
240 }
241 
242 
243 }
244 
245 #endif
246 
247 #endif
248 
249 IMB_set_errhand(c_info);
250 err_flag = 0;
251 
252 }
253 
254 
255 
256 
IMB_close_transfer(struct comm_info * c_info,struct Bench * Bmark,int size)257 void IMB_close_transfer (struct comm_info* c_info, struct Bench* Bmark, int size)
258 /*
259 
260 
261                       Closes / frees file / window components
262 
263 
264 
265 Input variables:
266 
267 -Bmark                (type struct Bench*)
268                       (For explanation of struct Bench type:
269                       describes all aspects of modes of a benchmark;
270                       see [1] for more information)
271 
272                       Given benchmark
273 
274 
275 -size                 (type int)
276                       (Only IO case): used to determine file view
277 
278 
279 
280 In/out variables:
281 
282 -c_info               (type struct comm_info*)
283                       Collection of all base data for MPI;
284                       see [1] for more information
285 
286                       Corresponding components (File or Window related) are freed
287 
288 
289 
290 */
291 {
292 #ifdef MPIIO
293 if( c_info->view != MPI_DATATYPE_NULL )
294     MPI_Type_free(&c_info->view);
295 
296 MPI_File_close(&c_info->fh);
297 
298 #else
299 #ifdef EXT
300 
301 if( c_info->WIN != MPI_WIN_NULL )
302 MPI_Win_free(&c_info->WIN);
303 
304 #endif
305 
306 #endif
307 }
308