00001
00002
00003
00004
00005
00006
00007
00008 #include <assert.h>
00009 #include "adio.h"
00010 #include "adio_extern.h"
00011 #ifdef AGGREGATION_PROFILE
00012 #include "mpe.h"
00013 #endif
00014 #include "heap-sort.h"
00015
00016
00017
00018
00019
00020
00021
00022
00023 #define DTYPE_SKIP
00024
00025 #ifdef DEBUG3
00026 static char *off_type_name[MAX_OFF_TYPE] = {"TEMP_OFFSETS",
00027 "REAL_OFFSETS"};
00028 #endif
00029
00030
00031 static inline ADIO_Offset view_state_get_cur_sz(view_state *tmp_view_state_p,
00032 int op_type)
00033 {
00034 flatten_state *tmp_state_p = NULL;
00035 switch(op_type)
00036 {
00037 case TEMP_OFF:
00038 tmp_state_p = &(tmp_view_state_p->tmp_state);
00039 break;
00040 case REAL_OFF:
00041 tmp_state_p = &(tmp_view_state_p->cur_state);
00042 break;
00043 default:
00044 fprintf(stderr, "op_type invalid\n");
00045 }
00046 return tmp_state_p->cur_sz;
00047 }
00048
00049
00050 static inline ADIO_Offset view_state_get_next_len(view_state *tmp_view_state_p,
00051 int op_type)
00052 {
00053 flatten_state *tmp_state_p = NULL;
00054 switch(op_type)
00055 {
00056 case TEMP_OFF:
00057 tmp_state_p = &(tmp_view_state_p->tmp_state);
00058 break;
00059 case REAL_OFF:
00060 tmp_state_p = &(tmp_view_state_p->cur_state);
00061 break;
00062 default:
00063 fprintf(stderr, "op_type invalid\n");
00064 }
00065 return (ADIO_Offset)
00066 tmp_view_state_p->flat_type_p->blocklens[tmp_state_p->idx] -
00067 tmp_state_p->cur_reg_off;
00068 }
00069
00070
00071
00072
00073
00074 static inline int view_state_add_region(
00075 ADIO_Offset max_sz,
00076 view_state *tmp_view_state_p,
00077 ADIO_Offset *st_reg_p,
00078 ADIO_Offset *tmp_reg_sz_p,
00079 int op_type)
00080 {
00081 ADIOI_Flatlist_node *tmp_flat_type_p = NULL;
00082 flatten_state *tmp_state_p = NULL;
00083 int64_t data_sz = 0;
00084
00085 #ifdef AGGREGATION_PROFILE
00086
00087 #endif
00088
00089 switch(op_type)
00090 {
00091 case TEMP_OFF:
00092 tmp_state_p = &(tmp_view_state_p->tmp_state);
00093 break;
00094 case REAL_OFF:
00095 tmp_state_p = &(tmp_view_state_p->cur_state);
00096 break;
00097 default:
00098 fprintf(stderr, "op_type invalid\n");
00099 }
00100
00101 tmp_flat_type_p = tmp_view_state_p->flat_type_p;
00102
00103 *st_reg_p = tmp_state_p->abs_off;
00104
00105
00106
00107 assert(tmp_state_p->cur_reg_off !=
00108 tmp_flat_type_p->blocklens[tmp_state_p->idx]);
00109
00110 assert(tmp_state_p->cur_sz != tmp_view_state_p->sz);
00111
00112
00113 assert(tmp_flat_type_p->blocklens[tmp_state_p->idx] != 0);
00114
00115 #ifdef DEBUG3
00116 fprintf(stderr, "view_state:(blocklens[%Ld]=%d,cur_reg_off=%Ld,"
00117 "max_sz=%Ld)\n", tmp_state_p->idx,
00118 tmp_flat_type_p->blocklens[tmp_state_p->idx],
00119 tmp_state_p->cur_reg_off, max_sz);
00120 #endif
00121
00122
00123 if (tmp_flat_type_p->blocklens[tmp_state_p->idx] -
00124 tmp_state_p->cur_reg_off <= max_sz)
00125 {
00126 data_sz = tmp_flat_type_p->blocklens[tmp_state_p->idx] -
00127 tmp_state_p->cur_reg_off;
00128
00129 tmp_state_p->cur_sz += data_sz;
00130
00131
00132 if (tmp_flat_type_p->count == 1)
00133 {
00134 assert(tmp_flat_type_p->blocklens[tmp_state_p->idx] != 0);
00135 tmp_state_p->abs_off += data_sz;
00136 #ifdef DEBUG3
00137 fprintf(stderr, "view_state_add_region: %s contig type "
00138 "(old abs_off=%Ld,abs_off=%Ld,cur_sz=%Ld,reg size=%Ld)\n",
00139 off_type_name[op_type], tmp_state_p->abs_off - data_sz,
00140 tmp_state_p->abs_off, tmp_state_p->cur_sz, data_sz);
00141 #endif
00142 }
00143 else
00144 {
00145
00146 if (tmp_state_p->idx == (tmp_flat_type_p->count - 1))
00147 {
00148 tmp_state_p->abs_off += data_sz -
00149 tmp_flat_type_p->indices[tmp_flat_type_p->count-1] -
00150 tmp_flat_type_p->blocklens[tmp_flat_type_p->count-1] +
00151 tmp_view_state_p->ext;
00152 #ifdef DEBUG3
00153 fprintf(stderr, "view_state_add_region: %s last region for type "
00154 "(old abs_off=%Ld,abs_off=%Ld,cur_sz=%Ld,reg size=%Ld)\n",
00155 off_type_name[op_type], tmp_state_p->abs_off - data_sz,
00156 tmp_state_p->abs_off, tmp_state_p->cur_sz, data_sz);
00157 #endif
00158 }
00159 else
00160 {
00161 tmp_state_p->abs_off +=
00162 tmp_flat_type_p->indices[tmp_state_p->idx + 1] -
00163 (tmp_flat_type_p->indices[tmp_state_p->idx] +
00164 tmp_state_p->cur_reg_off);
00165 #ifdef DEBUG3
00166 fprintf(stderr, "view_state_add_region: %s inner region type "
00167 "(old abs_off=%Ld,abs_off=%Ld,cur_sz=%Ld,reg size=%Ld)\n",
00168 off_type_name[op_type], tmp_state_p->abs_off -
00169 (tmp_flat_type_p->indices[tmp_state_p->idx + 1] -
00170 (tmp_flat_type_p->indices[tmp_state_p->idx] +
00171 tmp_state_p->cur_reg_off)), tmp_state_p->abs_off,
00172 tmp_state_p->cur_sz, data_sz);
00173 #endif
00174 }
00175
00176 do {
00177 tmp_state_p->idx =
00178 (tmp_state_p->idx + 1) % tmp_flat_type_p->count;
00179 } while (tmp_flat_type_p->blocklens[tmp_state_p->idx] == 0);
00180 }
00181 tmp_state_p->cur_reg_off = 0;
00182 }
00183 else
00184 {
00185 data_sz = max_sz;
00186 tmp_state_p->cur_reg_off += data_sz;
00187 tmp_state_p->abs_off += data_sz;
00188 tmp_state_p->cur_sz += data_sz;
00189 #ifdef DEBUG3
00190 fprintf(stderr, "view_state_add_region: %s partial region type "
00191 "(cur_reg_off=%Ld,abs_off=%Ld,cur_sz=%Ld,reg size=%Ld\n",
00192 off_type_name[op_type], tmp_state_p->cur_reg_off,
00193 tmp_state_p->abs_off, tmp_state_p->cur_sz, data_sz);
00194 #endif
00195 }
00196
00197 *tmp_reg_sz_p = data_sz;
00198 #ifdef AGGREGATION_PROFILE
00199
00200 #endif
00201 return 0;
00202 }
00203
00204
00205
00206 int ADIOI_init_view_state(int file_ptr_type,
00207 int nprocs,
00208 view_state *view_state_arr,
00209 int op_type)
00210 {
00211 ADIOI_Flatlist_node *tmp_flat_type_p = NULL;
00212 ADIO_Offset tmp_off_used = 0, st_reg = 0, tmp_reg_sz = 0;
00213 int i;
00214 flatten_state *tmp_state_p = NULL;
00215 view_state *tmp_view_p = NULL;
00216
00217 for (i = 0; i < nprocs; i++)
00218 {
00219 switch(op_type)
00220 {
00221 case TEMP_OFF:
00222 tmp_state_p = &(view_state_arr[i].tmp_state);
00223 break;
00224 case REAL_OFF:
00225 tmp_state_p = &(view_state_arr[i].cur_state);
00226 break;
00227 default:
00228 fprintf(stderr, "op_type invalid\n");
00229 }
00230
00231 tmp_view_p = &(view_state_arr[i]);
00232 tmp_flat_type_p = tmp_view_p->flat_type_p;
00233
00234 if (file_ptr_type == ADIO_INDIVIDUAL)
00235 tmp_state_p->abs_off = tmp_view_p->fp_ind;
00236 else
00237 tmp_state_p->abs_off = tmp_view_p->disp;
00238
00239 tmp_off_used = 0;
00240
00241
00242 while (tmp_flat_type_p->blocklens[tmp_state_p->idx] == 0)
00243 tmp_state_p->idx = (tmp_state_p->idx + 1) % tmp_flat_type_p->count;
00244 if (file_ptr_type == ADIO_EXPLICIT_OFFSET)
00245 tmp_state_p->abs_off += tmp_flat_type_p->indices[tmp_state_p->idx];
00246
00247
00248
00249
00250
00251 while (tmp_off_used != tmp_view_p->byte_off)
00252 {
00253 view_state_add_region(
00254 tmp_view_p->byte_off - tmp_off_used,
00255 &(view_state_arr[i]), &st_reg, &tmp_reg_sz,
00256 op_type);
00257 }
00258
00259
00260
00261 tmp_state_p->cur_sz = 0;
00262 #ifdef DEBUG1
00263 fprintf(stderr, "init_view_state: %s (idx=%d,byte_off=%Ld,"
00264 "abs_off=%Ld,reg_off=%Ld,sz=%Ld)\n", off_type_name[op_type],
00265 i, tmp_view_p->byte_off, tmp_state_p->abs_off,
00266 tmp_state_p->cur_reg_off, tmp_view_p->sz);
00267 #endif
00268
00269 }
00270 return 0;
00271 }
00272
00273
00274
00275 static inline int get_next_fr_off(ADIO_File fd,
00276 ADIO_Offset off,
00277 ADIO_Offset fr_st_off,
00278 MPI_Datatype *fr_type_p,
00279 ADIO_Offset *fr_next_off_p,
00280 ADIO_Offset *fr_max_len_p)
00281 {
00282 MPI_Aint fr_extent = -1;
00283 ADIO_Offset tmp_off, off_rem;
00284 ADIOI_Flatlist_node *fr_node_p = CtvAccess(ADIOI_Flatlist);
00285 int i = -1, fr_dtype_ct = 0;
00286
00287
00288 while (fr_node_p->type != (*fr_type_p))
00289 fr_node_p = fr_node_p->next;
00290 assert(fr_node_p != NULL);
00291
00292
00293 if (off - fr_st_off < 0)
00294 {
00295 *fr_next_off_p = fr_st_off + fr_node_p->indices[0];
00296 *fr_max_len_p = fr_node_p->blocklens[0];
00297 return 0;
00298 }
00299
00300
00301
00302 MPI_Type_extent(*fr_type_p, &fr_extent);
00303 tmp_off = off - fr_st_off;
00304 fr_dtype_ct = tmp_off / fr_extent;
00305 off_rem = tmp_off % fr_extent;
00306 for (i = 0; i < fr_node_p->count; i++)
00307 {
00308 if (off_rem < fr_node_p->indices[i])
00309 {
00310 *fr_next_off_p = fr_st_off +
00311 (fr_dtype_ct * fr_extent) + fr_node_p->indices[i];
00312 *fr_max_len_p = fr_node_p->blocklens[i];
00313 return 0;
00314 }
00315 else if (off_rem < fr_node_p->indices[i] + fr_node_p->blocklens[i])
00316 {
00317 *fr_next_off_p = off;
00318 *fr_max_len_p = fr_node_p->blocklens[i] -
00319 (off_rem - fr_node_p->indices[i]);
00320 return off;
00321 }
00322 }
00323
00324
00325 fprintf(stderr, "get_next_fr_off: Couldn't find the correct "
00326 "location of the next offset for this file realm.\n");
00327 return -1;
00328 }
00329
00330
00331
00332
00333
00334 static inline int find_next_off(ADIO_File fd,
00335 view_state *view_state_p,
00336 ADIO_Offset fr_st_off,
00337 MPI_Datatype *fr_type_p,
00338 int op_type,
00339 ADIO_Offset *cur_off_p,
00340 ADIO_Offset *cur_reg_max_len_p)
00341 {
00342 ADIOI_Flatlist_node *tmp_flat_type_p = NULL;
00343 ADIO_Offset tmp_off = -1, fr_next_off = -1, fr_max_len = -1,
00344 tmp_fr_max_len = -1;
00345 int ret = -1;
00346 flatten_state *tmp_state_p = NULL;
00347 ADIO_Offset tmp_st_off = 0, tmp_reg_sz = 0;
00348 #ifdef DTYPE_SKIP
00349 int skip_type_ct;
00350 #endif
00351
00352 #ifdef AGGREGATION_PROFILE
00353
00354 #endif
00355
00356 switch(op_type)
00357 {
00358 case TEMP_OFF:
00359 tmp_state_p = &(view_state_p->tmp_state);
00360 break;
00361 case REAL_OFF:
00362 tmp_state_p = &(view_state_p->cur_state);
00363 break;
00364 default:
00365 fprintf(stderr, "op_type invalid\n");
00366 }
00367
00368 tmp_flat_type_p = view_state_p->flat_type_p;
00369
00370
00371 if (tmp_state_p->cur_sz < view_state_p->sz) {
00372 tmp_st_off = 0;
00373 tmp_reg_sz = 0;
00374
00375
00376
00377 ret = get_next_fr_off(fd,
00378 tmp_state_p->abs_off,
00379 fr_st_off,
00380 fr_type_p,
00381 &fr_next_off,
00382 &fr_max_len);
00383
00384 while ((tmp_state_p->abs_off < fr_next_off) &&
00385 (tmp_state_p->cur_sz != view_state_p->sz))
00386 {
00387
00388
00389
00390
00391
00392
00393
00394
00395 #ifdef DTYPE_SKIP
00396 if (tmp_flat_type_p->count > 1) {
00397
00398 skip_type_ct = (fr_next_off - tmp_state_p->abs_off) /
00399 view_state_p->ext;
00400 if (skip_type_ct > 0) {
00401
00402
00403 tmp_state_p->cur_sz += skip_type_ct *
00404 view_state_p->type_sz;
00405 if (tmp_state_p->cur_sz >= view_state_p->sz) {
00406 tmp_state_p->cur_sz = view_state_p->sz;
00407 break;
00408 }
00409 tmp_state_p->abs_off += skip_type_ct * view_state_p->ext;
00410 }
00411 }
00412 #endif
00413 view_state_add_region(
00414 fr_next_off - tmp_state_p->abs_off,
00415 view_state_p,
00416 &tmp_st_off,
00417 &tmp_reg_sz,
00418 op_type);
00419
00420 ret = get_next_fr_off(fd,
00421 tmp_state_p->abs_off,
00422 fr_st_off,
00423 fr_type_p,
00424 &fr_next_off,
00425 &fr_max_len);
00426 }
00427
00428 if (tmp_state_p->cur_sz != view_state_p->sz) {
00429 tmp_off = tmp_state_p->abs_off;
00430
00431
00432 tmp_fr_max_len = fr_next_off + fr_max_len - tmp_off;
00433 }
00434 }
00435
00436 *cur_off_p = tmp_off;
00437 *cur_reg_max_len_p = tmp_fr_max_len;
00438 #ifdef AGGREGATION_PROFILE
00439
00440 #endif
00441 return 0;
00442 }
00443
00444
00445
00446
00447
00448
00449
00450 int ADIOI_Build_agg_reqs(ADIO_File fd, int rw_type, int nprocs,
00451 view_state *client_file_view_state_arr,
00452 MPI_Datatype *client_comm_dtype_arr,
00453 ADIO_Offset *client_comm_sz_arr,
00454 ADIO_Offset *agg_dtype_offset_p,
00455 MPI_Datatype *agg_dtype_p)
00456 {
00457 MPI_Aint **client_disp_arr = NULL, *agg_disp_arr = NULL;
00458 int **client_blk_arr = NULL, *agg_blk_arr = NULL;
00459 ADIO_Offset tmp_coll_buf_sz = 0, st_reg = 0, act_reg_sz = 0;
00460 ADIO_Offset cur_off = -1, cur_reg_max_len = -1;
00461 ADIO_Offset ds_fr_end = -1;
00462 ADIO_Offset *fr_st_off_arr = fd->file_realm_st_offs;
00463 MPI_Datatype *fr_type_arr = fd->file_realm_types;
00464 int *client_ol_ct_arr = NULL;
00465 int *client_ol_cur_ct_arr = NULL;
00466 int agg_ol_ct = 0, agg_ol_cur_ct = 0;
00467 int cur_off_proc = -1;
00468 int next_off_idx = -1;
00469 int i = 0, j = 0, all_done = -1;
00470 int agg_idx = fd->my_cb_nodes_index;
00471 heap_t offset_heap;
00472 ADIO_Offset next_off = -1, next_reg_max_len = -1;
00473
00474
00475 ADIO_Offset *client_comm_next_off_arr = NULL;
00476 ADIO_Offset agg_next_off = -1;
00477 #ifdef AGGREGATION_PROFILE
00478 MPE_Log_event (5016, 0, NULL);
00479 #endif
00480
00481 memset(client_comm_sz_arr, 0, nprocs*sizeof(ADIO_Offset));
00482
00483 if ((client_comm_next_off_arr = (ADIO_Offset *)
00484 ADIOI_Malloc(nprocs*sizeof(ADIO_Offset))) == NULL)
00485 {
00486 fprintf(stderr, "ADIOI_Build_agg_reqs: malloc client_next_off_arr "
00487 "failed\n");
00488 return -1;
00489 }
00490
00491 if ((client_ol_ct_arr = (int *) ADIOI_Calloc(nprocs, sizeof(int))) == NULL)
00492 {
00493 fprintf(stderr, "ADIOI_Build_agg_reqs: "
00494 "malloc client_ol_ct_arr failed\n");
00495 return -1;
00496 }
00497 if ((client_ol_cur_ct_arr =
00498 (int *) ADIOI_Calloc(nprocs, sizeof(int))) == NULL)
00499 {
00500 fprintf(stderr, "ADIOI_Build_agg_reqs: "
00501 "malloc client_ol_cur_ct_arr failed\n");
00502 return -1;
00503 }
00504
00505
00506
00507
00508
00509
00510
00511 for (i = 0; i < MAX_OFF_TYPE; i++)
00512 {
00513 memset(client_comm_next_off_arr, -1, nprocs*sizeof(ADIO_Offset));
00514 tmp_coll_buf_sz = 0;
00515 ds_fr_end = -1;
00516
00517
00518 ADIOI_Heap_create(&offset_heap, nprocs);
00519 offset_heap.size = 0;
00520
00521 for (j=0; j<nprocs; j++) {
00522 find_next_off(fd,
00523 &client_file_view_state_arr[j],
00524 fr_st_off_arr[agg_idx],
00525 &(fr_type_arr[agg_idx]),
00526 i,
00527 &cur_off,
00528 &cur_reg_max_len);
00529 if ((cur_off != -1) && (cur_reg_max_len > 0)) {
00530 ADIOI_Heap_insert(&offset_heap, cur_off, j, cur_reg_max_len);
00531 #ifdef DEBUG_HEAP
00532 printf ("initial: inserting offset %lld with "
00533 "cur_reg_max_len = %lld for p%d\n",
00534 cur_off, cur_reg_max_len, j);
00535 #endif
00536 }
00537
00538 }
00539 if (!offset_heap.size)
00540 ADIOI_Heap_insert(&offset_heap, -1, -1, -1);
00541
00542 while (tmp_coll_buf_sz < fd->hints->cb_buffer_size)
00543 {
00544
00545
00546
00547 ADIOI_Heap_extract_min(&offset_heap, &cur_off, &cur_off_proc,
00548 &cur_reg_max_len);
00549 #ifdef DEBUG_HEAP
00550 printf ("extracted cur_off %lld from proc %d\n",
00551 cur_off, cur_off_proc);
00552 #endif
00553
00554 if (cur_off == -1)
00555 break;
00556
00557 #ifdef DEBUG3
00558 fprintf(stderr, "ADIOI_Build_agg_reqs: %s proc %d start/add to"
00559 " list (max_reg_fr=%Ld,tmp_coll_buf_sz=%Ld,"
00560 "cb_buffer_size=%d)\n", off_type_name[i], cur_off_proc,
00561 cur_reg_max_len, tmp_coll_buf_sz,
00562 fd->hints->cb_buffer_size);
00563 #endif
00564
00565
00566
00567
00568
00569 if ((fd->hints->ds_write == ADIOI_HINT_ENABLE ||
00570 fd->hints->ds_write == ADIOI_HINT_AUTO) &&
00571 rw_type == ADIOI_WRITE && fd->hints->cb_nodes > 1)
00572 {
00573 #ifdef DEBUG2
00574 fprintf(stderr, "ADIOI_Build_agg_reqs: "
00575 "Warning - Data sieving writes on\n");
00576 #endif
00577 if (ds_fr_end == -1)
00578 {
00579 ds_fr_end = cur_off + cur_reg_max_len;
00580 #ifdef DEBUG1
00581 fprintf(stderr, "ADIOI_Build_agg_reqs: "
00582 "cur_off=%Ld, cur_reg_max_len=%Ld\n"
00583 "Data sieving file realm end initialized to %Ld\n",
00584 cur_off,
00585 cur_reg_max_len,
00586 ds_fr_end);
00587 #endif
00588 }
00589 else
00590 {
00591
00592
00593 if (ds_fr_end != cur_off + cur_reg_max_len)
00594 {
00595 #ifdef DEBUG1
00596 fprintf(stderr, "ADIOI_Build_agg_reqs: "
00597 "Data sieving file realm end changed from "
00598 "%Ld to %Ld\n", ds_fr_end,
00599 cur_off + cur_reg_max_len);
00600 #endif
00601 break;
00602 }
00603 }
00604 }
00605
00606
00607
00608 if (cur_reg_max_len > (fd->hints->cb_buffer_size -
00609 tmp_coll_buf_sz))
00610 cur_reg_max_len = fd->hints->cb_buffer_size - tmp_coll_buf_sz;
00611
00612 view_state_add_region(
00613 cur_reg_max_len,
00614 &(client_file_view_state_arr[cur_off_proc]),
00615 &st_reg, &act_reg_sz, i);
00616
00617 switch(i)
00618 {
00619 case TEMP_OFF:
00620
00621
00622
00623
00624 if (client_comm_next_off_arr[cur_off_proc] !=
00625 tmp_coll_buf_sz)
00626 {
00627 (client_ol_ct_arr[cur_off_proc])++;
00628 }
00629 client_comm_next_off_arr[cur_off_proc] =
00630 tmp_coll_buf_sz + act_reg_sz;
00631
00632 if (agg_next_off != st_reg)
00633 agg_ol_ct++;
00634 agg_next_off = st_reg + act_reg_sz;
00635 break;
00636 case REAL_OFF:
00637
00638
00639
00640 next_off_idx = client_ol_cur_ct_arr[cur_off_proc];
00641 if (client_comm_next_off_arr[cur_off_proc] !=
00642 tmp_coll_buf_sz)
00643 {
00644 client_disp_arr[cur_off_proc][next_off_idx] =
00645 tmp_coll_buf_sz;
00646 client_blk_arr[cur_off_proc][next_off_idx] =
00647 act_reg_sz;
00648 (client_ol_cur_ct_arr[cur_off_proc])++;
00649 }
00650 else
00651 {
00652 client_blk_arr[cur_off_proc][next_off_idx - 1]
00653 += act_reg_sz;
00654 }
00655 client_comm_sz_arr[cur_off_proc] += act_reg_sz;
00656 client_comm_next_off_arr[cur_off_proc] =
00657 tmp_coll_buf_sz + act_reg_sz;
00658
00659
00660
00661
00662 if (agg_next_off != st_reg)
00663 {
00664
00665
00666 if (!agg_ol_cur_ct)
00667 *agg_dtype_offset_p = st_reg;
00668 agg_disp_arr[agg_ol_cur_ct] = st_reg -
00669 (MPI_Aint) *agg_dtype_offset_p;
00670 agg_blk_arr[agg_ol_cur_ct] = act_reg_sz;
00671 agg_ol_cur_ct++;
00672 }
00673 else
00674 {
00675 agg_blk_arr[agg_ol_cur_ct - 1] += act_reg_sz;
00676 }
00677 agg_next_off = st_reg + act_reg_sz;
00678
00679 break;
00680 default:
00681 fprintf(stderr, "ADIOI_Build_agg_reqs: Impossible type\n");
00682 }
00683 tmp_coll_buf_sz += act_reg_sz;
00684
00685 find_next_off(fd,
00686 &client_file_view_state_arr[cur_off_proc],
00687 fr_st_off_arr[agg_idx],
00688 &(fr_type_arr[agg_idx]),
00689 i,
00690 &next_off,
00691 &next_reg_max_len);
00692
00693 if ((next_off != -1) || (!offset_heap.size)) {
00694 ADIOI_Heap_insert(&offset_heap, next_off, cur_off_proc,
00695 next_reg_max_len);
00696 #ifdef DEBUG_HEAP
00697 printf ("inserting offset %lld for p%d\n", next_off,
00698 cur_off_proc);
00699 #endif
00700 }
00701 }
00702
00703 if (i == TEMP_OFF)
00704 {
00705
00706
00707 if ((client_disp_arr = (MPI_Aint **)
00708 ADIOI_Malloc(nprocs*sizeof(MPI_Aint *))) == NULL)
00709 {
00710 fprintf(stderr, "ADIOI_Build_agg_reqs: malloc "
00711 "client_disp_arr failed\n");
00712 return -1;
00713 }
00714 if ((client_blk_arr = (int **) ADIOI_Malloc(
00715 nprocs*sizeof(int *))) == NULL)
00716 {
00717 ADIOI_Free(client_disp_arr);
00718 fprintf(stderr, "ADIOI_Build_agg_reqs: malloc "
00719 "client_blk_arr failed\n");
00720 return -1;
00721 }
00722 for (j = 0; j < nprocs; j++)
00723 {
00724 if ((client_disp_arr[j] = (MPI_Aint *) ADIOI_Malloc(
00725 client_ol_ct_arr[j]*sizeof(MPI_Aint))) == NULL)
00726 {
00727 fprintf(stderr, "ADIOI_Build_agg_reqs: malloc "
00728 "client_disp_arr[%d] failed\n", j);
00729 return -1;
00730 }
00731 if ((client_blk_arr[j] = (int *)
00732 ADIOI_Malloc(client_ol_ct_arr[j]*sizeof(int))) == NULL)
00733 {
00734 ADIOI_Free(client_disp_arr[j]);
00735 fprintf(stderr, "ADIOI_Build_agg_reqs: malloc "
00736 "client_blk_arr[%d] failed\n", j);
00737 return -1;
00738 }
00739 }
00740
00741 if (agg_ol_ct > 0)
00742 {
00743 if ((agg_disp_arr = (MPI_Aint *) ADIOI_Malloc(
00744 agg_ol_ct*sizeof(MPI_Aint))) == NULL)
00745 {
00746 fprintf(stderr,
00747 "ADIOI_Build_agg_reqs: malloc disp_arr failed\n");
00748 return -1;
00749 }
00750 if ((agg_blk_arr = (int *)
00751 ADIOI_Malloc(agg_ol_ct*sizeof(int))) == NULL)
00752 {
00753 ADIOI_Free(agg_disp_arr);
00754 fprintf(stderr,
00755 "ADIOI_Build_agg_reqs: malloc blk_arr failed\n");
00756 return -1;
00757 }
00758 }
00759 }
00760 ADIOI_Heap_free(&offset_heap);
00761 }
00762
00763
00764
00765 all_done = 1;
00766 for (i = 0; i < nprocs; i++)
00767 {
00768 if ((client_file_view_state_arr[i].cur_state.cur_sz !=
00769 client_file_view_state_arr[i].sz) ||
00770 client_comm_sz_arr[i] != 0)
00771 {
00772 all_done = 0;
00773 break;
00774 }
00775 }
00776 if (all_done == 1)
00777 {
00778 for (i = 0; i < nprocs; i++)
00779 {
00780 client_comm_sz_arr[i] = -1;
00781 }
00782 }
00783
00784
00785
00786 for (i = 0; i < nprocs; i++)
00787 {
00788 if (client_ol_cur_ct_arr[i] != client_ol_ct_arr[i])
00789 {
00790 fprintf(stderr, "ADIOI_Build_agg_reqs: ERROR Process %d "
00791 "processed only %d out of %d ol pairs\n", i,
00792 client_ol_cur_ct_arr[i],
00793 client_ol_ct_arr[i]);
00794 return -1;
00795 }
00796 }
00797 #ifdef DEBUG1
00798 fprintf(stderr, "ADIOI_Build_agg_reqs:(client,ol_pairs,size_req)=");
00799 for (i = 0; i < nprocs; i++)
00800 {
00801 fprintf(stderr, "(%d,%d,%Ld)", i, client_ol_ct_arr[i],
00802 client_comm_sz_arr[i]);
00803 if (i != nprocs - 1)
00804 fprintf(stderr, ",");
00805 }
00806 fprintf(stderr, "\n");
00807 #endif
00808 #ifdef DEBUG1
00809 fprintf(stderr, "ADIOI_Build_agg_reqs: Generated %d of %d "
00810 "aggregate offset-length pairs\n", agg_ol_cur_ct, agg_ol_ct);
00811 #endif
00812 #ifdef DEBUG2
00813 for (i = 0; i < nprocs; i++)
00814 {
00815 if (client_ol_ct_arr[i] > 0)
00816 {
00817 fprintf(stderr, "ADIOI_Build_agg_reqs: p %d (off,len) = ", i);
00818 for (j = 0; j < client_ol_ct_arr[i]; j++)
00819 {
00820 fprintf(stderr, "[%d](%d,%d) ", j,
00821 client_disp_arr[i][j],
00822 client_blk_arr[i][j]);
00823 }
00824 fprintf(stderr, "\n");
00825 }
00826 }
00827 if (agg_ol_ct) {
00828 fprintf(stderr, "ADIOI_Build_agg_reqs:agg_type(off,len)=");
00829 for (i = 0; i < agg_ol_ct; i++)
00830 {
00831 fprintf(stderr, "[%d](%d,%d)",
00832 i, agg_disp_arr[i], agg_blk_arr[i]);
00833 if (i != agg_ol_ct - 1)
00834 fprintf(stderr, ",");
00835 }
00836 fprintf(stderr, "\n");
00837 }
00838 #endif
00839
00840 assert(agg_ol_cur_ct == agg_ol_ct);
00841
00842
00843 for (i = 0; i < nprocs; i++)
00844 {
00845 if (client_comm_sz_arr[i] > 0)
00846 {
00847 MPI_Type_hindexed(client_ol_ct_arr[i], client_blk_arr[i],
00848 client_disp_arr[i], MPI_BYTE,
00849 &(client_comm_dtype_arr[i]));
00850 MPI_Type_commit(&(client_comm_dtype_arr[i]));
00851 }
00852 else
00853 {
00854 client_comm_dtype_arr[i] = MPI_BYTE;
00855 }
00856 ADIOI_Free(client_blk_arr[i]);
00857 ADIOI_Free(client_disp_arr[i]);
00858 }
00859 ADIOI_Free(client_blk_arr);
00860 ADIOI_Free(client_disp_arr);
00861
00862 if (agg_ol_ct > 0) {
00863 if (agg_ol_ct == 1)
00864 MPI_Type_contiguous (agg_blk_arr[0], MPI_BYTE, agg_dtype_p);
00865 else if (agg_ol_ct > 1)
00866 MPI_Type_hindexed(agg_ol_ct, agg_blk_arr, agg_disp_arr, MPI_BYTE,
00867 agg_dtype_p);
00868
00869 MPI_Type_commit(agg_dtype_p);
00870
00871 ADIOI_Free(agg_disp_arr);
00872 ADIOI_Free(agg_blk_arr);
00873 }
00874 ADIOI_Free(client_ol_ct_arr);
00875 ADIOI_Free(client_ol_cur_ct_arr);
00876 ADIOI_Free(client_comm_next_off_arr);
00877 #ifdef AGGREGATION_PROFILE
00878 MPE_Log_event (5017, 0, NULL);
00879 #endif
00880 return 0;
00881 }
00882
00883
00884
00885
00886
00887 int ADIOI_Build_client_reqs(ADIO_File fd,
00888 int nprocs,
00889 view_state *my_mem_view_state_arr,
00890 view_state *agg_file_view_state_arr,
00891 ADIO_Offset *agg_comm_sz_arr,
00892 MPI_Datatype *agg_comm_dtype_arr)
00893 {
00894 MPI_Aint **agg_disp_arr = NULL;
00895 int **agg_blk_arr = NULL;
00896 view_state *tmp_mem_state_p = NULL, *tmp_file_state_p = NULL;
00897 ADIO_Offset total_agg_comm_sz = 0, cur_total_agg_comm_sz = 0;
00898 ADIO_Offset st_reg = 0, act_reg_sz = 0, tmp_reg_sz = 0;
00899 ADIO_Offset cur_off = -1, cur_reg_max_len = -1;
00900 ADIO_Offset tmp_cur_off = -1, tmp_cur_reg_max_len = -1;
00901 ADIO_Offset agg_mem_st_reg = 0, agg_mem_act_reg_sz = 0;
00902 ADIO_Offset *fr_st_off_arr = fd->file_realm_st_offs;
00903 ADIO_Offset *agg_comm_cur_sz_arr = NULL;
00904 MPI_Datatype *fr_type_arr = fd->file_realm_types;
00905 int cb_node_ct = fd->hints->cb_nodes;
00906 int *agg_ol_ct_arr = NULL;
00907 int *agg_ol_cur_ct_arr = NULL;
00908 int agg_fr_idx = -1, tmp_agg_fr_idx = -1;
00909 int cur_off_proc = -1;
00910 int i = 0, j = 0;
00911 int agg_next_off_idx = -1;
00912
00913 ADIO_Offset *agg_mem_next_off_arr = NULL;
00914 #ifdef AGGREGATION_PROFILE
00915 MPE_Log_event (5018, 0, NULL);
00916 #endif
00917
00918 #ifdef DEBUG
00919 fprintf(stderr, "ADIOI_Build_client_reqs:(agg,size_req)=");
00920 for (i = 0; i < nprocs; i++)
00921 {
00922 int tmp_agg_idx = ADIOI_Agg_idx(i, fd);
00923 if (tmp_agg_idx >= 0)
00924 {
00925 fprintf(stderr, "(%d,%Ld)", i, agg_comm_sz_arr[i]);
00926 if (i != fd->hints->cb_nodes - 1)
00927 fprintf(stderr, ",");
00928 }
00929 fprintf(stderr, "\n");
00930 }
00931 #endif
00932
00933 if ((agg_mem_next_off_arr = (ADIO_Offset *) ADIOI_Malloc(
00934 nprocs*sizeof(ADIO_Offset))) == NULL)
00935 {
00936 fprintf(stderr, "ADIOI_Build_client_reqs: malloc agg_mem_next_off_arr"
00937 "failed\n");
00938 return -1;
00939 }
00940
00941 if ((agg_comm_cur_sz_arr = (ADIO_Offset *)
00942 ADIOI_Malloc(nprocs*sizeof(ADIO_Offset))) == NULL)
00943 {
00944 fprintf(stderr, "ADIOI_Build_client_reqs: malloc agg_comm_cur_sz_arr"
00945 " failed\n");
00946 return -1;
00947 }
00948 if ((agg_ol_ct_arr = (int *) ADIOI_Calloc(nprocs, sizeof(int)))
00949 == NULL)
00950 {
00951 fprintf(stderr, "ADIOI_Build_client_reqs: "
00952 "malloc agg_ol_ct_arr failed\n");
00953 return -1;
00954 }
00955 if ((agg_ol_cur_ct_arr = (int *) ADIOI_Calloc(nprocs, sizeof(int)))
00956 == NULL)
00957 {
00958 fprintf(stderr, "ADIOI_Build_client_reqs: "
00959 "malloc agg_ol_cur_ct_arr failed\n");
00960 return -1;
00961 }
00962
00963 for (i = 0; i < nprocs; i++)
00964 {
00965 if (agg_comm_sz_arr[i] > 0)
00966 total_agg_comm_sz += agg_comm_sz_arr[i];
00967 }
00968
00969
00970
00971
00972
00973
00974 for (i = 0; i < MAX_OFF_TYPE; i++)
00975 {
00976 cur_total_agg_comm_sz = 0;
00977 memset(agg_comm_cur_sz_arr, 0, nprocs*sizeof(ADIO_Offset));
00978 memset(agg_mem_next_off_arr, -1, nprocs*sizeof(ADIO_Offset));
00979 while (total_agg_comm_sz > cur_total_agg_comm_sz)
00980 {
00981
00982
00983 cur_off = -1;
00984 for (j = 0; j < nprocs; j++)
00985 {
00986 tmp_agg_fr_idx = ADIOI_Agg_idx(j, fd);
00987 assert(tmp_agg_fr_idx < cb_node_ct);
00988
00989
00990
00991
00992 if (tmp_agg_fr_idx < 0 ||
00993 agg_comm_cur_sz_arr[j] == agg_comm_sz_arr[j])
00994 {
00995 continue;
00996 }
00997
00998 find_next_off(fd,
00999 &(agg_file_view_state_arr[j]),
01000 fr_st_off_arr[tmp_agg_fr_idx],
01001 &(fr_type_arr[tmp_agg_fr_idx]),
01002 i,
01003 &tmp_cur_off,
01004 &tmp_cur_reg_max_len);
01005 if (tmp_cur_off == -1)
01006 continue;
01007
01008 if ((cur_off == -1) ||
01009 (cur_off > tmp_cur_off))
01010 {
01011 agg_fr_idx = tmp_agg_fr_idx;
01012 cur_off_proc = j;
01013 cur_off = tmp_cur_off;
01014 cur_reg_max_len = tmp_cur_reg_max_len;
01015 }
01016 }
01017
01018 assert(cur_off_proc != -1);
01019
01020
01021
01022
01023 if (cur_reg_max_len > agg_comm_sz_arr[cur_off_proc] -
01024 agg_comm_cur_sz_arr[cur_off_proc])
01025 {
01026 cur_reg_max_len = agg_comm_sz_arr[cur_off_proc] -
01027 agg_comm_cur_sz_arr[cur_off_proc];
01028 }
01029 assert(cur_reg_max_len > 0);
01030
01031 view_state_add_region(
01032 cur_reg_max_len,
01033 &(agg_file_view_state_arr[cur_off_proc]),
01034 &st_reg, &act_reg_sz, i);
01035
01036 #ifdef DEBUG2
01037 fprintf(stderr, "ADIOI_Build_client_reqs: %s File region"
01038 " (proc=%d,off=%Ld,sz=%Ld)\n",
01039 off_type_name[i], cur_off_proc,
01040 cur_off, act_reg_sz);
01041 #endif
01042
01043
01044
01045
01046
01047 tmp_file_state_p = &(agg_file_view_state_arr[cur_off_proc]);
01048 tmp_mem_state_p = &(my_mem_view_state_arr[cur_off_proc]);
01049 assert(view_state_get_cur_sz(tmp_file_state_p, i) - act_reg_sz >=
01050 view_state_get_cur_sz(tmp_mem_state_p, i));
01051 while (view_state_get_cur_sz(tmp_file_state_p, i) - act_reg_sz !=
01052 view_state_get_cur_sz(tmp_mem_state_p, i))
01053 {
01054 ADIO_Offset fill_st_reg = -1, fill_reg_sz = -1;
01055 view_state_add_region(
01056 view_state_get_cur_sz(tmp_file_state_p, i) - act_reg_sz -
01057 view_state_get_cur_sz(tmp_mem_state_p, i),
01058 tmp_mem_state_p,
01059 &fill_st_reg,
01060 &fill_reg_sz, i);
01061 }
01062
01063
01064
01065
01066 tmp_reg_sz = 0;
01067 while (tmp_reg_sz != act_reg_sz)
01068 {
01069 view_state_add_region(
01070 act_reg_sz - tmp_reg_sz,
01071 tmp_mem_state_p,
01072 &agg_mem_st_reg, &agg_mem_act_reg_sz,
01073 i);
01074 tmp_reg_sz += agg_mem_act_reg_sz;
01075
01076 #ifdef DEBUG2
01077 fprintf(stderr, "ADIOI_Build_client_reqs: Mem region %s"
01078 "(proc=%d,off=%Ld,sz=%Ld)\n",
01079 off_type_name[i], cur_off_proc,
01080 agg_mem_st_reg, agg_mem_act_reg_sz);
01081 #endif
01082 agg_comm_cur_sz_arr[cur_off_proc] += agg_mem_act_reg_sz;
01083 cur_total_agg_comm_sz += agg_mem_act_reg_sz;
01084 switch(i)
01085 {
01086 case TEMP_OFF:
01087
01088
01089
01090 if (agg_mem_next_off_arr[cur_off_proc] !=
01091 agg_mem_st_reg)
01092 {
01093 agg_ol_ct_arr[cur_off_proc]++;
01094 }
01095 agg_mem_next_off_arr[cur_off_proc] =
01096 agg_mem_st_reg + agg_mem_act_reg_sz;
01097 break;
01098 case REAL_OFF:
01099
01100
01101
01102 agg_next_off_idx = agg_ol_cur_ct_arr[cur_off_proc];
01103 if (agg_mem_next_off_arr[cur_off_proc] !=
01104 agg_mem_st_reg)
01105 {
01106 agg_disp_arr[cur_off_proc][agg_next_off_idx] =
01107 agg_mem_st_reg;
01108 agg_blk_arr[cur_off_proc][agg_next_off_idx] =
01109 agg_mem_act_reg_sz;
01110 (agg_ol_cur_ct_arr[cur_off_proc])++;
01111 }
01112 else
01113 {
01114 agg_blk_arr[cur_off_proc][agg_next_off_idx - 1]
01115 += agg_mem_act_reg_sz;
01116 }
01117 agg_mem_next_off_arr[cur_off_proc] =
01118 agg_mem_st_reg + agg_mem_act_reg_sz;
01119 break;
01120 default:
01121 fprintf(stderr, "ADIOI_Build_client_reqs: "
01122 "Impossible type\n");
01123 }
01124 }
01125 }
01126
01127
01128
01129 if (i == TEMP_OFF)
01130 {
01131
01132
01133 if ((agg_disp_arr = (MPI_Aint **)
01134 ADIOI_Malloc(nprocs*sizeof(MPI_Aint *))) == NULL)
01135 {
01136 fprintf(stderr,
01137 "ADIOI_Build_client_reqs: malloc agg_disp_arr failed\n");
01138 return -1;
01139 }
01140 if ((agg_blk_arr = (int **) ADIOI_Malloc(nprocs*sizeof(int *)))
01141 == NULL)
01142 {
01143 ADIOI_Free(agg_disp_arr);
01144 fprintf(stderr,
01145 "ADIOI_Build_client_reqs: malloc agg_blk_arr failed\n");
01146 return -1;
01147 }
01148 for (j = 0; j < nprocs; j++)
01149 {
01150 if ((agg_disp_arr[j] = (MPI_Aint *)
01151 ADIOI_Malloc(agg_ol_ct_arr[j]*sizeof(MPI_Aint))) == NULL)
01152 {
01153 fprintf(stderr, "ADIOI_Build_client_reqs: malloc "
01154 "agg_disp_arr[%d] failed\n", j);
01155 return -1;
01156 }
01157 if ((agg_blk_arr[j] = (int *)
01158 ADIOI_Malloc(agg_ol_ct_arr[j]*sizeof(int))) == NULL)
01159 {
01160 ADIOI_Free(agg_disp_arr[j]);
01161 fprintf(stderr, "ADIOI_Build_client_reqs: malloc "
01162 "agg_blk_arr[%d] failed\n", j);
01163 return -1;
01164 }
01165 }
01166 }
01167 }
01168
01169 #ifdef DEBUG
01170 fprintf(stderr, "ADIOI_Build_client_reqs:(agg,cur_ol_count=ol_count)=");
01171 for (i = 0; i < nprocs; i++)
01172 {
01173 int tmp_agg_idx = ADIOI_Agg_idx(i, fd);
01174 if (tmp_agg_idx >= 0)
01175 {
01176 fprintf(stderr, "(%d,%d=%d)", i, agg_ol_cur_ct_arr[i],
01177 agg_ol_ct_arr[i]);
01178 assert(agg_ol_ct_arr[i] == agg_ol_cur_ct_arr[i]);
01179 if (tmp_agg_idx != fd->hints->cb_nodes - 1)
01180 fprintf(stderr, ",");
01181 }
01182 }
01183 fprintf(stderr, "\n");
01184 #endif
01185
01186 #ifdef DEBUG2
01187 for (i = 0; i < nprocs; i++)
01188 {
01189 if (agg_ol_ct_arr[i] > 0)
01190 {
01191 fprintf(stderr, "ADIOI_Build_client_reqs: p %d (off,len) = ", i);
01192 for (j = 0; j < agg_ol_ct_arr[i]; j++)
01193 {
01194 fprintf(stderr, "[%d](%d,%d) ", j,
01195 agg_disp_arr[i][j],
01196 agg_blk_arr[i][j]);
01197 }
01198 fprintf(stderr, "\n");
01199 }
01200 }
01201 #endif
01202
01203
01204 for (i = 0; i < nprocs; i++)
01205 {
01206 if (agg_comm_sz_arr[i] > 0)
01207 {
01208 MPI_Type_hindexed(agg_ol_ct_arr[i], agg_blk_arr[i],
01209 agg_disp_arr[i], MPI_BYTE,
01210 &(agg_comm_dtype_arr[i]));
01211 MPI_Type_commit(&(agg_comm_dtype_arr[i]));
01212 }
01213 else
01214 {
01215 agg_comm_dtype_arr[i] = MPI_BYTE;
01216 }
01217 ADIOI_Free(agg_blk_arr[i]);
01218 ADIOI_Free(agg_disp_arr[i]);
01219 }
01220 ADIOI_Free(agg_blk_arr);
01221 ADIOI_Free(agg_disp_arr);
01222
01223 ADIOI_Free(agg_mem_next_off_arr);
01224 ADIOI_Free(agg_comm_cur_sz_arr);
01225 ADIOI_Free(agg_ol_ct_arr);
01226 ADIOI_Free(agg_ol_cur_ct_arr);
01227 #ifdef AGGREGATION_PROFILE
01228 MPE_Log_event (5019, 0, NULL);
01229 #endif
01230 return 0;
01231 }
01232
01233
01234
01235
01236
01237
01238
01239
01240 int ADIOI_Build_client_pre_req(ADIO_File fd,
01241 int agg_rank, int agg_idx,
01242 view_state *my_mem_view_state_p,
01243 view_state *agg_file_view_state_p,
01244 ADIO_Offset max_pre_req_sz,
01245 int max_ol_ct)
01246 {
01247 ADIO_Offset act_reg_sz = 0, tmp_reg_sz = 0;
01248 ADIO_Offset cur_off = -1, cur_reg_max_len = -1;
01249 ADIO_Offset agg_mem_st_reg = 0, agg_mem_act_reg_sz = 0;
01250 int agg_ol_ct = 0, agg_ol_cur_ct = 0;
01251 int i, agg_next_off_idx = -1;
01252
01253 ADIO_Offset cur_sz = 0, max_sz = 0, agg_mem_next_off = -1;
01254 ADIO_Offset fill_st_reg = -1, fill_reg_sz = -1;
01255 ADIO_Offset *fr_st_off_arr = fd->file_realm_st_offs;
01256 MPI_Datatype *fr_type_arr = fd->file_realm_types;
01257 MPI_Aint *tmp_disp_arr = NULL;
01258 int *tmp_blk_arr = NULL, exit_loop = -1;
01259 flatten_state *tmp_mem_state_p = NULL, *tmp_file_state_p = NULL;
01260 #ifdef DTYPE_SKIP
01261 int skip_type_ct;
01262 #endif
01263 if (agg_idx < 0 || agg_idx >= fd->hints->cb_nodes)
01264 {
01265 fprintf(stderr, "ADIOI_Build_client_pre_req: Invalid agg_idx %d\n",
01266 agg_idx);
01267 return -1;
01268 }
01269
01270 if (agg_file_view_state_p->cur_state.cur_sz ==
01271 agg_file_view_state_p->sz || max_pre_req_sz <= 0 ||
01272 max_ol_ct <= 0)
01273 {
01274 #ifdef DEBUG1
01275 fprintf(stderr,
01276 "ADIOI_Build_client_pre_req: Nothing to preprocess\n");
01277 #endif
01278 return 0;
01279 }
01280
01281
01282
01283 if ((my_mem_view_state_p->pre_sz >= max_pre_req_sz) ||
01284 (my_mem_view_state_p->pre_ol_ct >= max_ol_ct))
01285 {
01286 #ifdef DEBUG1
01287 fprintf(stderr,
01288 "ADIOI_Build_client_pre_req: Old values surpass new "
01289 "pre_req values\n");
01290 #endif
01291 return 0;
01292 }
01293
01294
01295
01296
01297
01298 for (i = 0; i < MAX_OFF_TYPE; i++)
01299 {
01300 switch(i)
01301 {
01302 case TEMP_OFF:
01303 tmp_mem_state_p = &(my_mem_view_state_p->tmp_state);
01304 tmp_file_state_p = &(agg_file_view_state_p->tmp_state);
01305 break;
01306 case REAL_OFF:
01307 tmp_mem_state_p = &(my_mem_view_state_p->cur_state);
01308 tmp_file_state_p = &(agg_file_view_state_p->cur_state);
01309 break;
01310 default:
01311 fprintf(stderr, "ADIOI_Build_client_pre_req: "
01312 "Invalid off type %d\n", i);
01313 }
01314
01315 if (i == TEMP_OFF && my_mem_view_state_p->pre_sz > 0)
01316 {
01317 cur_sz = my_mem_view_state_p->pre_sz;
01318 agg_ol_ct = my_mem_view_state_p->pre_ol_ct;
01319
01320 tmp_disp_arr = my_mem_view_state_p->pre_disp_arr;
01321 tmp_blk_arr = my_mem_view_state_p->pre_blk_arr;
01322 my_mem_view_state_p->pre_disp_arr = NULL;
01323 my_mem_view_state_p->pre_blk_arr = NULL;
01324 agg_mem_next_off =
01325 tmp_disp_arr[agg_ol_ct - 1] + tmp_blk_arr[agg_ol_ct - 1];
01326 }
01327 else if (i == REAL_OFF && my_mem_view_state_p->pre_sz > 0)
01328 {
01329 cur_sz = my_mem_view_state_p->pre_sz;
01330 agg_ol_cur_ct = my_mem_view_state_p->pre_ol_ct;
01331
01332
01333
01334 memcpy(my_mem_view_state_p->pre_disp_arr, tmp_disp_arr,
01335 my_mem_view_state_p->pre_ol_ct * sizeof(MPI_Aint));
01336 memcpy(my_mem_view_state_p->pre_blk_arr, tmp_blk_arr,
01337 my_mem_view_state_p->pre_ol_ct * sizeof(int));
01338
01339 ADIOI_Free(tmp_disp_arr);
01340 ADIOI_Free(tmp_blk_arr);
01341
01342 agg_mem_next_off =
01343 my_mem_view_state_p->pre_disp_arr[agg_ol_cur_ct - 1] +
01344 my_mem_view_state_p->pre_blk_arr[agg_ol_cur_ct - 1];
01345 }
01346 else
01347 {
01348 cur_sz = 0;
01349 }
01350
01351
01352
01353 if (max_pre_req_sz - cur_sz >
01354 agg_file_view_state_p->sz - tmp_file_state_p->cur_sz)
01355 {
01356 max_sz = cur_sz +
01357 agg_file_view_state_p->sz - tmp_file_state_p->cur_sz;
01358 }
01359 else
01360 max_sz = max_pre_req_sz;
01361
01362 assert(cur_sz != max_sz);
01363 #ifdef DEBUG1
01364 fprintf(stderr,
01365 "ADIOI_Build_client_pre_req: (cur_sz=%Ld,agg_ol_ct=%d,"
01366 "agg_mem_next_off=%Ld,max_sz=%Ld,max_ol_ct=%d)\n",
01367 cur_sz, agg_ol_ct, agg_mem_next_off, max_sz, max_ol_ct);
01368 #endif
01369 while (cur_sz < max_sz)
01370 {
01371 find_next_off(fd, agg_file_view_state_p,
01372 fr_st_off_arr[agg_rank],
01373 &(fr_type_arr[agg_rank]),
01374 i,
01375 &cur_off,
01376 &cur_reg_max_len);
01377
01378
01379
01380
01381
01382 if (cur_off == -1)
01383 break;
01384
01385 assert(cur_off != -1);
01386
01387
01388
01389
01390
01391 while (tmp_file_state_p->cur_sz != tmp_mem_state_p->cur_sz)
01392 {
01393 #ifdef DTYPE_SKIP
01394 if (my_mem_view_state_p->flat_type_p->count > 1) {
01395
01396 skip_type_ct =
01397 (tmp_file_state_p->cur_sz - tmp_mem_state_p->cur_sz) /
01398 my_mem_view_state_p->type_sz;
01399 if (skip_type_ct > 0) {
01400 tmp_mem_state_p->cur_sz +=
01401 skip_type_ct * my_mem_view_state_p->type_sz;
01402 tmp_mem_state_p->abs_off +=
01403 skip_type_ct * my_mem_view_state_p->ext;
01404 if (tmp_mem_state_p->cur_sz ==
01405 tmp_file_state_p->cur_sz)
01406 break;
01407 }
01408 }
01409 #endif
01410 view_state_add_region(
01411 tmp_file_state_p->cur_sz - tmp_mem_state_p->cur_sz,
01412 my_mem_view_state_p,
01413 &fill_st_reg,
01414 &fill_reg_sz, i);
01415 }
01416
01417
01418
01419
01420
01421
01422
01423 if (cur_reg_max_len >
01424 view_state_get_next_len(agg_file_view_state_p, i))
01425 cur_reg_max_len =
01426 view_state_get_next_len(agg_file_view_state_p, i);
01427
01428 if (cur_reg_max_len > max_sz - cur_sz)
01429 cur_reg_max_len = max_sz - cur_sz;
01430
01431 assert(cur_reg_max_len > 0);
01432
01433
01434
01435
01436 act_reg_sz = 0;
01437 exit_loop = 0;
01438 while ((act_reg_sz < cur_reg_max_len) &&
01439 (exit_loop == 0))
01440 {
01441 view_state_add_region(
01442 cur_reg_max_len - act_reg_sz,
01443 my_mem_view_state_p,
01444 &agg_mem_st_reg, &agg_mem_act_reg_sz,
01445 i);
01446 act_reg_sz += agg_mem_act_reg_sz;
01447
01448 #ifdef DEBUG2
01449 fprintf(stderr, "ADIOI_Build_client_pre_req: %s Mem region"
01450 "(proc=%d,off=%Ld,sz=%Ld)\n",
01451 off_type_name[i], agg_rank, agg_mem_st_reg,
01452 agg_mem_act_reg_sz);
01453 #endif
01454 switch(i)
01455 {
01456 case TEMP_OFF:
01457
01458
01459
01460 if (agg_mem_next_off != agg_mem_st_reg)
01461 {
01462 agg_ol_ct++;
01463 if (agg_ol_ct == max_ol_ct)
01464 exit_loop = 1;
01465 }
01466 agg_mem_next_off =
01467 agg_mem_st_reg + agg_mem_act_reg_sz;
01468 break;
01469 case REAL_OFF:
01470
01471
01472
01473 agg_next_off_idx = agg_ol_cur_ct;
01474 if (agg_mem_next_off != agg_mem_st_reg)
01475 {
01476 my_mem_view_state_p->
01477 pre_disp_arr[agg_next_off_idx] =
01478 agg_mem_st_reg;
01479 my_mem_view_state_p->
01480 pre_blk_arr[agg_next_off_idx] =
01481 agg_mem_act_reg_sz;
01482 agg_ol_cur_ct++;
01483 if (agg_ol_cur_ct == agg_ol_ct)
01484 exit_loop = 1;
01485 }
01486 else
01487 {
01488 my_mem_view_state_p->
01489 pre_blk_arr[agg_next_off_idx - 1]
01490 += agg_mem_act_reg_sz;
01491 }
01492 agg_mem_next_off =
01493 agg_mem_st_reg + agg_mem_act_reg_sz;
01494 break;
01495 default:
01496 fprintf(stderr, "ADIOI_Build_client_pre_req: "
01497 "Impossible type\n");
01498 }
01499 }
01500
01501
01502
01503
01504
01505
01506 view_state_add_region(act_reg_sz - tmp_reg_sz,
01507 agg_file_view_state_p,
01508 &fill_st_reg, &fill_reg_sz, i);
01509 #ifdef DEBUG2
01510 fprintf(stderr, "ADIOI_Build_client_pre_req: %s File region"
01511 " (proc=%d,off=%Ld,sz=%Ld)\n",
01512 off_type_name[i], agg_rank, fill_st_reg, fill_reg_sz);
01513 #endif
01514 if (fill_reg_sz != act_reg_sz)
01515 {
01516 fprintf(stderr, "ADIOI_Build_client_pre_req: "
01517 "view_state_add_region failed to match the memtype\n");
01518 return -1;
01519 }
01520
01521 cur_sz += act_reg_sz;
01522 }
01523
01524
01525
01526 if (i == TEMP_OFF)
01527 {
01528 if ((my_mem_view_state_p->pre_disp_arr = (MPI_Aint *)
01529 ADIOI_Malloc(agg_ol_ct * sizeof(MPI_Aint))) == NULL)
01530 {
01531 fprintf(stderr, "ADIOI_Build_client_pre_req: malloc "
01532 "pre_disp_arr of size %ld failed\n",
01533 (long int)agg_ol_ct * sizeof(MPI_Aint));
01534 return -1;
01535 }
01536 if ((my_mem_view_state_p->pre_blk_arr = (int *)
01537 ADIOI_Malloc(agg_ol_ct * sizeof(int))) == NULL)
01538 {
01539 ADIOI_Free(my_mem_view_state_p->pre_disp_arr);
01540 fprintf(stderr, "ADIOI_Build_client_pre_req: malloc "
01541 "agg_blk_arr of size %ld failed\n",
01542 (long int)agg_ol_ct * sizeof(int));
01543 return -1;
01544 }
01545 }
01546 }
01547
01548 my_mem_view_state_p->pre_sz = cur_sz;
01549 my_mem_view_state_p->pre_ol_ct = agg_ol_ct;
01550
01551 #ifdef DEBUG1
01552 fprintf(stderr, "ADIOI_Build_client_pre_req:(agg=%d,cur_ol_count=%d"
01553 "=ol_count=%d)\n",
01554 agg_rank, my_mem_view_state_p->pre_ol_ct, agg_ol_ct);
01555 #endif
01556
01557 #ifdef DEBUG2
01558 if (agg_ol_ct > 0)
01559 {
01560 fprintf(stderr, "ADIOI_Build_client_pre_req: agg=%d,pre_sz=%Ld "
01561 "(off,len) = \n", agg_rank, my_mem_view_state_p->pre_sz);
01562 for (i = 0; i < my_mem_view_state_p->pre_ol_ct; i++)
01563 {
01564 fprintf(stderr, "[%d](%d,%d) ", i,
01565 my_mem_view_state_p->pre_disp_arr[i],
01566 my_mem_view_state_p->pre_blk_arr[i]);
01567 if (i % 5 == 0 && i != 0)
01568 fprintf(stderr, "\n");
01569 }
01570 fprintf(stderr, "\n");
01571 }
01572 #endif
01573
01574 return 0;
01575 }
01576
01577
01578
01579
01580 static int process_pre_req(ADIO_File fd,
01581 int agg_rank,
01582 int agg_idx,
01583 view_state *my_mem_view_state_p,
01584 view_state *agg_file_view_state_p,
01585 ADIO_Offset agg_comm_sz,
01586 int off_type,
01587 MPI_Aint *agg_disp_arr,
01588 int *agg_blk_arr,
01589 ADIO_Offset *agg_comm_pre_sz_p,
01590 ADIO_Offset *agg_comm_cur_sz_p,
01591 ADIO_Offset *agg_comm_sz_p,
01592 int *agg_ol_cur_ct_p,
01593 int *agg_ol_ct_p,
01594 ADIO_Offset *agg_mem_next_off_p)
01595 {
01596 int i, has_partial = 0;
01597 MPI_Aint partial_disp = 0;
01598 int partial_len = 0;
01599 ADIO_Offset tmp_agg_comm_pre_sz = 0;
01600
01601 assert (my_mem_view_state_p->pre_sz > 0);
01602 switch(off_type)
01603 {
01604 case TEMP_OFF:
01605
01606 if (my_mem_view_state_p->pre_sz > *agg_comm_sz_p)
01607 {
01608 for (i = 0; i < my_mem_view_state_p->pre_ol_ct; i++)
01609 {
01610 if ((my_mem_view_state_p->pre_blk_arr[i] +
01611 *agg_comm_pre_sz_p) > *agg_comm_sz_p)
01612 {
01613 has_partial = 1;
01614 partial_len = *agg_comm_sz_p - *agg_comm_pre_sz_p;
01615 *agg_comm_pre_sz_p = *agg_comm_sz_p;
01616 i++;
01617 break;
01618 }
01619 else if ((my_mem_view_state_p->pre_blk_arr[i] +
01620 *agg_comm_pre_sz_p) == *agg_comm_sz_p)
01621 {
01622 *agg_comm_pre_sz_p +=
01623 my_mem_view_state_p->pre_blk_arr[i];
01624 i++;
01625 break;
01626 }
01627 else
01628 *agg_comm_pre_sz_p +=
01629 my_mem_view_state_p->pre_blk_arr[i];
01630 }
01631
01632 if (has_partial == 1)
01633 {
01634 *agg_mem_next_off_p =
01635 my_mem_view_state_p->pre_disp_arr[i - 1] +
01636 partial_len;
01637 }
01638 else
01639 {
01640 *agg_mem_next_off_p =
01641 my_mem_view_state_p->pre_disp_arr[i - 1] +
01642 my_mem_view_state_p->pre_blk_arr[i - 1];
01643 }
01644
01645 *agg_comm_cur_sz_p = *agg_comm_pre_sz_p;
01646 *agg_ol_ct_p = i;
01647
01648 }
01649 else
01650 {
01651 *agg_comm_pre_sz_p = my_mem_view_state_p->pre_sz;
01652 *agg_comm_cur_sz_p = *agg_comm_pre_sz_p;
01653 *agg_ol_ct_p = my_mem_view_state_p->pre_ol_ct;
01654 *agg_mem_next_off_p =
01655 my_mem_view_state_p->pre_disp_arr[
01656 my_mem_view_state_p->pre_ol_ct - 1] +
01657 my_mem_view_state_p->pre_blk_arr[
01658 my_mem_view_state_p->pre_ol_ct - 1];
01659 }
01660 #ifdef DEBUG1
01661 fprintf(stderr, "process_pre_req: TEMP_OFF "
01662 "agg_comm_pre_sz=%Ld,agg_comm_cur_sz=%Ld,agg_ol_ct=%d\n",
01663 *agg_comm_pre_sz_p, *agg_comm_cur_sz_p, *agg_ol_ct_p);
01664 #endif
01665 assert(*agg_comm_cur_sz_p <= *agg_comm_sz_p);
01666 break;
01667 case REAL_OFF:
01668
01669
01670 for (i = 0; i < my_mem_view_state_p->pre_ol_ct; i++)
01671 {
01672 agg_disp_arr[i] = my_mem_view_state_p->pre_disp_arr[i];
01673 agg_blk_arr[i] = my_mem_view_state_p->pre_blk_arr[i];
01674
01675 if ((my_mem_view_state_p->pre_blk_arr[i] +
01676 tmp_agg_comm_pre_sz) > *agg_comm_pre_sz_p)
01677 {
01678 has_partial = 1;
01679 agg_blk_arr[i] = *agg_comm_pre_sz_p - tmp_agg_comm_pre_sz;
01680 tmp_agg_comm_pre_sz = *agg_comm_pre_sz_p;
01681 partial_disp = my_mem_view_state_p->pre_disp_arr[i] +
01682 agg_blk_arr[i];
01683 partial_len = my_mem_view_state_p->pre_blk_arr[i] -
01684 agg_blk_arr[i];
01685 i++;
01686 break;
01687 }
01688 else if ((my_mem_view_state_p->pre_blk_arr[i] +
01689 tmp_agg_comm_pre_sz) == *agg_comm_pre_sz_p)
01690 {
01691 tmp_agg_comm_pre_sz +=
01692 my_mem_view_state_p->pre_blk_arr[i];
01693 i++;
01694 break;
01695 }
01696 else
01697 tmp_agg_comm_pre_sz +=
01698 my_mem_view_state_p->pre_blk_arr[i];
01699 }
01700 *agg_mem_next_off_p = agg_disp_arr[i - 1] + agg_blk_arr[i - 1];
01701 *agg_ol_cur_ct_p = i;
01702 *agg_comm_cur_sz_p = *agg_comm_pre_sz_p;
01703
01704
01705 if ((i < my_mem_view_state_p->pre_ol_ct) || (has_partial == 1))
01706 {
01707 int remain_ol_ct =
01708 my_mem_view_state_p->pre_ol_ct - i + has_partial;
01709 MPI_Aint *new_pre_disp_arr = NULL;
01710 int *new_pre_blk_arr = NULL;
01711
01712 if ((new_pre_disp_arr = (MPI_Aint *)
01713 ADIOI_Malloc(remain_ol_ct * sizeof(MPI_Aint))) == NULL)
01714 {
01715 fprintf(stderr, "process_pre_req: malloc "
01716 "new_pre_disp_arr failed\n");
01717 return -1;
01718 }
01719 if ((new_pre_blk_arr = (int *)
01720 ADIOI_Malloc(remain_ol_ct * sizeof(int))) == NULL)
01721 {
01722 fprintf(stderr, "process_pre_req: malloc "
01723 "new_pre_blk_arr failed\n");
01724 return -1;
01725 }
01726
01727 memcpy(new_pre_disp_arr,
01728 &(my_mem_view_state_p->pre_disp_arr[i - has_partial]),
01729 remain_ol_ct * sizeof(MPI_Aint));
01730 memcpy(new_pre_blk_arr,
01731 &(my_mem_view_state_p->pre_blk_arr[i - has_partial]),
01732 remain_ol_ct * sizeof(int));
01733
01734
01735 if (has_partial == 1)
01736 {
01737
01738
01739 new_pre_disp_arr[0] = partial_disp;
01740 new_pre_blk_arr[0] = partial_len;
01741 }
01742
01743 ADIOI_Free(my_mem_view_state_p->pre_disp_arr);
01744 ADIOI_Free(my_mem_view_state_p->pre_blk_arr);
01745
01746 my_mem_view_state_p->pre_disp_arr = new_pre_disp_arr;
01747 my_mem_view_state_p->pre_blk_arr = new_pre_blk_arr;
01748 my_mem_view_state_p->pre_ol_ct = remain_ol_ct;
01749 my_mem_view_state_p->pre_sz -= *agg_comm_pre_sz_p;
01750 }
01751 else
01752 {
01753 ADIOI_Free(my_mem_view_state_p->pre_disp_arr);
01754 ADIOI_Free(my_mem_view_state_p->pre_blk_arr);
01755
01756 my_mem_view_state_p->pre_disp_arr = NULL;
01757 my_mem_view_state_p->pre_blk_arr = NULL;
01758 my_mem_view_state_p->pre_ol_ct = 0;
01759 my_mem_view_state_p->pre_sz = 0;
01760 }
01761 #ifdef DEBUG1
01762 fprintf(stderr, "process_pre_req: REAL_OFF "
01763 "agg_comm_pre_sz=%Ld,agg_comm_cur_sz=%Ld,agg_ol_ct=%d,"
01764 "agg_ol_cur_ct=%d\n",
01765 *agg_comm_pre_sz_p, *agg_comm_cur_sz_p, *agg_ol_ct_p,
01766 *agg_ol_cur_ct_p);
01767 #endif
01768 break;
01769 default:
01770 fprintf(stderr, "process_pre_req: Invalid off_type %d\n",
01771 off_type);
01772 }
01773 return 0;
01774 }
01775
01776
01777
01778
01779 int ADIOI_Build_client_req(ADIO_File fd,
01780 int agg_rank,
01781 int agg_idx,
01782 view_state *my_mem_view_state_p,
01783 view_state *agg_file_view_state_p,
01784 ADIO_Offset agg_comm_sz,
01785 MPI_Datatype *agg_comm_dtype_p)
01786 {
01787 MPI_Aint *agg_disp_arr = NULL;
01788 int *agg_blk_arr = NULL;
01789 ADIO_Offset st_reg = 0, act_reg_sz = 0, tmp_reg_sz = 0;
01790 ADIO_Offset cur_off = -1, cur_reg_max_len = -1;
01791 ADIO_Offset agg_mem_st_reg = 0, agg_mem_act_reg_sz = 0;
01792 int agg_ol_ct = 0, agg_ol_cur_ct = 0;
01793 int i = 0, agg_next_off_idx = -1;
01794 ADIO_Offset agg_mem_next_off = 0, agg_comm_cur_sz = 0, agg_comm_pre_sz = 0;
01795 ADIO_Offset *fr_st_off_arr = fd->file_realm_st_offs;
01796 MPI_Datatype *fr_type_arr = fd->file_realm_types;
01797 flatten_state *tmp_mem_state_p = NULL, *tmp_file_state_p = NULL;
01798 #ifdef DTYPE_SKIP
01799 int skip_type_ct;
01800 #endif
01801
01802 if (agg_idx < 0 || agg_idx >= fd->hints->cb_nodes)
01803 {
01804 #ifdef DEBUG1
01805 fprintf(stderr, "ADIOI_Build_client_req: agg_rank %d does not map "
01806 "to a valid node in cb_node\n", agg_rank);
01807 #endif
01808 return 0;
01809 }
01810
01811 #ifdef AGGREGATION_PROFILE
01812 MPE_Log_event (5018, 0, NULL);
01813 #endif
01814
01815 #ifdef DEBUG1
01816 fprintf(stderr, "ADIOI_Build_client_req:(agg=%d,size_req=%Ld)\n",
01817 agg_idx, agg_comm_sz);
01818 #endif
01819
01820
01821
01822
01823
01824
01825 for (i = 0; i < MAX_OFF_TYPE; i++)
01826 {
01827 switch(i)
01828 {
01829 case TEMP_OFF:
01830 tmp_mem_state_p = &(my_mem_view_state_p->tmp_state);
01831 tmp_file_state_p = &(agg_file_view_state_p->tmp_state);
01832 break;
01833 case REAL_OFF:
01834 tmp_mem_state_p = &(my_mem_view_state_p->cur_state);
01835 tmp_file_state_p = &(agg_file_view_state_p->cur_state);
01836 break;
01837 default:
01838 fprintf(stderr, "ADIOI_Build_client_pre_req: "
01839 "Invalid off type %d\n", i);
01840 }
01841
01842 agg_comm_cur_sz = 0;
01843 agg_mem_next_off = -1;
01844
01845
01846 if (my_mem_view_state_p->pre_sz > 0)
01847 {
01848 process_pre_req(fd,
01849 agg_rank,
01850 agg_idx,
01851 my_mem_view_state_p,
01852 agg_file_view_state_p,
01853 agg_comm_sz,
01854 i,
01855 agg_disp_arr,
01856 agg_blk_arr,
01857 &agg_comm_pre_sz,
01858 &agg_comm_cur_sz,
01859 &agg_comm_sz,
01860 &agg_ol_cur_ct,
01861 &agg_ol_ct,
01862 &agg_mem_next_off);
01863 }
01864
01865 while (agg_comm_cur_sz < agg_comm_sz)
01866 {
01867 find_next_off(fd, agg_file_view_state_p,
01868 fr_st_off_arr[agg_idx],
01869 &(fr_type_arr[agg_idx]),
01870 i,
01871 &cur_off,
01872 &cur_reg_max_len);
01873
01874 assert(cur_off != -1);
01875
01876
01877
01878
01879 if (cur_reg_max_len > (agg_comm_sz - agg_comm_cur_sz))
01880 {
01881 cur_reg_max_len = agg_comm_sz - agg_comm_cur_sz;
01882 }
01883 assert(cur_reg_max_len > 0);
01884
01885 view_state_add_region(
01886 cur_reg_max_len,
01887 agg_file_view_state_p,
01888 &st_reg, &act_reg_sz, i);
01889
01890 #ifdef DEBUG2
01891 fprintf(stderr, "ADIOI_Build_client_req: %s File region"
01892 " (proc=%d,off=%Ld,sz=%Ld)\n",
01893 off_type_name[i], agg_rank, cur_off, act_reg_sz);
01894 #endif
01895
01896
01897
01898
01899
01900
01901 assert(tmp_file_state_p->cur_sz - act_reg_sz >=
01902 tmp_mem_state_p->cur_sz);
01903
01904 while (tmp_file_state_p->cur_sz - act_reg_sz !=
01905 tmp_mem_state_p->cur_sz)
01906 {
01907 ADIO_Offset fill_st_reg = -1, fill_reg_sz = -1;
01908 #ifdef DTYPE_SKIP
01909 if (my_mem_view_state_p->flat_type_p->count > 1) {
01910
01911 skip_type_ct =
01912 (tmp_file_state_p->cur_sz - act_reg_sz -
01913 tmp_mem_state_p->cur_sz) /
01914 my_mem_view_state_p->type_sz;
01915 if (skip_type_ct > 0) {
01916 tmp_mem_state_p->cur_sz +=
01917 skip_type_ct * my_mem_view_state_p->type_sz;
01918 tmp_mem_state_p->abs_off +=
01919 skip_type_ct * my_mem_view_state_p->ext;
01920 if ((tmp_mem_state_p->cur_sz - act_reg_sz) ==
01921 tmp_file_state_p->cur_sz)
01922 break;
01923 }
01924 }
01925 #endif
01926 view_state_add_region(
01927 tmp_file_state_p->cur_sz -
01928 act_reg_sz - tmp_mem_state_p->cur_sz,
01929 my_mem_view_state_p,
01930 &fill_st_reg,
01931 &fill_reg_sz, i);
01932 }
01933
01934
01935
01936
01937 tmp_reg_sz = 0;
01938 while (tmp_reg_sz != act_reg_sz)
01939 {
01940 view_state_add_region(
01941 act_reg_sz - tmp_reg_sz,
01942 my_mem_view_state_p,
01943 &agg_mem_st_reg, &agg_mem_act_reg_sz,
01944 i);
01945 tmp_reg_sz += agg_mem_act_reg_sz;
01946
01947 #ifdef DEBUG2
01948 fprintf(stderr, "ADIOI_Build_client_req: %s Mem region"
01949 "(off=%Ld,sz=%Ld)\n",
01950 off_type_name[i], agg_mem_st_reg,
01951 agg_mem_act_reg_sz);
01952 #endif
01953 agg_comm_cur_sz += agg_mem_act_reg_sz;
01954 switch(i)
01955 {
01956 case TEMP_OFF:
01957
01958
01959
01960 if (agg_mem_next_off != agg_mem_st_reg)
01961 {
01962 agg_ol_ct++;
01963 }
01964 agg_mem_next_off =
01965 agg_mem_st_reg + agg_mem_act_reg_sz;
01966 break;
01967 case REAL_OFF:
01968
01969
01970
01971 agg_next_off_idx = agg_ol_cur_ct;
01972 if (agg_mem_next_off != agg_mem_st_reg)
01973 {
01974 agg_disp_arr[agg_next_off_idx] =
01975 agg_mem_st_reg;
01976 agg_blk_arr[agg_next_off_idx] =
01977 agg_mem_act_reg_sz;
01978 agg_ol_cur_ct++;
01979 }
01980 else
01981 {
01982 agg_blk_arr[agg_next_off_idx - 1]
01983 += agg_mem_act_reg_sz;
01984 }
01985 agg_mem_next_off =
01986 agg_mem_st_reg + agg_mem_act_reg_sz;
01987 break;
01988 default:
01989 fprintf(stderr, "ADIOI_Build_client_req: "
01990 "Impossible type\n");
01991 }
01992 }
01993 }
01994
01995
01996
01997 if (i == TEMP_OFF)
01998 {
01999
02000
02001 if ((agg_disp_arr = (MPI_Aint *)
02002 ADIOI_Malloc(agg_ol_ct * sizeof(MPI_Aint))) == NULL)
02003 {
02004 fprintf(stderr, "ADIOI_Build_client_req: malloc "
02005 "agg_disp_arr of size %ld failed\n",
02006 (long int)agg_ol_ct * sizeof(MPI_Aint));
02007 return -1;
02008 }
02009 if ((agg_blk_arr = (int *)
02010 ADIOI_Malloc(agg_ol_ct * sizeof(int))) == NULL)
02011 {
02012 ADIOI_Free(agg_disp_arr);
02013 fprintf(stderr, "ADIOI_Build_client_req: malloc "
02014 "agg_blk_arr of size %ld failed\n",
02015 (long int)agg_ol_ct * sizeof(int));
02016 return -1;
02017 }
02018 }
02019 }
02020
02021 assert(agg_ol_ct == agg_ol_cur_ct);
02022 #ifdef DEBUG1
02023 fprintf(stderr,
02024 "ADIOI_Build_client_req:(agg=%d,cur_ol_count=%d=ol_count=%d)\n",
02025 agg_rank, agg_ol_cur_ct, agg_ol_ct);
02026 #endif
02027
02028 #ifdef DEBUG2
02029 if (agg_ol_ct > 0)
02030 {
02031 fprintf(stderr, "ADIOI_Build_client_req: p %d (off,len) = ", agg_rank);
02032 for (i = 0; i < agg_ol_ct; i++)
02033 {
02034 fprintf(stderr, "[%d](%d,%d) ", i,
02035 agg_disp_arr[i], agg_blk_arr[i]);
02036 if (i % 5 == 0 && i != 0)
02037 fprintf(stderr, "\n");
02038 }
02039 fprintf(stderr, "\n");
02040 }
02041 #endif
02042 #ifdef DEBUG1
02043 fprintf(stderr,
02044 "ADIOI_Build_client_req:(agg=%d,pre_ol_count=%d)\n",
02045 agg_idx, my_mem_view_state_p->pre_ol_ct);
02046 #endif
02047
02048 #ifdef DEBUG2
02049 if (my_mem_view_state_p->pre_sz > 0)
02050 {
02051 fprintf(stderr, "ADIOI_Build_client_req: p %d pre(off,len) = ",
02052 agg_idx);
02053 for (i = 0; i < my_mem_view_state_p->pre_ol_ct; i++)
02054 {
02055 fprintf(stderr, "[%d](%d,%d) ", i,
02056 my_mem_view_state_p->pre_disp_arr[i],
02057 my_mem_view_state_p->pre_blk_arr[i]);
02058 if (i % 5 == 0 && i != 0)
02059 fprintf(stderr, "\n");
02060 }
02061 fprintf(stderr, "\n");
02062 }
02063 #endif
02064
02065
02066 if (agg_comm_sz > 0)
02067 {
02068 MPI_Type_hindexed(agg_ol_ct, agg_blk_arr, agg_disp_arr, MPI_BYTE,
02069 agg_comm_dtype_p);
02070 MPI_Type_commit(agg_comm_dtype_p);
02071 }
02072 else
02073 {
02074 *agg_comm_dtype_p = MPI_BYTE;
02075 }
02076
02077 ADIOI_Free(agg_blk_arr);
02078 ADIOI_Free(agg_disp_arr);
02079
02080 #ifdef AGGREGATION_PROFILE
02081 MPE_Log_event (5019, 0, NULL);
02082 #endif
02083 return 0;
02084 }
02085
02086