00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "adio.h"
00010 #include "adio_extern.h"
00011 #ifdef PROFILE
00012 #include "mpe.h"
00013 #endif
00014
00015 #undef AGG_DEBUG
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 int ADIOI_Calc_aggregator(ADIO_File fd,
00075 ADIO_Offset off,
00076 ADIO_Offset min_off,
00077 ADIO_Offset *len,
00078 ADIO_Offset fd_size,
00079 ADIO_Offset *fd_start,
00080 ADIO_Offset *fd_end)
00081 {
00082 int rank_index, rank;
00083 ADIO_Offset avail_bytes;
00084
00085 #ifdef AGG_DEBUG
00086 #if 0
00087 FPRINTF(stdout, "off = %Ld, min_off = %Ld, len = %Ld, fd_size = %Ld\n",
00088 off, min_off, *len, fd_size);
00089 #endif
00090 #endif
00091
00092
00093 rank_index = (int) ((off - min_off + fd_size)/ fd_size - 1);
00094
00095
00096
00097
00098
00099
00100
00101
00102 avail_bytes = fd_end[rank_index] + 1 - off;
00103 if (avail_bytes < *len) {
00104
00105 *len = avail_bytes;
00106 }
00107
00108
00109
00110 rank = fd->hints->ranklist[rank_index];
00111
00112 return rank;
00113 }
00114
00115 void ADIOI_Calc_file_domains(ADIO_Offset *st_offsets, ADIO_Offset
00116 *end_offsets, int nprocs, int nprocs_for_coll,
00117 ADIO_Offset *min_st_offset_ptr,
00118 ADIO_Offset **fd_start_ptr, ADIO_Offset
00119 **fd_end_ptr, ADIO_Offset *fd_size_ptr)
00120 {
00121
00122
00123
00124
00125 ADIO_Offset min_st_offset, max_end_offset, *fd_start, *fd_end, fd_size;
00126 int i;
00127
00128 #ifdef AGG_DEBUG
00129 FPRINTF(stderr, "ADIOI_Calc_file_domains: %d aggregator(s)\n",
00130 nprocs_for_coll);
00131 #endif
00132
00133
00134
00135 min_st_offset = st_offsets[0];
00136 max_end_offset = end_offsets[0];
00137
00138 for (i=1; i<nprocs; i++) {
00139 min_st_offset = ADIOI_MIN(min_st_offset, st_offsets[i]);
00140 max_end_offset = ADIOI_MAX(max_end_offset, end_offsets[i]);
00141 }
00142
00143
00144
00145
00146
00147
00148 fd_size = ((max_end_offset - min_st_offset + 1) + nprocs_for_coll -
00149 1)/nprocs_for_coll;
00150
00151
00152 *fd_start_ptr = (ADIO_Offset *)
00153 ADIOI_Malloc(nprocs_for_coll*sizeof(ADIO_Offset));
00154 *fd_end_ptr = (ADIO_Offset *)
00155 ADIOI_Malloc(nprocs_for_coll*sizeof(ADIO_Offset));
00156
00157 fd_start = *fd_start_ptr;
00158 fd_end = *fd_end_ptr;
00159
00160 fd_start[0] = min_st_offset;
00161 fd_end[0] = min_st_offset + fd_size - 1;
00162
00163 for (i=1; i<nprocs_for_coll; i++) {
00164 fd_start[i] = fd_end[i-1] + 1;
00165 fd_end[i] = fd_start[i] + fd_size - 1;
00166 }
00167
00168
00169
00170
00171
00172
00173
00174 for (i=0; i<nprocs_for_coll; i++) {
00175 if (fd_start[i] > max_end_offset)
00176 fd_start[i] = fd_end[i] = -1;
00177 if (fd_end[i] > max_end_offset)
00178 fd_end[i] = max_end_offset;
00179 }
00180
00181 *fd_size_ptr = fd_size;
00182 *min_st_offset_ptr = min_st_offset;
00183 }
00184
00185
00186
00187
00188
00189
00190 void ADIOI_Calc_my_req(ADIO_File fd, ADIO_Offset *offset_list, int *len_list,
00191 int contig_access_count, ADIO_Offset
00192 min_st_offset, ADIO_Offset *fd_start,
00193 ADIO_Offset *fd_end, ADIO_Offset fd_size,
00194 int nprocs,
00195 int *count_my_req_procs_ptr,
00196 int **count_my_req_per_proc_ptr,
00197 ADIOI_Access **my_req_ptr,
00198 int **buf_idx_ptr)
00199 {
00200 int *count_my_req_per_proc, count_my_req_procs, *buf_idx;
00201 int i, l, proc;
00202 ADIO_Offset fd_len, rem_len, curr_idx, off;
00203 ADIOI_Access *my_req;
00204
00205 *count_my_req_per_proc_ptr = (int *) ADIOI_Calloc(nprocs,sizeof(int));
00206 count_my_req_per_proc = *count_my_req_per_proc_ptr;
00207
00208
00209
00210
00211
00212 buf_idx = (int *) ADIOI_Malloc(nprocs*sizeof(int));
00213
00214
00215
00216
00217
00218
00219 for (i=0; i < nprocs; i++) buf_idx[i] = -1;
00220
00221
00222
00223
00224 for (i=0; i < contig_access_count; i++) {
00225 off = offset_list[i];
00226 fd_len = len_list[i];
00227
00228
00229
00230
00231
00232 proc = ADIOI_Calc_aggregator(fd, off, min_st_offset, &fd_len, fd_size,
00233 fd_start, fd_end);
00234 count_my_req_per_proc[proc]++;
00235
00236
00237
00238
00239
00240 rem_len = len_list[i] - fd_len;
00241
00242 while (rem_len != 0) {
00243 off += fd_len;
00244 fd_len = rem_len;
00245 proc = ADIOI_Calc_aggregator(fd, off, min_st_offset, &fd_len,
00246 fd_size, fd_start, fd_end);
00247
00248 count_my_req_per_proc[proc]++;
00249 rem_len -= fd_len;
00250 }
00251 }
00252
00253
00254
00255 *my_req_ptr = (ADIOI_Access *)
00256 ADIOI_Malloc(nprocs*sizeof(ADIOI_Access));
00257 my_req = *my_req_ptr;
00258
00259 count_my_req_procs = 0;
00260 for (i=0; i < nprocs; i++) {
00261 if (count_my_req_per_proc[i]) {
00262 my_req[i].offsets = (ADIO_Offset *)
00263 ADIOI_Malloc(count_my_req_per_proc[i] * sizeof(ADIO_Offset));
00264 my_req[i].lens = (int *)
00265 ADIOI_Malloc(count_my_req_per_proc[i] * sizeof(int));
00266 count_my_req_procs++;
00267 }
00268 my_req[i].count = 0;
00269
00270 }
00271
00272
00273 curr_idx = 0;
00274 for (i=0; i<contig_access_count; i++) {
00275 off = offset_list[i];
00276 fd_len = len_list[i];
00277 proc = ADIOI_Calc_aggregator(fd, off, min_st_offset, &fd_len, fd_size,
00278 fd_start, fd_end);
00279
00280
00281 if (buf_idx[proc] == -1) buf_idx[proc] = (int) curr_idx;
00282
00283 l = my_req[proc].count;
00284 curr_idx += (int) fd_len;
00285
00286 rem_len = len_list[i] - fd_len;
00287
00288
00289
00290
00291
00292
00293 my_req[proc].offsets[l] = off;
00294 my_req[proc].lens[l] = (int) fd_len;
00295 my_req[proc].count++;
00296
00297 while (rem_len != 0) {
00298 off += fd_len;
00299 fd_len = rem_len;
00300 proc = ADIOI_Calc_aggregator(fd, off, min_st_offset, &fd_len,
00301 fd_size, fd_start, fd_end);
00302
00303 if (buf_idx[proc] == -1) buf_idx[proc] = (int) curr_idx;
00304
00305 l = my_req[proc].count;
00306 curr_idx += fd_len;
00307 rem_len -= fd_len;
00308
00309 my_req[proc].offsets[l] = off;
00310 my_req[proc].lens[l] = (int) fd_len;
00311 my_req[proc].count++;
00312 }
00313 }
00314
00315 #ifdef AGG_DEBUG
00316 for (i=0; i<nprocs; i++) {
00317 if (count_my_req_per_proc[i] > 0) {
00318 FPRINTF(stdout, "data needed from %d (count = %d):\n", i,
00319 my_req[i].count);
00320 for (l=0; l < my_req[i].count; l++) {
00321 FPRINTF(stdout, " off[%d] = %Ld, len[%d] = %d\n", l,
00322 my_req[i].offsets[l], l, my_req[i].lens[l]);
00323 }
00324 }
00325 }
00326 #if 0
00327 for (i=0; i<nprocs; i++) {
00328 FPRINTF(stdout, "buf_idx[%d] = 0x%x\n", i, buf_idx[i]);
00329 }
00330 #endif
00331 #endif
00332
00333 *count_my_req_procs_ptr = count_my_req_procs;
00334 *buf_idx_ptr = buf_idx;
00335 }
00336
00337
00338
00339 void ADIOI_Calc_others_req(ADIO_File fd, int count_my_req_procs,
00340 int *count_my_req_per_proc,
00341 ADIOI_Access *my_req,
00342 int nprocs, int myrank,
00343 int *count_others_req_procs_ptr,
00344 ADIOI_Access **others_req_ptr)
00345 {
00346
00347
00348
00349
00350
00351
00352
00353
00354 int *count_others_req_per_proc, count_others_req_procs;
00355 int i, j;
00356 MPI_Request *send_requests, *recv_requests;
00357 MPI_Status *statuses;
00358 ADIOI_Access *others_req;
00359
00360
00361
00362 count_others_req_per_proc = (int *) ADIOI_Malloc(nprocs*sizeof(int));
00363
00364 MPI_Alltoall(count_my_req_per_proc, 1, MPI_INT,
00365 count_others_req_per_proc, 1, MPI_INT, fd->comm);
00366
00367 *others_req_ptr = (ADIOI_Access *)
00368 ADIOI_Malloc(nprocs*sizeof(ADIOI_Access));
00369 others_req = *others_req_ptr;
00370
00371 count_others_req_procs = 0;
00372 for (i=0; i<nprocs; i++) {
00373 if (count_others_req_per_proc[i]) {
00374 others_req[i].count = count_others_req_per_proc[i];
00375 others_req[i].offsets = (ADIO_Offset *)
00376 ADIOI_Malloc(count_others_req_per_proc[i]*sizeof(ADIO_Offset));
00377 others_req[i].lens = (int *)
00378 ADIOI_Malloc(count_others_req_per_proc[i]*sizeof(int));
00379 others_req[i].mem_ptrs = (MPI_Aint *)
00380 ADIOI_Malloc(count_others_req_per_proc[i]*sizeof(MPI_Aint));
00381 count_others_req_procs++;
00382 }
00383 else others_req[i].count = 0;
00384 }
00385
00386
00387
00388 send_requests = (MPI_Request *)
00389 ADIOI_Malloc(2*(count_my_req_procs+1)*sizeof(MPI_Request));
00390 recv_requests = (MPI_Request *)
00391 ADIOI_Malloc(2*(count_others_req_procs+1)*sizeof(MPI_Request));
00392
00393
00394 j = 0;
00395 for (i=0; i<nprocs; i++) {
00396 if (others_req[i].count) {
00397 MPI_Irecv(others_req[i].offsets, others_req[i].count,
00398 ADIO_OFFSET, i, i+myrank, fd->comm, &recv_requests[j]);
00399 j++;
00400 MPI_Irecv(others_req[i].lens, others_req[i].count,
00401 MPI_INT, i, i+myrank+1, fd->comm, &recv_requests[j]);
00402 j++;
00403 }
00404 }
00405
00406 j = 0;
00407 for (i=0; i < nprocs; i++) {
00408 if (my_req[i].count) {
00409 MPI_Isend(my_req[i].offsets, my_req[i].count,
00410 ADIO_OFFSET, i, i+myrank, fd->comm, &send_requests[j]);
00411 j++;
00412 MPI_Isend(my_req[i].lens, my_req[i].count,
00413 MPI_INT, i, i+myrank+1, fd->comm, &send_requests[j]);
00414 j++;
00415 }
00416 }
00417
00418 statuses = (MPI_Status *) ADIOI_Malloc((1 + 2* \
00419 ADIOI_MAX(count_my_req_procs,count_others_req_procs)) * \
00420 sizeof(MPI_Status));
00421
00422
00423 MPI_Waitall(2*count_my_req_procs, send_requests, statuses);
00424 MPI_Waitall(2*count_others_req_procs, recv_requests, statuses);
00425
00426 ADIOI_Free(send_requests);
00427 ADIOI_Free(recv_requests);
00428 ADIOI_Free(statuses);
00429 ADIOI_Free(count_others_req_per_proc);
00430
00431 *count_others_req_procs_ptr = count_others_req_procs;
00432 }