1 diff -ruN ad_lustre_orig/ad_lustre_aggregate.c ad_lustre/ad_lustre_aggregate.c
2 --- ad_lustre_orig/ad_lustre_aggregate.c 1970-01-01 08:00:00.000000000 +0800
3 +++ ad_lustre/ad_lustre_aggregate.c 2008-10-17 17:30:00.000000000 +0800
5 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
7 + * Copyright (C) 1997 University of Chicago.
8 + * See COPYRIGHT notice in top-level directory.
10 + * Copyright (C) 2007 Oak Ridge National Laboratory
12 + * Copyright (C) 2008 Sun Microsystems, Lustre group
15 +#include "ad_lustre.h"
16 +#include "adio_extern.h"
18 +void ADIOI_LUSTRE_Get_striping_info(ADIO_File fd, int ** striping_info_ptr,
21 + int *striping_info = NULL;
22 + /* get striping information:
23 + * striping_info[0]: stripe_size
24 + * striping_info[1]: stripe_count
25 + * striping_info[2]: avail_cb_nodes
27 + int stripe_size, stripe_count, CO = 1, CO_max = 1, CO_nodes, lflag;
28 + int avail_cb_nodes, divisor, nprocs_for_coll = fd->hints->cb_nodes;
29 + char *value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL + 1) * sizeof(char));
31 + /* Get hints value */
33 + MPI_Info_get(fd->info, "striping_unit", MPI_MAX_INFO_VAL, value, &lflag);
35 + stripe_size = atoi(value);
37 + /* stripe_size and stripe_count have been validated in ADIOI_LUSTRE_Open() */
38 + MPI_Info_get(fd->info, "striping_factor", MPI_MAX_INFO_VAL, value, &lflag);
40 + stripe_count = atoi(value);
42 + /* Calculate the available number of I/O clients, that is
43 + * avail_cb_nodes=min(cb_nodes, stripe_count*CO), where
47 + /* for collective read,
48 + * if "CO" clients access the same OST simultaneously,
49 + * the OST disk seek time would be much. So, to avoid this,
50 + * it might be better if 1 client only accesses 1 OST.
51 + * So, we set CO = 1 to meet the above requirement.
54 + /*XXX: maybe there are other better way for collective read */
56 + /* CO_max: the largest number of IO clients for each ost group */
57 + CO_max = (nprocs_for_coll - 1)/ stripe_count + 1;
58 + /* CO also has been validated in ADIOI_LUSTRE_Open(), >0 */
59 + MPI_Info_get(fd->info, "CO", MPI_MAX_INFO_VAL, value, &lflag);
62 + CO = ADIOI_MIN(CO_max, CO);
64 + /* Calculate how many IO clients we need */
65 + /* To avoid extent lock conflicts,
66 + * avail_cb_nodes should divide (stripe_count*CO) exactly,
67 + * so that each OST is accessed by only one or more constant clients. */
68 + avail_cb_nodes = ADIOI_MIN(nprocs_for_coll, stripe_count * CO);
69 + if (avail_cb_nodes == nprocs_for_coll) {
70 + CO_nodes = stripe_count * CO;
72 + /* find the divisor of CO_nodes */
76 + } while (CO_nodes % divisor);
77 + CO_nodes = CO_nodes / divisor;
78 + /* if stripe_count*CO is a prime number, change nothing */
79 + if ((CO_nodes <= avail_cb_nodes) && (CO_nodes != 1)) {
80 + avail_cb_nodes = CO_nodes;
83 + } while (CO_nodes != 1);
86 + *striping_info_ptr = (int *) ADIOI_Malloc(3 * sizeof(int));
87 + striping_info = *striping_info_ptr;
88 + striping_info[0] = stripe_size;
89 + striping_info[1] = stripe_count;
90 + striping_info[2] = avail_cb_nodes;
95 +int ADIOI_LUSTRE_Calc_aggregator(ADIO_File fd, ADIO_Offset off,
96 + ADIO_Offset *len, int *striping_info)
98 + int rank_index, rank;
99 + ADIO_Offset avail_bytes;
100 + int stripe_size = striping_info[0];
101 + int avail_cb_nodes = striping_info[2];
103 + /* Produce the stripe-contiguous pattern for Lustre */
104 + rank_index = (int)((off / stripe_size) % avail_cb_nodes);
106 + avail_bytes = (off / (ADIO_Offset)stripe_size + 1) *
107 + (ADIO_Offset)stripe_size - off;
108 + if (avail_bytes < *len) {
109 + /* this proc only has part of the requested contig. region */
110 + *len = avail_bytes;
112 + /* map our index to a rank */
113 + /* NOTE: FOR NOW WE DON'T HAVE A MAPPING...JUST DO 0..NPROCS_FOR_COLL */
114 + rank = fd->hints->ranklist[rank_index];
119 +void ADIOI_LUSTRE_Calc_my_req(ADIO_File fd, ADIO_Offset *offset_list,
120 + int *len_list, int contig_access_count,
121 + int *striping_info, int nprocs,
122 + int *count_my_req_procs_ptr,
123 + int **count_my_req_per_proc_ptr,
124 + ADIOI_Access ** my_req_ptr,
127 + /* Nothing different from ADIOI_Calc_my_req(), except calling
128 + * ADIOI_Lustre_Calc_aggregator() instead of the old one */
129 + int *count_my_req_per_proc, count_my_req_procs, *buf_idx;
131 + ADIO_Offset avail_len, rem_len, curr_idx, off;
132 + ADIOI_Access *my_req;
134 + *count_my_req_per_proc_ptr = (int *) ADIOI_Calloc(nprocs, sizeof(int));
135 + count_my_req_per_proc = *count_my_req_per_proc_ptr;
137 + /* buf_idx is relevant only if buftype_is_contig.
138 + * buf_idx[i] gives the index into user_buf where data received
139 + * from proc. i should be placed. This allows receives to be done
140 + * without extra buffer. This can't be done if buftype is not contig.
142 + buf_idx = (int *) ADIOI_Malloc(nprocs * sizeof(int));
143 + /* initialize buf_idx to -1 */
144 + for (i = 0; i < nprocs; i++)
147 + /* one pass just to calculate how much space to allocate for my_req;
148 + * contig_access_count was calculated way back in ADIOI_Calc_my_off_len()
150 + for (i = 0; i < contig_access_count; i++) {
151 + /* short circuit offset/len processing if len == 0
152 + * (zero-byte read/write
154 + if (len_list[i] == 0)
156 + off = offset_list[i];
157 + avail_len = len_list[i];
158 + /* we set avail_len to be the total size of the access.
159 + * then ADIOI_LUSTRE_Calc_aggregator() will modify the value to return
160 + * the amount that was available.
162 + proc = ADIOI_LUSTRE_Calc_aggregator(fd, off, &avail_len, striping_info);
163 + count_my_req_per_proc[proc]++;
164 + /* figure out how many data is remaining in the access
165 + * we'll take care of this data (if there is any)
166 + * in the while loop below.
168 + rem_len = len_list[i] - avail_len;
170 + while (rem_len != 0) {
171 + off += avail_len; /* point to first remaining byte */
172 + avail_len = rem_len; /* save remaining size, pass to calc */
173 + proc = ADIOI_LUSTRE_Calc_aggregator(fd, off, &avail_len, striping_info);
174 + count_my_req_per_proc[proc]++;
175 + rem_len -= avail_len; /* reduce remaining length by amount from fd */
179 + *my_req_ptr = (ADIOI_Access *) ADIOI_Malloc(nprocs * sizeof(ADIOI_Access));
180 + my_req = *my_req_ptr;
182 + count_my_req_procs = 0;
183 + for (i = 0; i < nprocs; i++) {
184 + if (count_my_req_per_proc[i]) {
185 + my_req[i].offsets = (ADIO_Offset *)
186 + ADIOI_Malloc(count_my_req_per_proc[i] *
187 + sizeof(ADIO_Offset));
188 + my_req[i].lens = (int *) ADIOI_Malloc(count_my_req_per_proc[i] *
190 + count_my_req_procs++;
192 + my_req[i].count = 0; /* will be incremented where needed later */
195 + /* now fill in my_req */
197 + for (i = 0; i < contig_access_count; i++) {
198 + if (len_list[i] == 0)
200 + off = offset_list[i];
201 + avail_len = len_list[i];
202 + proc = ADIOI_LUSTRE_Calc_aggregator(fd, off, &avail_len, striping_info);
204 + /* for each separate contiguous access from this process */
205 + if (buf_idx[proc] == -1)
206 + buf_idx[proc] = (int) curr_idx;
208 + l = my_req[proc].count;
209 + curr_idx += (int) avail_len; /* NOTE: Why is curr_idx an int? Fix? */
211 + rem_len = len_list[i] - avail_len;
213 + /* store the proc, offset, and len information in an array
214 + * of structures, my_req. Each structure contains the
215 + * offsets and lengths located in that process's FD,
216 + * and the associated count.
218 + my_req[proc].offsets[l] = off;
219 + my_req[proc].lens[l] = (int) avail_len;
220 + my_req[proc].count++;
222 + while (rem_len != 0) {
224 + avail_len = rem_len;
225 + proc = ADIOI_LUSTRE_Calc_aggregator(fd, off, &avail_len,
227 + if (buf_idx[proc] == -1)
228 + buf_idx[proc] = (int) curr_idx;
230 + l = my_req[proc].count;
231 + curr_idx += avail_len;
232 + rem_len -= avail_len;
234 + my_req[proc].offsets[l] = off;
235 + my_req[proc].lens[l] = (int) avail_len;
236 + my_req[proc].count++;
241 + for (i = 0; i < nprocs; i++) {
242 + if (count_my_req_per_proc[i] > 0) {
243 + FPRINTF(stdout, "data needed from %d (count = %d):\n",
244 + i, my_req[i].count);
245 + for (l = 0; l < my_req[i].count; l++) {
246 + FPRINTF(stdout, " off[%d] = %lld, len[%d] = %d\n",
247 + l, my_req[i].offsets[l], l, my_req[i].lens[l]);
253 + for (i = 0; i < nprocs; i++) {
254 + FPRINTF(stdout, "buf_idx[%d] = 0x%x\n", i, buf_idx[i]);
258 + *count_my_req_procs_ptr = count_my_req_procs;
259 + *buf_idx_ptr = buf_idx;
262 +int ADIOI_LUSTRE_Docollect(ADIO_File fd, int contig_access_count,
263 + int *len_list, int nprocs)
265 + /* If the processes are non-interleaved, we will check the req_size.
266 + * if (avg_req_size > big_req_size) {
271 + int i, docollect = 1, lflag, big_req_size = 0;
272 + ADIO_Offset req_size = 0, total_req_size;
273 + int avg_req_size, total_access_count;
274 + char *value = NULL;
276 + /* calculate total_req_size and total_access_count */
277 + for (i = 0; i < contig_access_count; i++)
278 + req_size += len_list[i];
279 + MPI_Allreduce(&req_size, &total_req_size, 1, MPI_LONG_LONG_INT, MPI_SUM,
281 + MPI_Allreduce(&contig_access_count, &total_access_count, 1, MPI_INT, MPI_SUM,
283 + /* estimate average req_size */
284 + avg_req_size = (int)(total_req_size / total_access_count);
286 + /* get hint of big_req_size */
287 + value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL + 1) * sizeof(char));
288 + MPI_Info_get(fd->info, "big_req_size", MPI_MAX_INFO_VAL, value, &lflag);
290 + big_req_size = atoi(value);
291 + /* Don't perform collective I/O if there are big requests */
292 + if ((big_req_size > 0) && (avg_req_size > big_req_size))
300 +void ADIOI_LUSTRE_Calc_others_req(ADIO_File fd, int count_my_req_procs,
301 + int *count_my_req_per_proc,
302 + ADIOI_Access * my_req,
303 + int nprocs, int myrank,
304 + ADIO_Offset start_offset,
305 + ADIO_Offset end_offset,
306 + int *striping_info,
307 + int *count_others_req_procs_ptr,
308 + ADIOI_Access ** others_req_ptr)
310 + /* what requests of other processes will be written by this process */
312 + int *count_others_req_per_proc, count_others_req_procs, proc;
313 + int i, j, lflag, samesize = 0, contiguous = 0;
314 + int avail_cb_nodes = striping_info[2];
315 + MPI_Request *send_requests, *recv_requests;
316 + MPI_Status *statuses;
317 + ADIOI_Access *others_req;
318 + char *value = NULL;
319 + ADIO_Offset min_st_offset, off, req_len, avail_len, rem_len, *all_lens;
321 + /* There are two hints, which could reduce some MPI communication overhead,
322 + * if the users knows the I/O pattern and set them correctly. */
324 + * contiguous_data: if the data are contiguous,
325 + * we don't need to do MPI_Alltoall().
326 + * same_io_size: And if the data req size is same,
327 + * we can calculate the offset directly
329 + value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL + 1) * sizeof(char));
330 + /* hint of contiguous data */
331 + MPI_Info_get(fd->info, "contiguous_data", MPI_MAX_INFO_VAL, value, &lflag);
332 + if (lflag && !strcmp(value, "yes"))
334 + /* hint of same io size */
335 + MPI_Info_get(fd->info, "same_io_size", MPI_MAX_INFO_VAL, value, &lflag);
336 + if (lflag && !strcmp(value, "yes"))
340 + *others_req_ptr = (ADIOI_Access *) ADIOI_Malloc(nprocs *
341 + sizeof(ADIOI_Access));
342 + others_req = *others_req_ptr;
344 + /* if the data are contiguous, we can calulate the offset and length
345 + * of the other requests simply, instead of MPI_Alltoall() */
347 + for (i = 0; i < nprocs; i++) {
348 + others_req[i].count = 0;
350 + req_len = end_offset - start_offset + 1;
351 + all_lens = (ADIO_Offset *) ADIOI_Malloc(nprocs * sizeof(ADIO_Offset));
353 + /* same req size ? */
354 + if (samesize == 0) {
355 + /* calculate the min_st_offset */
356 + MPI_Allreduce(&start_offset, &min_st_offset, 1, MPI_LONG_LONG,
357 + MPI_MIN, fd->comm);
358 + /* exchange request length */
359 + MPI_Allgather(&req_len, 1, ADIO_OFFSET, all_lens, 1, ADIO_OFFSET,
361 + } else { /* same request size */
362 + /* calculate the 1st request's offset */
363 + min_st_offset = start_offset - myrank * req_len;
364 + /* assign request length to all_lens[] */
365 + for (i = 0; i < nprocs; i ++)
366 + all_lens[i] = req_len;
368 + if (myrank < avail_cb_nodes) {
369 + /* This is a IO client and it will receive data from others */
370 + off = min_st_offset;
371 + /* calcaulte other_req[i].count */
372 + for (i = 0; i < nprocs; i++) {
373 + avail_len = all_lens[i];
374 + rem_len = avail_len;
375 + while (rem_len > 0) {
376 + proc = ADIOI_LUSTRE_Calc_aggregator(fd, off, &avail_len,
378 + if (proc == myrank) {
379 + others_req[i].count ++;
382 + rem_len -= avail_len;
383 + avail_len = rem_len;
386 + /* calculate offset and len for each request */
387 + off = min_st_offset;
388 + for (i = 0; i < nprocs; i++) {
389 + if (others_req[i].count) {
390 + others_req[i].offsets = (ADIO_Offset *)
391 + ADIOI_Malloc(others_req[i].count *
392 + sizeof(ADIO_Offset));
393 + others_req[i].lens = (int *)
394 + ADIOI_Malloc(others_req[i].count *
396 + others_req[i].mem_ptrs = (MPI_Aint *)
397 + ADIOI_Malloc(others_req[i].count *
401 + avail_len = all_lens[i];
402 + rem_len = avail_len;
403 + while (rem_len > 0) {
404 + proc = ADIOI_LUSTRE_Calc_aggregator(fd, off, &avail_len,
406 + if (proc == myrank) {
407 + others_req[i].offsets[j] = off;
408 + others_req[i].lens[j] = (int)avail_len;
412 + rem_len -= avail_len;
413 + avail_len = rem_len;
417 + ADIOI_Free(all_lens);
419 + /* multiple non-contiguous requests */
420 + /* first find out how much to send/recv and from/to whom */
423 + * count_others_req_procs:
424 + * number of processes whose requests will be written by
425 + * this process (including this process itself)
426 + * count_others_req_per_proc[i]:
427 + * how many separate contiguous requests of proc[i] will be
428 + * written by this process.
431 + count_others_req_per_proc = (int *) ADIOI_Malloc(nprocs * sizeof(int));
433 + MPI_Alltoall(count_my_req_per_proc, 1, MPI_INT,
434 + count_others_req_per_proc, 1, MPI_INT, fd->comm);
436 + count_others_req_procs = 0;
437 + for (i = 0; i < nprocs; i++) {
438 + if (count_others_req_per_proc[i]) {
439 + others_req[i].count = count_others_req_per_proc[i];
440 + others_req[i].offsets = (ADIO_Offset *)
441 + ADIOI_Malloc(others_req[i].count *
442 + sizeof(ADIO_Offset));
443 + others_req[i].lens = (int *)
444 + ADIOI_Malloc(others_req[i].count *
446 + others_req[i].mem_ptrs = (MPI_Aint *)
447 + ADIOI_Malloc(others_req[i].count *
449 + count_others_req_procs++;
451 + others_req[i].count = 0;
454 + /* now send the calculated offsets and lengths to respective processes */
456 + send_requests = (MPI_Request *) ADIOI_Malloc(2 * (count_my_req_procs + 1) *
457 + sizeof(MPI_Request));
458 + recv_requests = (MPI_Request *) ADIOI_Malloc(2 * (count_others_req_procs+1)*
459 + sizeof(MPI_Request));
460 + /* +1 to avoid a 0-size malloc */
463 + for (i = 0; i < nprocs; i++) {
464 + if (others_req[i].count) {
465 + MPI_Irecv(others_req[i].offsets, others_req[i].count,
466 + ADIO_OFFSET, i, i + myrank, fd->comm,
467 + &recv_requests[j]);
469 + MPI_Irecv(others_req[i].lens, others_req[i].count,
470 + MPI_INT, i, i + myrank + 1, fd->comm,
471 + &recv_requests[j]);
477 + for (i = 0; i < nprocs; i++) {
478 + if (my_req[i].count) {
479 + MPI_Isend(my_req[i].offsets, my_req[i].count,
480 + ADIO_OFFSET, i, i + myrank, fd->comm,
481 + &send_requests[j]);
483 + MPI_Isend(my_req[i].lens, my_req[i].count,
484 + MPI_INT, i, i + myrank + 1, fd->comm,
485 + &send_requests[j]);
490 + statuses = (MPI_Status *)
491 + ADIOI_Malloc((1 + 2 * ADIOI_MAX(count_my_req_procs,
492 + count_others_req_procs)) *
493 + sizeof(MPI_Status));
494 + /* +1 to avoid a 0-size malloc */
496 + MPI_Waitall(2 * count_my_req_procs, send_requests, statuses);
497 + MPI_Waitall(2 * count_others_req_procs, recv_requests, statuses);
499 + ADIOI_Free(send_requests);
500 + ADIOI_Free(recv_requests);
501 + ADIOI_Free(statuses);
502 + ADIOI_Free(count_others_req_per_proc);
504 + *count_others_req_procs_ptr = count_others_req_procs;
507 diff -ruN ad_lustre_orig/ad_lustre.c ad_lustre/ad_lustre.c
508 --- ad_lustre_orig/ad_lustre.c 2008-09-17 14:36:57.000000000 +0800
509 +++ ad_lustre/ad_lustre.c 2008-10-17 17:03:42.000000000 +0800
511 /* -*- Mode: C; c-basic-offset:4 ; -*- */
513 - * Copyright (C) 2001 University of Chicago.
515 + * Copyright (C) 2001 University of Chicago.
516 * See COPYRIGHT notice in top-level directory.
518 * Copyright (C) 2007 Oak Ridge National Laboratory
520 + * Copyright (C) 2008 Sun Microsystems, Lustre group
523 #include "ad_lustre.h"
525 ADIOI_LUSTRE_ReadContig, /* ReadContig */
526 ADIOI_LUSTRE_WriteContig, /* WriteContig */
527 ADIOI_GEN_ReadStridedColl, /* ReadStridedColl */
528 - ADIOI_GEN_WriteStridedColl, /* WriteStridedColl */
529 + ADIOI_LUSTRE_WriteStridedColl, /* WriteStridedColl */
530 ADIOI_GEN_SeekIndividual, /* SeekIndividual */
531 ADIOI_GEN_Fcntl, /* Fcntl */
532 ADIOI_LUSTRE_SetInfo, /* SetInfo */
533 ADIOI_GEN_ReadStrided, /* ReadStrided */
534 - ADIOI_GEN_WriteStrided, /* WriteStrided */
535 + ADIOI_LUSTRE_WriteStrided, /* WriteStrided */
536 ADIOI_GEN_Close, /* Close */
537 #if defined(ROMIO_HAVE_WORKING_AIO) && !defined(CRAY_XT_LUSTRE)
538 ADIOI_GEN_IreadContig, /* IreadContig */
539 diff -ruN ad_lustre_orig/ad_lustre.h ad_lustre/ad_lustre.h
540 --- ad_lustre_orig/ad_lustre.h 2008-09-17 14:36:57.000000000 +0800
541 +++ ad_lustre/ad_lustre.h 2008-10-17 17:11:11.000000000 +0800
543 /* -*- Mode: C; c-basic-offset:4 ; -*- */
545 - * Copyright (C) 1997 University of Chicago.
547 + * Copyright (C) 1997 University of Chicago.
548 * See COPYRIGHT notice in top-level directory.
550 * Copyright (C) 2007 Oak Ridge National Laboratory
552 + * Copyright (C) 2008 Sun Microsystems, Lustre group
555 #ifndef AD_UNIX_INCLUDE
558 /*#include <fcntl.h>*/
559 #include <sys/ioctl.h>
561 #include "lustre/lustre_user.h"
563 +/* copy something from lustre_user.h here */
564 +# define LOV_USER_MAGIC 0x0BD10BD0
565 +# define LL_IOC_LOV_SETSTRIPE _IOW ('f', 154, long)
566 +# define LL_IOC_LOV_GETSTRIPE _IOW ('f', 155, long)
567 +# define lov_user_ost_data lov_user_ost_data_v1
568 +struct lov_user_ost_data_v1 { /* per-stripe data structure */
569 + __u64 l_object_id; /* OST object ID */
570 + __u64 l_object_gr; /* OST object group (creating MDS number) */
571 + __u32 l_ost_gen; /* generation of this OST index */
572 + __u32 l_ost_idx; /* OST index in LOV */
573 +} __attribute__((packed));
574 +#define lov_user_md lov_user_md_v1
575 +struct lov_user_md_v1 { /* LOV EA user data (host-endian) */
576 + __u32 lmm_magic; /* magic number = LOV_USER_MAGIC_V1 */
577 + __u32 lmm_pattern; /* LOV_PATTERN_RAID0, LOV_PATTERN_RAID1 */
578 + __u64 lmm_object_id; /* LOV object ID */
579 + __u64 lmm_object_gr; /* LOV object group */
580 + __u32 lmm_stripe_size; /* size of stripe in bytes */
581 + __u16 lmm_stripe_count; /* num stripes in use for this object */
582 + __u16 lmm_stripe_offset; /* starting stripe offset in lmm_objects */
583 + struct lov_user_ost_data_v1 lmm_objects[0]; /* per-stripe data */
584 +} __attribute__((packed));
587 /*#include "adioi.h"*/
591 void ADIOI_LUSTRE_Open(ADIO_File fd, int *error_code);
592 void ADIOI_LUSTRE_Close(ADIO_File fd, int *error_code);
593 -void ADIOI_LUSTRE_ReadContig(ADIO_File fd, void *buf, int count,
594 - MPI_Datatype datatype, int file_ptr_type,
595 - ADIO_Offset offset, ADIO_Status *status, int
597 -void ADIOI_LUSTRE_WriteContig(ADIO_File fd, void *buf, int count,
598 - MPI_Datatype datatype, int file_ptr_type,
599 - ADIO_Offset offset, ADIO_Status *status, int
601 +void ADIOI_LUSTRE_ReadContig(ADIO_File fd, void *buf, int count,
602 + MPI_Datatype datatype, int file_ptr_type,
603 + ADIO_Offset offset, ADIO_Status *status,
605 +void ADIOI_LUSTRE_WriteContig(ADIO_File fd, void *buf, int count,
606 + MPI_Datatype datatype, int file_ptr_type,
607 + ADIO_Offset offset, ADIO_Status *status,
609 +void ADIOI_LUSTRE_WriteStrided(ADIO_File fd, void *buf, int count,
610 + MPI_Datatype datatype, int file_ptr_type,
611 + ADIO_Offset offset, ADIO_Status *status,
613 void ADIOI_LUSTRE_WriteStridedColl(ADIO_File fd, void *buf, int count,
614 - MPI_Datatype datatype, int file_ptr_type,
615 - ADIO_Offset offset, ADIO_Status *status, int
617 + MPI_Datatype datatype, int file_ptr_type,
618 + ADIO_Offset offset, ADIO_Status *status,
620 void ADIOI_LUSTRE_ReadStridedColl(ADIO_File fd, void *buf, int count,
621 - MPI_Datatype datatype, int file_ptr_type,
622 - ADIO_Offset offset, ADIO_Status *status, int
624 + MPI_Datatype datatype, int file_ptr_type,
625 + ADIO_Offset offset, ADIO_Status *status,
627 +void ADIOI_LUSTRE_ReadStrided(ADIO_File fd, void *buf, int count,
628 + MPI_Datatype datatype, int file_ptr_type,
629 + ADIO_Offset offset, ADIO_Status *status,
631 void ADIOI_LUSTRE_Fcntl(ADIO_File fd, int flag, ADIO_Fcntl_t *fcntl_struct,
633 void ADIOI_LUSTRE_SetInfo(ADIO_File fd, MPI_Info users_info, int *error_code);
635 #endif /* End of AD_UNIX_INCLUDE */
636 diff -ruN ad_lustre_orig/ad_lustre_hints.c ad_lustre/ad_lustre_hints.c
637 --- ad_lustre_orig/ad_lustre_hints.c 2008-09-17 14:36:57.000000000 +0800
638 +++ ad_lustre/ad_lustre_hints.c 2008-10-20 14:36:48.000000000 +0800
640 /* -*- Mode: C; c-basic-offset:4 ; -*- */
642 - * Copyright (C) 1997 University of Chicago.
644 + * Copyright (C) 1997 University of Chicago.
645 * See COPYRIGHT notice in top-level directory.
647 * Copyright (C) 2007 Oak Ridge National Laboratory
649 + * Copyright (C) 2008 Sun Microsystems, Lustre group
652 #include "ad_lustre.h"
653 @@ -11,130 +13,173 @@
655 void ADIOI_LUSTRE_SetInfo(ADIO_File fd, MPI_Info users_info, int *error_code)
657 - char *value, *value_in_fd;
658 - int flag, tmp_val[3], str_factor=-1, str_unit=0, start_iodev=-1;
659 - struct lov_user_md lum = { 0 };
660 - int err, myrank, fd_sys, perm, amode, old_mask;
661 + char *value = NULL;
662 + int flag, tmp_val, int_val, str_factor, str_unit, start_iodev;
663 + static char myname[] = "ADIOI_LUSTRE_SETINFO";
665 + *error_code = MPI_SUCCESS;
666 value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL+1)*sizeof(char));
668 if ( (fd->info) == MPI_INFO_NULL) {
669 - /* This must be part of the open call. can set striping parameters
671 + /* This must be part of the open call. can set striping parameters
673 MPI_Info_create(&(fd->info));
675 MPI_Info_set(fd->info, "direct_read", "false");
676 MPI_Info_set(fd->info, "direct_write", "false");
677 fd->direct_read = fd->direct_write = 0;
679 - /* has user specified striping or server buffering parameters
681 + /* has user specified striping or server buffering parameters
682 and do they have the same value on all processes? */
683 if (users_info != MPI_INFO_NULL) {
684 - MPI_Info_get(users_info, "striping_unit", MPI_MAX_INFO_VAL,
687 - str_unit=atoi(value);
689 - MPI_Info_get(users_info, "striping_factor", MPI_MAX_INFO_VAL,
692 - str_factor=atoi(value);
694 - MPI_Info_get(users_info, "start_iodevice", MPI_MAX_INFO_VAL,
695 + /* direct read and write */
696 + MPI_Info_get(users_info, "direct_read", MPI_MAX_INFO_VAL,
699 - start_iodev=atoi(value);
701 - MPI_Info_get(users_info, "direct_read", MPI_MAX_INFO_VAL,
703 if (flag && (!strcmp(value, "true") || !strcmp(value, "TRUE"))) {
704 MPI_Info_set(fd->info, "direct_read", "true");
708 - MPI_Info_get(users_info, "direct_write", MPI_MAX_INFO_VAL,
709 + MPI_Info_get(users_info, "direct_write", MPI_MAX_INFO_VAL,
711 if (flag && (!strcmp(value, "true") || !strcmp(value, "TRUE"))) {
712 MPI_Info_set(fd->info, "direct_write", "true");
713 fd->direct_write = 1;
716 + MPI_Info_get(users_info, "striping_unit", MPI_MAX_INFO_VAL,
718 + if (flag && (str_unit = atoi(value))) {
719 + tmp_val = str_unit;
720 + MPI_Bcast(&tmp_val, 1, MPI_INT, 0, fd->comm);
721 + if (tmp_val != str_unit) {
722 + MPIO_ERR_CREATE_CODE_INFO_NOT_SAME(myname,
728 + MPI_Info_set(fd->info, "striping_unit", value);
731 + MPI_Info_get(users_info, "striping_factor", MPI_MAX_INFO_VAL,
733 + if (flag && (str_factor = atoi(value))) {
734 + tmp_val = str_factor;
735 + MPI_Bcast(&tmp_val, 1, MPI_INT, 0, fd->comm);
736 + if (tmp_val != str_factor) {
737 + MPIO_ERR_CREATE_CODE_INFO_NOT_SAME(myname,
743 + MPI_Info_set(fd->info, "striping_factor", value);
745 + /* stripe offset */
746 + MPI_Info_get(users_info, "start_iodevice", MPI_MAX_INFO_VAL,
748 + if (flag && ((start_iodev = atoi(value)) >= 0)) {
749 + tmp_val = start_iodev;
750 + MPI_Bcast(&tmp_val, 1, MPI_INT, 0, fd->comm);
751 + if (tmp_val != start_iodev) {
752 + MPIO_ERR_CREATE_CODE_INFO_NOT_SAME(myname,
758 + MPI_Info_set(fd->info, "start_iodevice", value);
762 - MPI_Comm_rank(fd->comm, &myrank);
764 - tmp_val[0] = str_factor;
765 - tmp_val[1] = str_unit;
766 - tmp_val[2] = start_iodev;
768 + if (users_info != MPI_INFO_NULL) {
769 + /* CO: IO Clients/OST,
770 + * to keep the load balancing between clients and OSTs */
771 + MPI_Info_get(users_info, "CO", MPI_MAX_INFO_VAL, value,
773 + if (flag && (int_val = atoi(value)) > 0) {
775 + MPI_Bcast(&tmp_val, 1, MPI_INT, 0, fd->comm);
776 + if (tmp_val != int_val) {
777 + MPIO_ERR_CREATE_CODE_INFO_NOT_SAME(myname,
783 + MPI_Info_set(fd->info, "CO", value);
785 - MPI_Bcast(tmp_val, 3, MPI_INT, 0, fd->comm);
787 - if (tmp_val[0] != str_factor
788 - || tmp_val[1] != str_unit
789 - || tmp_val[2] != start_iodev) {
790 - FPRINTF(stderr, "ADIOI_LUSTRE_SetInfo: All keys"
791 - "-striping_factor:striping_unit:start_iodevice "
792 - "need to be identical across all processes\n");
793 - MPI_Abort(MPI_COMM_WORLD, 1);
794 - } else if ((str_factor > 0) || (str_unit > 0) || (start_iodev >= 0)) {
795 - /* if user has specified striping info, process 0 tries to set it */
797 - if (fd->perm == ADIO_PERM_NULL) {
798 - old_mask = umask(022);
800 - perm = old_mask ^ 0666;
802 - else perm = fd->perm;
805 - if (fd->access_mode & ADIO_CREATE)
806 - amode = amode | O_CREAT;
807 - if (fd->access_mode & ADIO_RDONLY)
808 - amode = amode | O_RDONLY;
809 - if (fd->access_mode & ADIO_WRONLY)
810 - amode = amode | O_WRONLY;
811 - if (fd->access_mode & ADIO_RDWR)
812 - amode = amode | O_RDWR;
813 - if (fd->access_mode & ADIO_EXCL)
814 - amode = amode | O_EXCL;
816 - /* we need to create file so ensure this is set */
817 - amode = amode | O_LOV_DELAY_CREATE | O_CREAT;
819 - fd_sys = open(fd->filename, amode, perm);
820 - if (fd_sys == -1) {
821 - if (errno != EEXIST)
823 - "Failure to open file %s %d %d\n",strerror(errno), amode, perm);
825 - lum.lmm_magic = LOV_USER_MAGIC;
826 - lum.lmm_pattern = 0;
827 - lum.lmm_stripe_size = str_unit;
828 - lum.lmm_stripe_count = str_factor;
829 - lum.lmm_stripe_offset = start_iodev;
831 - err = ioctl(fd_sys, LL_IOC_LOV_SETSTRIPE, &lum);
832 - if (err == -1 && errno != EEXIST) {
833 - fprintf(stderr, "Failure to set stripe info %s \n", strerror(errno));
837 - } /* End of striping parameters validation */
839 + * if the req size is bigger than this,
840 + * collective IO may not be performed.
842 + MPI_Info_get(users_info, "big_req_size", MPI_MAX_INFO_VAL, value,
844 + if (flag && (int_val = atoi(value)) > 0) {
846 + MPI_Bcast(&tmp_val, 1, MPI_INT, 0, fd->comm);
847 + if (tmp_val != int_val) {
848 + MPIO_ERR_CREATE_CODE_INFO_NOT_SAME(myname,
854 + MPI_Info_set(fd->info, "big_req_size", value);
856 + /* ds_in_coll: disable data sieving in collective IO */
857 + MPI_Info_get(users_info, "ds_in_coll", MPI_MAX_INFO_VAL,
859 + if (flag && (!strcmp(value, "enable") ||
860 + !strcmp(value, "ENABLE"))) {
861 + tmp_val = int_val = 1;
862 + MPI_Bcast(&tmp_val, 1, MPI_INT, 0, fd->comm);
863 + if (tmp_val != int_val) {
864 + MPIO_ERR_CREATE_CODE_INFO_NOT_SAME(myname,
870 + MPI_Info_set(fd->info, "ds_in_coll", "enable");
872 + /* contiguous_data: whether the data are contiguous */
873 + MPI_Info_get(users_info, "contiguous_data", MPI_MAX_INFO_VAL,
875 + if (flag && (!strcmp(value, "yes") ||
876 + !strcmp(value, "YES"))) {
877 + tmp_val = int_val = 1;
878 + MPI_Bcast(&tmp_val, 1, MPI_INT, 0, fd->comm);
879 + if (tmp_val != int_val) {
880 + MPIO_ERR_CREATE_CODE_INFO_NOT_SAME(myname,
886 + MPI_Info_set(fd->info, "contiguous_data", "yes");
888 + /* same_io_size: whether the req size is same */
889 + MPI_Info_get(users_info, "same_io_size", MPI_MAX_INFO_VAL,
891 + if (flag && (!strcmp(value, "yes") ||
892 + !strcmp(value, "YES"))) {
893 + tmp_val = int_val = 1;
894 + MPI_Bcast(&tmp_val, 1, MPI_INT, 0, fd->comm);
895 + if (tmp_val != int_val) {
896 + MPIO_ERR_CREATE_CODE_INFO_NOT_SAME(myname,
902 + MPI_Info_set(fd->info, "same_io_size", "yes");
905 - MPI_Barrier(fd->comm);
906 - /* set the values for collective I/O and data sieving parameters */
907 - ADIOI_GEN_SetInfo(fd, users_info, error_code);
909 - /* The file has been opened previously and fd->fd_sys is a valid
910 - file descriptor. cannot set striping parameters now. */
912 - /* set the values for collective I/O and data sieving parameters */
913 - ADIOI_GEN_SetInfo(fd, users_info, error_code);
916 - if (ADIOI_Direct_read) fd->direct_read = 1;
917 - if (ADIOI_Direct_write) fd->direct_write = 1;
920 + /* set the values for collective I/O and data sieving parameters */
921 + ADIOI_GEN_SetInfo(fd, users_info, error_code);
923 - *error_code = MPI_SUCCESS;
924 + if (ADIOI_Direct_read) fd->direct_read = 1;
925 + if (ADIOI_Direct_write) fd->direct_write = 1;
927 diff -ruN ad_lustre_orig/ad_lustre_open.c ad_lustre/ad_lustre_open.c
928 --- ad_lustre_orig/ad_lustre_open.c 2008-09-17 14:36:57.000000000 +0800
929 +++ ad_lustre/ad_lustre_open.c 2008-09-17 18:55:50.000000000 +0800
931 /* -*- Mode: C; c-basic-offset:4 ; -*- */
933 - * Copyright (C) 1997 University of Chicago.
935 + * Copyright (C) 1997 University of Chicago.
936 * See COPYRIGHT notice in top-level directory.
938 * Copyright (C) 2007 Oak Ridge National Laboratory
940 + * Copyright (C) 2008 Sun Microsystems, Lustre group
943 #include "ad_lustre.h"
945 void ADIOI_LUSTRE_Open(ADIO_File fd, int *error_code)
947 - int perm, old_mask, amode, amode_direct;
948 + int perm, old_mask, amode = 0, amode_direct = 0, flag = 0, err, myrank;
949 + int stripe_size = 0, stripe_count = 0, stripe_offset = -1;
950 struct lov_user_md lum = { 0 };
952 + char *value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL + 1) * sizeof(char));
954 #if defined(MPICH2) || !defined(PRINT_ERR_MSG)
955 static char myname[] = "ADIOI_LUSTRE_OPEN";
957 old_mask = umask(022);
959 perm = old_mask ^ 0666;
961 - else perm = fd->perm;
966 - if (fd->access_mode & ADIO_CREATE)
967 + if (fd->access_mode & ADIO_CREATE) {
968 amode = amode | O_CREAT;
969 + /* Check striping info
970 + * if already set by SetInfo(), set them to lum; otherwise, set by lum
972 + MPI_Info_get(fd->info, "striping_unit", MPI_MAX_INFO_VAL, value,
975 + stripe_size = atoi(value);
977 + MPI_Info_get(fd->info, "striping_factor", MPI_MAX_INFO_VAL, value,
980 + stripe_count = atoi(value);
982 + MPI_Info_get(fd->info, "start_iodevice", MPI_MAX_INFO_VAL, value,
985 + stripe_offset = atoi(value);
987 + /* if user has specified striping info,
988 + * process 0 will try to check and set it.
990 + if ((stripe_size > 0) || (stripe_count > 0) || (stripe_offset >= 0)) {
991 + MPI_Comm_rank(fd->comm, &myrank);
993 + int fd_sys = open(fd->filename, amode, perm);
994 + if (fd_sys == -1) {
995 + if (errno != EEXIST)
996 + FPRINTF(stderr, "Failure to open file %s %d %d\n",
997 + strerror(errno), amode, perm);
999 + lum.lmm_magic = LOV_USER_MAGIC;
1000 + lum.lmm_pattern = 1;
1001 + lum.lmm_stripe_size = stripe_size;
1002 + lum.lmm_stripe_count = stripe_count;
1003 + lum.lmm_stripe_offset = stripe_offset;
1005 + if (ioctl(fd_sys, LL_IOC_LOV_SETSTRIPE, &lum))
1007 + "Failure to set striping info to Lustre!\n");
1011 + MPI_Barrier(fd->comm);
1015 if (fd->access_mode & ADIO_RDONLY)
1016 amode = amode | O_RDONLY;
1017 if (fd->access_mode & ADIO_WRONLY)
1019 fd->fd_sys = open(fd->filename, amode|O_CREAT, perm);
1021 if (fd->fd_sys != -1) {
1024 - value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL+1)*sizeof(char));
1026 /* get file striping information and set it in info */
1027 - lum.lmm_magic = LOV_USER_MAGIC;
1028 - err = ioctl(fd->fd_sys, LL_IOC_LOV_GETSTRIPE, (void *) &lum);
1031 - sprintf(value, "%d", lum.lmm_stripe_size);
1032 - MPI_Info_set(fd->info, "striping_unit", value);
1034 - sprintf(value, "%d", lum.lmm_stripe_count);
1035 - MPI_Info_set(fd->info, "striping_factor", value);
1037 - sprintf(value, "%d", lum.lmm_stripe_offset);
1038 - MPI_Info_set(fd->info, "start_iodevice", value);
1040 - ADIOI_Free(value);
1041 + lum.lmm_magic = LOV_USER_MAGIC;
1042 + err = ioctl(fd->fd_sys, LL_IOC_LOV_GETSTRIPE, (void *) &lum);
1045 + if (lum.lmm_stripe_size && lum.lmm_stripe_count &&
1046 + (lum.lmm_stripe_offset >= 0)) {
1047 + sprintf(value, "%d", lum.lmm_stripe_size);
1048 + MPI_Info_set(fd->info, "striping_unit", value);
1050 + sprintf(value, "%d", lum.lmm_stripe_count);
1051 + MPI_Info_set(fd->info, "striping_factor", value);
1053 + sprintf(value, "%d", lum.lmm_stripe_offset);
1054 + MPI_Info_set(fd->info, "start_iodevice", value);
1056 + FPRINTF(stderr, "Striping info is invalid!\n");
1057 + ADIOI_Free(value);
1058 + MPI_Abort(MPI_COMM_WORLD, 1);
1061 + FPRINTF(stderr, "Failed to get striping info from Lustre!\n");
1062 + ADIOI_Free(value);
1063 + MPI_Abort(MPI_COMM_WORLD, 1);
1065 if (fd->access_mode & ADIO_APPEND)
1066 fd->fp_ind = fd->fp_sys_posn = lseek(fd->fd_sys, 0, SEEK_END);
1070 if ((fd->fd_sys != -1) && (fd->access_mode & ADIO_APPEND))
1071 - fd->fp_ind = fd->fp_sys_posn = lseek(fd->fd_sys, 0, SEEK_END);
1072 + fd->fp_ind = fd->fp_sys_posn = lseek(fd->fd_sys, 0, SEEK_END);
1075 if (fd->direct_write || fd->direct_read) {
1076 @@ -81,20 +133,22 @@
1079 /* --BEGIN ERROR HANDLING-- */
1080 - if (fd->fd_sys == -1 || ((fd->fd_direct == -1) &&
1081 - (fd->direct_write || fd->direct_read))) {
1082 + if (fd->fd_sys == -1 || ((fd->fd_direct == -1) &&
1083 + (fd->direct_write || fd->direct_read))) {
1084 if (errno == ENAMETOOLONG)
1085 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
1086 - MPIR_ERR_RECOVERABLE, myname,
1087 - __LINE__, MPI_ERR_BAD_FILE,
1088 + MPIR_ERR_RECOVERABLE,
1092 "**filenamelong %s %d",
1094 strlen(fd->filename));
1095 else if (errno == ENOENT)
1096 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
1097 - MPIR_ERR_RECOVERABLE, myname,
1098 - __LINE__, MPI_ERR_NO_SUCH_FILE,
1099 + MPIR_ERR_RECOVERABLE,
1101 + MPI_ERR_NO_SUCH_FILE,
1105 @@ -108,27 +162,30 @@
1107 else if (errno == EACCES) {
1108 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
1109 - MPIR_ERR_RECOVERABLE, myname,
1110 - __LINE__, MPI_ERR_ACCESS,
1111 + MPIR_ERR_RECOVERABLE,
1115 - "**fileaccess %s",
1118 - else if (errno == EROFS) {
1119 + "**fileaccess %s",
1121 + } else if (errno == EROFS) {
1122 /* Read only file or file system and write access requested */
1123 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
1124 - MPIR_ERR_RECOVERABLE, myname,
1125 - __LINE__, MPI_ERR_READ_ONLY,
1126 - "**ioneedrd", 0 );
1129 + MPIR_ERR_RECOVERABLE,
1131 + MPI_ERR_READ_ONLY,
1134 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
1135 - MPIR_ERR_RECOVERABLE, myname,
1136 - __LINE__, MPI_ERR_IO, "**io",
1137 + MPIR_ERR_RECOVERABLE,
1139 + MPI_ERR_IO, "**io",
1140 "**io %s", strerror(errno));
1144 /* --END ERROR HANDLING-- */
1145 - else *error_code = MPI_SUCCESS;
1146 + *error_code = MPI_SUCCESS;
1149 + ADIOI_Free(value);
1151 diff -ruN ad_lustre_orig/ad_lustre_rwcontig.c ad_lustre/ad_lustre_rwcontig.c
1152 --- ad_lustre_orig/ad_lustre_rwcontig.c 2008-09-17 14:36:57.000000000 +0800
1153 +++ ad_lustre/ad_lustre_rwcontig.c 2008-10-15 22:44:35.000000000 +0800
1155 /* -*- Mode: C; c-basic-offset:4 ; -*- */
1157 - * Copyright (C) 1997 University of Chicago.
1159 + * Copyright (C) 1997 University of Chicago.
1160 * See COPYRIGHT notice in top-level directory.
1162 * Copyright (C) 2007 Oak Ridge National Laboratory
1164 + * Copyright (C) 2008 Sun Microsystems, Lustre group
1167 #define _XOPEN_SOURCE 600
1168 diff -ruN ad_lustre_orig/ad_lustre_wrcoll.c ad_lustre/ad_lustre_wrcoll.c
1169 --- ad_lustre_orig/ad_lustre_wrcoll.c 1970-01-01 08:00:00.000000000 +0800
1170 +++ ad_lustre/ad_lustre_wrcoll.c 2008-10-17 16:34:36.000000000 +0800
1172 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
1174 + * Copyright (C) 1997 University of Chicago.
1175 + * See COPYRIGHT notice in top-level directory.
1177 + * Copyright (C) 2007 Oak Ridge National Laboratory
1179 + * Copyright (C) 2008 Sun Microsystems, Lustre group
1182 +#include "ad_lustre.h"
1183 +#include "adio_extern.h"
1185 +/* prototypes of functions used for collective writes only. */
1186 +static void ADIOI_LUSTRE_Exch_and_write(ADIO_File fd, void *buf,
1187 + MPI_Datatype datatype, int nprocs,
1189 + ADIOI_Access *others_req,
1190 + ADIOI_Access *my_req,
1191 + ADIO_Offset *offset_list,
1193 + int contig_access_count,
1194 + int * striping_info,
1195 + int *buf_idx, int *error_code);
1196 +static void ADIOI_LUSTRE_Fill_send_buffer(ADIO_File fd, void *buf,
1197 + ADIOI_Flatlist_node * flat_buf,
1199 + ADIO_Offset * offset_list,
1200 + int *len_list, int *send_size,
1201 + MPI_Request * requests,
1202 + int *sent_to_proc, int nprocs,
1203 + int myrank, int contig_access_count,
1204 + int * striping_info,
1205 + int *send_buf_idx,
1206 + int *curr_to_proc,
1207 + int *done_to_proc, int iter,
1208 + MPI_Aint buftype_extent);
1209 +static void ADIOI_LUSTRE_W_Exchange_data(ADIO_File fd, void *buf,
1211 + ADIOI_Flatlist_node * flat_buf,
1212 + ADIO_Offset * offset_list,
1213 + int *len_list, int *send_size,
1214 + int *recv_size, ADIO_Offset off,
1215 + int size, int *count,
1216 + int *start_pos, int *partial_recv,
1217 + int *sent_to_proc, int nprocs,
1218 + int myrank, int buftype_is_contig,
1219 + int contig_access_count,
1220 + int * striping_info,
1221 + ADIOI_Access * others_req,
1222 + int *send_buf_idx,
1223 + int *curr_to_proc,
1224 + int *done_to_proc, int *hole,
1225 + int iter, MPI_Aint buftype_extent,
1226 + int *buf_idx, int *error_code);
1227 +void ADIOI_Heap_merge(ADIOI_Access * others_req, int *count,
1228 + ADIO_Offset * srt_off, int *srt_len, int *start_pos,
1229 + int nprocs, int nprocs_recv, int total_elements);
1231 +void ADIOI_LUSTRE_WriteStridedColl(ADIO_File fd, void *buf, int count,
1232 + MPI_Datatype datatype,
1233 + int file_ptr_type, ADIO_Offset offset,
1234 + ADIO_Status * status, int *error_code)
1236 + ADIOI_Access *my_req;
1237 + /* array of nprocs access structures, one for each other process has
1238 + this process's request */
1240 + ADIOI_Access *others_req;
1241 + /* array of nprocs access structures, one for each other process
1242 + whose request is written by this process. */
1244 + int i, filetype_is_contig, nprocs, myrank, do_collect = 0;
1245 + int contig_access_count = 0, buftype_is_contig, interleave_count = 0;
1246 + int *count_my_req_per_proc, count_my_req_procs, count_others_req_procs;
1247 + ADIO_Offset orig_fp, start_offset, end_offset, off;
1248 + ADIO_Offset *offset_list = NULL, *st_offsets = NULL, *end_offsets = NULL;
1249 + int *buf_idx = NULL, *len_list = NULL, *striping_info = NULL;
1250 + int old_error, tmp_error;
1252 + MPI_Comm_size(fd->comm, &nprocs);
1253 + MPI_Comm_rank(fd->comm, &myrank);
1255 + orig_fp = fd->fp_ind;
1257 + /* IO patten identification if cb_write isn't disabled */
1258 + if (fd->hints->cb_write != ADIOI_HINT_DISABLE) {
1259 + /* For this process's request, calculate the list of offsets and
1260 + lengths in the file and determine the start and end offsets. */
1261 + ADIOI_Calc_my_off_len(fd, count, datatype, file_ptr_type, offset,
1262 + &offset_list, &len_list, &start_offset,
1263 + &end_offset, &contig_access_count);
1265 + /* each process communicates its start and end offsets to other
1266 + processes. The result is an array each of start and end offsets stored
1267 + in order of process rank. */
1268 + st_offsets = (ADIO_Offset *) ADIOI_Malloc(nprocs * sizeof(ADIO_Offset));
1269 + end_offsets = (ADIO_Offset *) ADIOI_Malloc(nprocs * sizeof(ADIO_Offset));
1270 + MPI_Allgather(&start_offset, 1, ADIO_OFFSET, st_offsets, 1,
1271 + ADIO_OFFSET, fd->comm);
1272 + MPI_Allgather(&end_offset, 1, ADIO_OFFSET, end_offsets, 1,
1273 + ADIO_OFFSET, fd->comm);
1274 + /* are the accesses of different processes interleaved? */
1275 + for (i = 1; i < nprocs; i++)
1276 + if ((st_offsets[i] < end_offsets[i-1]) &&
1277 + (st_offsets[i] <= end_offsets[i]))
1278 + interleave_count++;
1279 + /* This is a rudimentary check for interleaving, but should suffice
1280 + for the moment. */
1282 + /* Two typical access patterns can benefit from collective write.
1283 + * 1) the processes are interleaved, and
1284 + * 2) the req size is small.
1286 + if (interleave_count > 0) {
1289 + do_collect = ADIOI_LUSTRE_Docollect(fd, contig_access_count,
1290 + len_list, nprocs);
1293 + ADIOI_Datatype_iscontig(datatype, &buftype_is_contig);
1295 + /* Decide if collective I/O should be done */
1296 + if ((!do_collect && fd->hints->cb_write == ADIOI_HINT_AUTO) ||
1297 + fd->hints->cb_write == ADIOI_HINT_DISABLE) {
1299 + int filerange_is_contig = 0;
1301 + /* use independent accesses */
1302 + if (fd->hints->cb_write != ADIOI_HINT_DISABLE) {
1303 + ADIOI_Free(offset_list);
1304 + ADIOI_Free(len_list);
1305 + ADIOI_Free(st_offsets);
1306 + ADIOI_Free(end_offsets);
1309 + fd->fp_ind = orig_fp;
1310 + ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
1311 + if (buftype_is_contig && filetype_is_contig) {
1312 + if (file_ptr_type == ADIO_EXPLICIT_OFFSET) {
1313 + off = fd->disp + (fd->etype_size) * offset;
1314 + ADIO_WriteContig(fd, buf, count, datatype,
1315 + ADIO_EXPLICIT_OFFSET,
1316 + off, status, error_code);
1318 + ADIO_WriteContig(fd, buf, count, datatype, ADIO_INDIVIDUAL,
1319 + 0, status, error_code);
1321 + ADIO_WriteStrided(fd, buf, count, datatype, file_ptr_type,
1322 + offset, status, error_code);
1327 + /* Get Lustre hints information */
1328 + ADIOI_LUSTRE_Get_striping_info(fd, &striping_info, 1);
1329 + /* calculate what portions of the access requests of this process are
1330 + * located in which process
1332 + ADIOI_LUSTRE_Calc_my_req(fd, offset_list, len_list, contig_access_count,
1333 + striping_info, nprocs, &count_my_req_procs,
1334 + &count_my_req_per_proc, &my_req, &buf_idx);
1335 + /* calculate what process's requests will be written by this process */
1336 + ADIOI_LUSTRE_Calc_others_req(fd, count_my_req_procs,
1337 + count_my_req_per_proc,
1338 + my_req, nprocs, myrank,
1339 + start_offset, end_offset, striping_info,
1340 + &count_others_req_procs, &others_req);
1341 + ADIOI_Free(count_my_req_per_proc);
1343 + /* exchange data and write in sizes of no more than stripe_size. */
1344 + ADIOI_LUSTRE_Exch_and_write(fd, buf, datatype, nprocs, myrank,
1345 + others_req, my_req,
1346 + offset_list, len_list, contig_access_count,
1347 + striping_info, buf_idx, error_code);
1349 + old_error = *error_code;
1350 + if (*error_code != MPI_SUCCESS)
1351 + *error_code = MPI_ERR_IO;
1353 + /* optimization: if only one process performing i/o, we can perform
1354 + * a less-expensive Bcast */
1355 +#ifdef ADIOI_MPE_LOGGING
1356 + MPE_Log_event(ADIOI_MPE_postwrite_a, 0, NULL);
1358 + if (fd->hints->cb_nodes == 1)
1359 + MPI_Bcast(error_code, 1, MPI_INT,
1360 + fd->hints->ranklist[0], fd->comm);
1362 + tmp_error = *error_code;
1363 + MPI_Allreduce(&tmp_error, error_code, 1, MPI_INT,
1364 + MPI_MAX, fd->comm);
1366 +#ifdef ADIOI_MPE_LOGGING
1367 + MPE_Log_event(ADIOI_MPE_postwrite_b, 0, NULL);
1370 + if ((old_error != MPI_SUCCESS) && (old_error != MPI_ERR_IO))
1371 + *error_code = old_error;
1374 + if (!buftype_is_contig)
1375 + ADIOI_Delete_flattened(datatype);
1377 + /* free all memory allocated for collective I/O */
1378 + /* free others_req */
1379 + for (i = 0; i < nprocs; i++) {
1380 + if (others_req[i].count) {
1381 + ADIOI_Free(others_req[i].offsets);
1382 + ADIOI_Free(others_req[i].lens);
1383 + ADIOI_Free(others_req[i].mem_ptrs);
1386 + ADIOI_Free(others_req);
1387 + /* free my_req here */
1388 + for (i = 0; i < nprocs; i++) {
1389 + if (my_req[i].count) {
1390 + ADIOI_Free(my_req[i].offsets);
1391 + ADIOI_Free(my_req[i].lens);
1394 + ADIOI_Free(my_req);
1395 + ADIOI_Free(buf_idx);
1396 + ADIOI_Free(offset_list);
1397 + ADIOI_Free(len_list);
1398 + ADIOI_Free(st_offsets);
1399 + ADIOI_Free(end_offsets);
1400 + ADIOI_Free(striping_info);
1402 +#ifdef HAVE_STATUS_SET_BYTES
1404 + int bufsize, size;
1405 + /* Don't set status if it isn't needed */
1406 + MPI_Type_size(datatype, &size);
1407 + bufsize = size * count;
1408 + MPIR_Status_set_bytes(status, datatype, bufsize);
1410 + /* This is a temporary way of filling in status. The right way is to
1411 + * keep track of how much data was actually written during collective I/O.
1415 + fd->fp_sys_posn = -1; /* set it to null. */
1418 +static void ADIOI_LUSTRE_Exch_and_write(ADIO_File fd, void *buf,
1419 + MPI_Datatype datatype, int nprocs,
1420 + int myrank, ADIOI_Access *others_req,
1421 + ADIOI_Access *my_req,
1422 + ADIO_Offset *offset_list,
1423 + int *len_list, int contig_access_count,
1424 + int *striping_info, int *buf_idx,
1427 + int hole, i, j, m, flag, ntimes = 1 , max_ntimes, buftype_is_contig;
1428 + ADIO_Offset st_loc = -1, end_loc = -1, min_st_loc, max_end_loc;
1429 + ADIO_Offset off, req_off, send_off, iter_st_off, *off_list;
1430 + ADIO_Offset max_size, step_size = 0;
1431 + int real_size, req_len, send_len;
1432 + int *recv_curr_offlen_ptr, *recv_count, *recv_size;
1433 + int *send_curr_offlen_ptr, *send_size;
1434 + int *partial_recv, *sent_to_proc, *recv_start_pos;
1435 + int *send_buf_idx, *curr_to_proc, *done_to_proc;
1436 + char *write_buf = NULL, *value;
1437 + MPI_Status status;
1438 + ADIOI_Flatlist_node *flat_buf = NULL;
1439 + MPI_Aint buftype_extent;
1440 + int stripe_size = striping_info[0], avail_cb_nodes = striping_info[2];
1441 + int lflag, data_sieving = 0;
1443 + *error_code = MPI_SUCCESS; /* changed below if error */
1445 + /* calculate the number of writes of stripe size to be done.
1446 + * That gives the no. of communication phases as well.
1448 + * Because we redistribute data in stripe-contiguous pattern for Lustre,
1449 + * each process has the same no. of communication phases.
1452 + for (i = 0; i < nprocs; i++) {
1453 + if (others_req[i].count) {
1454 + st_loc = others_req[i].offsets[0];
1455 + end_loc = others_req[i].offsets[0];
1459 + for (i = 0; i < nprocs; i++) {
1460 + for (j = 0; j < others_req[i].count; j++) {
1461 + st_loc = ADIOI_MIN(st_loc, others_req[i].offsets[j]);
1462 + end_loc = ADIOI_MAX(end_loc, (others_req[i].offsets[j] +
1463 + others_req[i].lens[j] - 1));
1466 + /* this process does no writing. */
1467 + if ((st_loc == -1) && (end_loc == -1))
1469 + MPI_Allreduce(&end_loc, &max_end_loc, 1, MPI_LONG_LONG_INT, MPI_MAX, fd->comm);
1470 + /* avoid min_st_loc be -1 */
1472 + st_loc = max_end_loc;
1473 + MPI_Allreduce(&st_loc, &min_st_loc, 1, MPI_LONG_LONG_INT, MPI_MIN, fd->comm);
1474 + /* align downward */
1475 + min_st_loc -= min_st_loc % (ADIO_Offset)stripe_size;
1477 + /* Each time, only avail_cb_nodes number of IO clients perform IO,
1478 + * so, step_size=avail_cb_nodes*stripe_size IO will be performed at most,
1479 + * and ntimes=whole_file_portion/step_size
1481 + step_size = (ADIO_Offset) avail_cb_nodes * stripe_size;
1482 + max_ntimes = (int)((max_end_loc - min_st_loc) / step_size + 1);
1484 + write_buf = (char *) ADIOI_Malloc(stripe_size);
1486 + /* calculate the start offset for each iteration */
1487 + off_list = (ADIO_Offset *) ADIOI_Malloc(max_ntimes * sizeof(ADIO_Offset));
1488 + for (m = 0; m < max_ntimes; m ++)
1489 + off_list[m] = max_end_loc;
1490 + for (i = 0; i < nprocs; i++) {
1491 + for (j = 0; j < others_req[i].count; j ++) {
1492 + req_off = others_req[i].offsets[j];
1493 + m = (int)((req_off - min_st_loc) / step_size);
1494 + off_list[m] = ADIOI_MIN(off_list[m], req_off);
1498 + recv_curr_offlen_ptr = (int *) ADIOI_Calloc(nprocs, sizeof(int));
1499 + send_curr_offlen_ptr = (int *) ADIOI_Calloc(nprocs, sizeof(int));
1500 + /* their use is explained below. calloc initializes to 0. */
1502 + recv_count = (int *) ADIOI_Malloc(nprocs * sizeof(int));
1503 + /* to store count of how many off-len pairs per proc are satisfied
1504 + in an iteration. */
1506 + send_size = (int *) ADIOI_Malloc(nprocs * sizeof(int));
1507 + /* total size of data to be sent to each proc. in an iteration.
1508 + Of size nprocs so that I can use MPI_Alltoall later. */
1510 + recv_size = (int *) ADIOI_Malloc(nprocs * sizeof(int));
1511 + /* total size of data to be recd. from each proc. in an iteration. */
1513 + sent_to_proc = (int *) ADIOI_Calloc(nprocs, sizeof(int));
1514 + /* amount of data sent to each proc so far. Used in
1515 + ADIOI_Fill_send_buffer. initialized to 0 here. */
1517 + send_buf_idx = (int *) ADIOI_Malloc(nprocs * sizeof(int));
1518 + curr_to_proc = (int *) ADIOI_Malloc(nprocs * sizeof(int));
1519 + done_to_proc = (int *) ADIOI_Malloc(nprocs * sizeof(int));
1520 + /* Above three are used in ADIOI_Fill_send_buffer */
1522 + recv_start_pos = (int *) ADIOI_Malloc(nprocs * sizeof(int));
1523 + /* used to store the starting value of recv_curr_offlen_ptr[i] in
1526 + ADIOI_Datatype_iscontig(datatype, &buftype_is_contig);
1527 + if (!buftype_is_contig) {
1528 + ADIOI_Flatten_datatype(datatype);
1529 + flat_buf = ADIOI_Flatlist;
1530 + while (flat_buf->type != datatype)
1531 + flat_buf = flat_buf->next;
1533 + MPI_Type_extent(datatype, &buftype_extent);
1535 + iter_st_off = min_st_loc;
1537 + /* Although we have recognized the data according to OST index,
1538 + * a read-modify-write will be done if there is a hole between the data.
1539 + * For example: if blocksize=60, xfersize=30 and stripe_size=100,
1540 + * then rank0 will collect data [0, 30] and [60, 90] then write. There
1541 + * is a hole in [30, 60], which will cause a read-modify-write in [0, 90].
1543 + * To reduce its impact on the performance, we disable data sieving
1544 + * by default, unless the hint "ds_in_coll" is enabled.
1546 + /* check the hint for data sieving */
1547 + value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL + 1) * sizeof(char));
1548 + MPI_Info_get(fd->info, "ds_in_coll", MPI_MAX_INFO_VAL, value, &lflag);
1549 + if (lflag && !strcmp(value, "enable"))
1551 + ADIOI_Free(value);
1553 + for (m = 0; m < max_ntimes; m++) {
1554 + /* go through all others_req and my_req to check which will be received
1555 + * and sent in this iteration.
1558 + /* Note that MPI guarantees that displacements in filetypes are in
1559 + monotonically nondecreasing order and that, for writes, the
1560 + filetypes cannot specify overlapping regions in the file. This
1561 + simplifies implementation a bit compared to reads. */
1564 + off = start offset in the file for the data to be written in
1566 + iter_st_off = start offset of this iteration
1567 + real_size = size of data written (bytes) corresponding to off
1568 + max_size = possible maximum size of data written in this iteration
1569 + req_off = offset in the file for a particular contiguous request minus
1570 + what was satisfied in previous iteration
1571 + send_off = offset the request needed by other processes in this iteration
1572 + req_len = size corresponding to req_off
1573 + send_len = size corresponding to send_off
1576 + /* first calculate what should be communicated */
1577 + for (i = 0; i < nprocs; i++)
1578 + recv_count[i] = recv_size[i] = send_size[i] = 0;
1580 + off = off_list[m];
1581 + max_size = ADIOI_MIN(step_size, max_end_loc - iter_st_off + 1);
1582 + real_size = (int) ADIOI_MIN((off / stripe_size + 1) * stripe_size - off,
1583 + end_loc - off + 1);
1585 + for (i = 0; i < nprocs; i++) {
1586 + if (my_req[i].count) {
1587 + for (j = send_curr_offlen_ptr[i]; j < my_req[i].count; j++) {
1588 + send_off = my_req[i].offsets[j];
1589 + send_len = my_req[i].lens[j];
1590 + if (send_off < iter_st_off + max_size) {
1591 + send_size[i] += send_len;
1596 + send_curr_offlen_ptr[i] = j;
1598 + if (others_req[i].count) {
1599 + recv_start_pos[i] = recv_curr_offlen_ptr[i];
1600 + for (j = recv_curr_offlen_ptr[i]; j < others_req[i].count; j++) {
1601 + req_off = others_req[i].offsets[j];
1602 + req_len = others_req[i].lens[j];
1603 + if (req_off < iter_st_off + max_size) {
1605 + MPI_Address(write_buf + req_off - off,
1606 + &(others_req[i].mem_ptrs[j]));
1607 + recv_size[i] += req_len;
1612 + recv_curr_offlen_ptr[i] = j;
1615 + /* use variable "hole" to pass data_sieving flag into W_Exchange_data */
1616 + hole = data_sieving;
1617 + ADIOI_LUSTRE_W_Exchange_data(fd, buf, write_buf, flat_buf, offset_list,
1618 + len_list, send_size, recv_size, off, real_size,
1619 + recv_count, recv_start_pos, partial_recv,
1620 + sent_to_proc, nprocs, myrank,
1621 + buftype_is_contig, contig_access_count,
1622 + striping_info, others_req, send_buf_idx,
1623 + curr_to_proc, done_to_proc, &hole, m,
1624 + buftype_extent, buf_idx, error_code);
1625 + if (*error_code != MPI_SUCCESS)
1629 + for (i = 0; i < nprocs; i++)
1630 + if (recv_count[i]) {
1635 + /* check whether to do data sieving */
1636 + if(data_sieving) {
1637 + ADIO_WriteContig(fd, write_buf, real_size, MPI_BYTE,
1638 + ADIO_EXPLICIT_OFFSET, off, &status,
1641 + /* if there is no hole, write data in one time;
1642 + * otherwise, write data in several times */
1644 + ADIO_WriteContig(fd, write_buf, real_size, MPI_BYTE,
1645 + ADIO_EXPLICIT_OFFSET, off, &status,
1648 + for (i = 0; i < nprocs; i++) {
1649 + if (others_req[i].count) {
1650 + for (j = 0; j < others_req[i].count; j++) {
1651 + if (others_req[i].offsets[j] < off + real_size &&
1652 + others_req[i].offsets[j] >= off) {
1653 + ADIO_WriteContig(fd,
1654 + write_buf + others_req[i].offsets[j] - off,
1655 + others_req[i].lens[j],
1656 + MPI_BYTE, ADIO_EXPLICIT_OFFSET,
1657 + others_req[i].offsets[j], &status,
1659 + if (*error_code != MPI_SUCCESS)
1667 + if (*error_code != MPI_SUCCESS)
1670 + iter_st_off += max_size;
1674 + ADIOI_Free(write_buf);
1675 + ADIOI_Free(recv_curr_offlen_ptr);
1676 + ADIOI_Free(send_curr_offlen_ptr);
1677 + ADIOI_Free(recv_count);
1678 + ADIOI_Free(send_size);
1679 + ADIOI_Free(recv_size);
1680 + ADIOI_Free(sent_to_proc);
1681 + ADIOI_Free(recv_start_pos);
1682 + ADIOI_Free(send_buf_idx);
1683 + ADIOI_Free(curr_to_proc);
1684 + ADIOI_Free(done_to_proc);
1685 + ADIOI_Free(off_list);
1688 +static void ADIOI_LUSTRE_W_Exchange_data(ADIO_File fd, void *buf,
1690 + ADIOI_Flatlist_node * flat_buf,
1691 + ADIO_Offset * offset_list,
1692 + int *len_list, int *send_size,
1693 + int *recv_size, ADIO_Offset off,
1694 + int size, int *count,
1695 + int *start_pos, int *partial_recv,
1696 + int *sent_to_proc, int nprocs,
1697 + int myrank, int buftype_is_contig,
1698 + int contig_access_count,
1699 + int * striping_info,
1700 + ADIOI_Access * others_req,
1701 + int *send_buf_idx,
1702 + int *curr_to_proc, int *done_to_proc,
1703 + int *hole, int iter,
1704 + MPI_Aint buftype_extent,
1705 + int *buf_idx, int *error_code)
1707 + int i, j, nprocs_recv, nprocs_send, err;
1708 + char **send_buf = NULL;
1709 + MPI_Request *requests, *send_req;
1710 + MPI_Datatype *recv_types;
1711 + MPI_Status *statuses, status;
1712 + int *srt_len, sum, sum_recv;
1713 + ADIO_Offset *srt_off;
1714 + int data_sieving = *hole;
1715 + static char myname[] = "ADIOI_W_EXCHANGE_DATA";
1717 + /* create derived datatypes for recv */
1719 + for (i = 0; i < nprocs; i++)
1723 + recv_types = (MPI_Datatype *) ADIOI_Malloc((nprocs_recv + 1) *
1724 + sizeof(MPI_Datatype));
1725 + /* +1 to avoid a 0-size malloc */
1728 + for (i = 0; i < nprocs; i++) {
1729 + if (recv_size[i]) {
1730 + MPI_Type_hindexed(count[i],
1731 + &(others_req[i].lens[start_pos[i]]),
1732 + &(others_req[i].mem_ptrs[start_pos[i]]),
1733 + MPI_BYTE, recv_types + j);
1734 + /* absolute displacements; use MPI_BOTTOM in recv */
1735 + MPI_Type_commit(recv_types + j);
1740 + /* To avoid a read-modify-write,
1741 + * check if there are holes in the data to be written.
1742 + * For this, merge the (sorted) offset lists others_req using a heap-merge.
1746 + for (i = 0; i < nprocs; i++)
1748 + srt_off = (ADIO_Offset *) ADIOI_Malloc((sum + 1) * sizeof(ADIO_Offset));
1749 + srt_len = (int *) ADIOI_Malloc((sum + 1) * sizeof(int));
1750 + /* +1 to avoid a 0-size malloc */
1752 + ADIOI_Heap_merge(others_req, count, srt_off, srt_len, start_pos,
1753 + nprocs, nprocs_recv, sum);
1755 + /* check if there are any holes */
1757 + for (i = 0; i < sum - 1; i++) {
1758 + if (srt_off[i] + srt_len[i] < srt_off[i + 1]) {
1763 + /* In some cases (see John Bent ROMIO REQ # 835), an odd interaction
1764 + * between aggregation, nominally contiguous regions, and cb_buffer_size
1765 + * should be handled with a read-modify-write (otherwise we will write out
1766 + * more data than we receive from everyone else (inclusive), so override
1771 + for (i = 0; i < nprocs; i++)
1772 + sum_recv += recv_size[i];
1773 + if (size > sum_recv)
1776 + /* check the hint for data sieving */
1777 + if (data_sieving && nprocs_recv && *hole) {
1778 + ADIO_ReadContig(fd, write_buf, size, MPI_BYTE,
1779 + ADIO_EXPLICIT_OFFSET, off, &status, &err);
1780 + // --BEGIN ERROR HANDLING--
1781 + if (err != MPI_SUCCESS) {
1782 + *error_code = MPIO_Err_create_code(err,
1783 + MPIR_ERR_RECOVERABLE,
1786 + "**ioRMWrdwr", 0);
1787 + ADIOI_Free(recv_types);
1788 + ADIOI_Free(srt_off);
1789 + ADIOI_Free(srt_len);
1792 + // --END ERROR HANDLING--
1794 + ADIOI_Free(srt_off);
1795 + ADIOI_Free(srt_len);
1798 + for (i = 0; i < nprocs; i++)
1802 + if (fd->atomicity) {
1803 + /* bug fix from Wei-keng Liao and Kenin Coloma */
1804 + requests = (MPI_Request *) ADIOI_Malloc((nprocs_send + 1) *
1805 + sizeof(MPI_Request));
1806 + send_req = requests;
1808 + requests = (MPI_Request *) ADIOI_Malloc((nprocs_send + nprocs_recv + 1)*
1809 + sizeof(MPI_Request));
1810 + /* +1 to avoid a 0-size malloc */
1812 + /* post receives */
1814 + for (i = 0; i < nprocs; i++) {
1815 + if (recv_size[i]) {
1816 + MPI_Irecv(MPI_BOTTOM, 1, recv_types[j], i,
1817 + myrank + i + 100 * iter, fd->comm, requests + j);
1821 + send_req = requests + nprocs_recv;
1825 + * if buftype_is_contig, data can be directly sent from
1826 + * user buf at location given by buf_idx. else use send_buf.
1828 + if (buftype_is_contig) {
1830 + for (i = 0; i < nprocs; i++)
1831 + if (send_size[i]) {
1832 + MPI_Isend(((char *) buf) + buf_idx[i], send_size[i],
1833 + MPI_BYTE, i, myrank + i + 100 * iter, fd->comm,
1836 + buf_idx[i] += send_size[i];
1838 + } else if (nprocs_send) {
1839 + /* buftype is not contig */
1840 + send_buf = (char **) ADIOI_Malloc(nprocs * sizeof(char *));
1841 + for (i = 0; i < nprocs; i++)
1843 + send_buf[i] = (char *) ADIOI_Malloc(send_size[i]);
1845 + ADIOI_LUSTRE_Fill_send_buffer(fd, buf, flat_buf, send_buf, offset_list,
1846 + len_list, send_size, send_req,
1847 + sent_to_proc, nprocs, myrank,
1848 + contig_access_count, striping_info,
1849 + send_buf_idx, curr_to_proc, done_to_proc,
1850 + iter, buftype_extent);
1851 + /* the send is done in ADIOI_Fill_send_buffer */
1854 + /* bug fix from Wei-keng Liao and Kenin Coloma */
1855 + if (fd->atomicity) {
1857 + for (i = 0; i < nprocs; i++) {
1858 + MPI_Status wkl_status;
1859 + if (recv_size[i]) {
1860 + MPI_Recv(MPI_BOTTOM, 1, recv_types[j], i,
1861 + myrank + i + 100 * iter, fd->comm, &wkl_status);
1867 + for (i = 0; i < nprocs_recv; i++)
1868 + MPI_Type_free(recv_types + i);
1869 + ADIOI_Free(recv_types);
1871 + /* bug fix from Wei-keng Liao and Kenin Coloma */
1872 + /* +1 to avoid a 0-size malloc */
1873 + if (fd->atomicity) {
1874 + statuses = (MPI_Status *) ADIOI_Malloc((nprocs_send + 1) *
1875 + sizeof(MPI_Status));
1877 + statuses = (MPI_Status *) ADIOI_Malloc((nprocs_send + nprocs_recv + 1) *
1878 + sizeof(MPI_Status));
1881 +#ifdef NEEDS_MPI_TEST
1883 + if (fd->atomicity) {
1884 + /* bug fix from Wei-keng Liao and Kenin Coloma */
1886 + MPI_Testall(nprocs_send, send_req, &i, statuses);
1889 + MPI_Testall(nprocs_send + nprocs_recv, requests, &i, statuses);
1892 + /* bug fix from Wei-keng Liao and Kenin Coloma */
1893 + if (fd->atomicity)
1894 + MPI_Waitall(nprocs_send, send_req, statuses);
1896 + MPI_Waitall(nprocs_send + nprocs_recv, requests, statuses);
1898 + ADIOI_Free(statuses);
1899 + ADIOI_Free(requests);
1900 + if (!buftype_is_contig && nprocs_send) {
1901 + for (i = 0; i < nprocs; i++)
1903 + ADIOI_Free(send_buf[i]);
1904 + ADIOI_Free(send_buf);
1908 +#define ADIOI_BUF_INCR \
1910 + while (buf_incr) { \
1911 + size_in_buf = ADIOI_MIN(buf_incr, flat_buf_sz); \
1912 + user_buf_idx += size_in_buf; \
1913 + flat_buf_sz -= size_in_buf; \
1914 + if (!flat_buf_sz) { \
1915 + if (flat_buf_idx < (flat_buf->count - 1)) flat_buf_idx++; \
1917 + flat_buf_idx = 0; \
1920 + user_buf_idx = flat_buf->indices[flat_buf_idx] + \
1921 + n_buftypes*buftype_extent; \
1922 + flat_buf_sz = flat_buf->blocklens[flat_buf_idx]; \
1924 + buf_incr -= size_in_buf; \
1929 +#define ADIOI_BUF_COPY \
1932 + size_in_buf = ADIOI_MIN(size, flat_buf_sz); \
1933 + memcpy(&(send_buf[p][send_buf_idx[p]]), \
1934 + ((char *) buf) + user_buf_idx, size_in_buf); \
1935 + send_buf_idx[p] += size_in_buf; \
1936 + user_buf_idx += size_in_buf; \
1937 + flat_buf_sz -= size_in_buf; \
1938 + if (!flat_buf_sz) { \
1939 + if (flat_buf_idx < (flat_buf->count - 1)) flat_buf_idx++; \
1941 + flat_buf_idx = 0; \
1944 + user_buf_idx = flat_buf->indices[flat_buf_idx] + \
1945 + n_buftypes*buftype_extent; \
1946 + flat_buf_sz = flat_buf->blocklens[flat_buf_idx]; \
1948 + size -= size_in_buf; \
1949 + buf_incr -= size_in_buf; \
1954 +static void ADIOI_LUSTRE_Fill_send_buffer(ADIO_File fd, void *buf,
1955 + ADIOI_Flatlist_node * flat_buf,
1957 + ADIO_Offset * offset_list,
1958 + int *len_list, int *send_size,
1959 + MPI_Request * requests,
1960 + int *sent_to_proc, int nprocs,
1962 + int contig_access_count,
1963 + int * striping_info,
1964 + int *send_buf_idx,
1965 + int *curr_to_proc,
1966 + int *done_to_proc, int iter,
1967 + MPI_Aint buftype_extent)
1969 + /* this function is only called if buftype is not contig */
1970 + int i, p, flat_buf_idx, size;
1971 + int flat_buf_sz, buf_incr, size_in_buf, jj, n_buftypes;
1972 + ADIO_Offset off, len, rem_len, user_buf_idx;
1974 + /* curr_to_proc[p] = amount of data sent to proc. p that has already
1975 + * been accounted for so far
1976 + * done_to_proc[p] = amount of data already sent to proc. p in
1977 + * previous iterations
1978 + * user_buf_idx = current location in user buffer
1979 + * send_buf_idx[p] = current location in send_buf of proc. p
1982 + for (i = 0; i < nprocs; i++) {
1983 + send_buf_idx[i] = curr_to_proc[i] = 0;
1984 + done_to_proc[i] = sent_to_proc[i];
1988 + user_buf_idx = flat_buf->indices[0];
1991 + flat_buf_sz = flat_buf->blocklens[0];
1993 + /* flat_buf_idx = current index into flattened buftype
1994 + * flat_buf_sz = size of current contiguous component in flattened buf
1996 + for (i = 0; i < contig_access_count; i++) {
1997 + off = offset_list[i];
1998 + rem_len = (ADIO_Offset) len_list[i];
2000 + /*this request may span to more than one process */
2001 + while (rem_len != 0) {
2003 + /* NOTE: len value is modified by ADIOI_Calc_aggregator() to be no
2004 + * longer than the single region that processor "p" is responsible
2007 + p = ADIOI_LUSTRE_Calc_aggregator(fd, off, &len, striping_info);
2009 + if (send_buf_idx[p] < send_size[p]) {
2010 + if (curr_to_proc[p] + len > done_to_proc[p]) {
2011 + if (done_to_proc[p] > curr_to_proc[p]) {
2012 + size = (int) ADIOI_MIN(curr_to_proc[p] + len -
2016 + buf_incr = done_to_proc[p] - curr_to_proc[p];
2018 + buf_incr = (int) (curr_to_proc[p] + len -
2020 + curr_to_proc[p] = done_to_proc[p] + size;
2023 + size = (int) ADIOI_MIN(len, send_size[p] -
2025 + buf_incr = (int) len;
2026 + curr_to_proc[p] += size;
2029 + if (send_buf_idx[p] == send_size[p]) {
2030 + MPI_Isend(send_buf[p], send_size[p], MPI_BYTE, p,
2031 + myrank + p + 100 * iter, fd->comm,
2036 + curr_to_proc[p] += (int) len;
2037 + buf_incr = (int) len;
2041 + buf_incr = (int) len;
2048 + for (i = 0; i < nprocs; i++)
2050 + sent_to_proc[i] = curr_to_proc[i];
2052 diff -ruN ad_lustre_orig/ad_lustre_wrstr.c ad_lustre/ad_lustre_wrstr.c
2053 --- ad_lustre_orig/ad_lustre_wrstr.c 1970-01-01 08:00:00.000000000 +0800
2054 +++ ad_lustre/ad_lustre_wrstr.c 2008-10-13 15:34:53.000000000 +0800
2056 +/* -*- Mode: C; c-basic-offset:4 ; -*- */
2058 + * Copyright (C) 1997 University of Chicago.
2059 + * See COPYRIGHT notice in top-level directory.
2061 + * Copyright (C) 2007 Oak Ridge National Laboratory
2063 + * Copyright (C) 2008 Sun Microsystems, Lustre group
2066 +#include "ad_lustre.h"
2067 +#include "adio_extern.h"
2069 +#define ADIOI_BUFFERED_WRITE \
2071 + if (req_off >= writebuf_off + writebuf_len) { \
2072 + if (writebuf_len) { \
2073 + ADIO_WriteContig(fd, writebuf, writebuf_len, MPI_BYTE, \
2074 + ADIO_EXPLICIT_OFFSET, writebuf_off, &status1, error_code); \
2075 + if (!(fd->atomicity)) \
2076 + ADIOI_UNLOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \
2077 + if (*error_code != MPI_SUCCESS) { \
2078 + *error_code = MPIO_Err_create_code(*error_code, \
2079 + MPIR_ERR_RECOVERABLE, myname, \
2080 + __LINE__, MPI_ERR_IO, \
2082 + ADIOI_Free(writebuf); \
2086 + writebuf_off = req_off; \
2087 + /* stripe_size alignment */ \
2088 + writebuf_len = (int) ADIOI_MIN(end_offset - writebuf_off + 1, \
2089 + (writebuf_off / stripe_size + 1) * \
2090 + stripe_size - writebuf_off);\
2091 + if (!(fd->atomicity)) \
2092 + ADIOI_WRITE_LOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \
2093 + ADIO_ReadContig(fd, writebuf, writebuf_len, MPI_BYTE, ADIO_EXPLICIT_OFFSET,\
2094 + writebuf_off, &status1, error_code); \
2095 + if (*error_code != MPI_SUCCESS) { \
2096 + *error_code = MPIO_Err_create_code(*error_code, \
2097 + MPIR_ERR_RECOVERABLE, myname, \
2098 + __LINE__, MPI_ERR_IO, \
2100 + ADIOI_Free(writebuf); \
2104 + write_sz = (int) ADIOI_MIN(req_len, writebuf_off + writebuf_len - req_off); \
2105 + memcpy(writebuf + req_off - writebuf_off, (char *)buf + userbuf_off, write_sz);\
2106 + while (write_sz != req_len) {\
2107 + ADIO_WriteContig(fd, writebuf, writebuf_len, MPI_BYTE, \
2108 + ADIO_EXPLICIT_OFFSET, writebuf_off, &status1, error_code); \
2109 + if (!(fd->atomicity)) \
2110 + ADIOI_UNLOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \
2111 + if (*error_code != MPI_SUCCESS) { \
2112 + *error_code = MPIO_Err_create_code(*error_code, \
2113 + MPIR_ERR_RECOVERABLE, myname, \
2114 + __LINE__, MPI_ERR_IO, \
2116 + ADIOI_Free(writebuf); \
2119 + req_len -= write_sz; \
2120 + userbuf_off += write_sz; \
2121 + writebuf_off += writebuf_len; \
2122 + /* stripe_size alignment */ \
2123 + writebuf_len = (int) ADIOI_MIN(end_offset - writebuf_off + 1, \
2124 + (writebuf_off / stripe_size + 1) * \
2125 + stripe_size - writebuf_off);\
2126 + if (!(fd->atomicity)) \
2127 + ADIOI_WRITE_LOCK(fd, writebuf_off, SEEK_SET, writebuf_len); \
2128 + ADIO_ReadContig(fd, writebuf, writebuf_len, MPI_BYTE, ADIO_EXPLICIT_OFFSET,\
2129 + writebuf_off, &status1, error_code); \
2130 + if (*error_code != MPI_SUCCESS) { \
2131 + *error_code = MPIO_Err_create_code(*error_code, \
2132 + MPIR_ERR_RECOVERABLE, myname, \
2133 + __LINE__, MPI_ERR_IO, \
2135 + ADIOI_Free(writebuf); \
2138 + write_sz = ADIOI_MIN(req_len, writebuf_len); \
2139 + memcpy(writebuf, (char *)buf + userbuf_off, write_sz);\
2144 +/* this macro is used when filetype is contig and buftype is not contig.
2145 + it does not do a read-modify-write and does not lock*/
2146 +#define ADIOI_BUFFERED_WRITE_WITHOUT_READ \
2148 + if (req_off >= writebuf_off + writebuf_len) { \
2149 + writebuf_off = req_off; \
2150 + /* stripe_size alignment */ \
2151 + writebuf_len = (int) ADIOI_MIN(end_offset - writebuf_off + 1, \
2152 + (writebuf_off / stripe_size + 1) * \
2153 + stripe_size - writebuf_off);\
2155 + write_sz = (int) ADIOI_MIN(req_len, writebuf_off + writebuf_len - req_off); \
2156 + memcpy(writebuf + req_off - writebuf_off, (char *)buf + userbuf_off, write_sz);\
2157 + while (req_len) { \
2158 + ADIO_WriteContig(fd, writebuf, writebuf_len, MPI_BYTE, \
2159 + ADIO_EXPLICIT_OFFSET, writebuf_off, &status1, error_code); \
2160 + if (*error_code != MPI_SUCCESS) { \
2161 + *error_code = MPIO_Err_create_code(*error_code, \
2162 + MPIR_ERR_RECOVERABLE, myname, \
2163 + __LINE__, MPI_ERR_IO, \
2165 + ADIOI_Free(writebuf); \
2168 + req_len -= write_sz; \
2169 + userbuf_off += write_sz; \
2170 + writebuf_off += writebuf_len; \
2171 + /* stripe_size alignment */ \
2172 + writebuf_len = (int) ADIOI_MIN(end_offset - writebuf_off + 1, \
2173 + (writebuf_off / stripe_size + 1) * \
2174 + stripe_size - writebuf_off);\
2175 + write_sz = ADIOI_MIN(req_len, writebuf_len); \
2176 + memcpy(writebuf, (char *)buf + userbuf_off, write_sz);\
2180 +void ADIOI_LUSTRE_WriteStrided(ADIO_File fd, void *buf, int count,
2181 + MPI_Datatype datatype, int file_ptr_type,
2182 + ADIO_Offset offset, ADIO_Status * status,
2185 + /* offset is in units of etype relative to the filetype. */
2186 + ADIOI_Flatlist_node *flat_buf, *flat_file;
2187 + int i, j, k, bwr_size, fwr_size = 0, st_index = 0;
2188 + int bufsize, num, size, sum, n_etypes_in_filetype, size_in_filetype;
2189 + int n_filetypes, etype_in_filetype;
2190 + ADIO_Offset abs_off_in_filetype = 0;
2191 + int filetype_size, etype_size, buftype_size, req_len;
2192 + MPI_Aint filetype_extent, buftype_extent;
2193 + int buf_count, buftype_is_contig, filetype_is_contig;
2194 + ADIO_Offset userbuf_off;
2195 + ADIO_Offset off, req_off, disp, end_offset = 0, writebuf_off, start_off;
2197 + int flag, st_fwr_size, st_n_filetypes, writebuf_len, write_sz;
2198 + ADIO_Status status1;
2199 + int new_bwr_size, new_fwr_size;
2201 + int stripe_size, lflag = 0;
2202 + static char myname[] = "ADIOI_LUSTRE_WriteStrided";
2204 + MPI_Comm_rank(fd->comm, &myrank);
2206 + if (fd->hints->ds_write == ADIOI_HINT_DISABLE) {
2207 + /* if user has disabled data sieving on writes, use naive
2208 + * approach instead.
2210 + ADIOI_GEN_WriteStrided_naive(fd,
2215 + offset, status, error_code);
2219 + *error_code = MPI_SUCCESS; /* changed below if error */
2221 + ADIOI_Datatype_iscontig(datatype, &buftype_is_contig);
2222 + ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
2224 + MPI_Type_size(fd->filetype, &filetype_size);
2225 + if (!filetype_size) {
2226 + *error_code = MPI_SUCCESS;
2230 + MPI_Type_extent(fd->filetype, &filetype_extent);
2231 + MPI_Type_size(datatype, &buftype_size);
2232 + MPI_Type_extent(datatype, &buftype_extent);
2233 + etype_size = fd->etype_size;
2235 + bufsize = buftype_size * count;
2237 + /* get striping info */
2238 + value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL + 1) * sizeof(char));
2239 + MPI_Info_get(fd->info, "striping_unit", MPI_MAX_INFO_VAL, value, &lflag);
2241 + stripe_size = atoi(value);
2242 + ADIOI_Free(value);
2244 + /* Different buftype to different filetype */
2245 + if (!buftype_is_contig && filetype_is_contig) {
2246 + /* noncontiguous in memory, contiguous in file. */
2247 + ADIOI_Flatten_datatype(datatype);
2248 + flat_buf = ADIOI_Flatlist;
2249 + while (flat_buf->type != datatype)
2250 + flat_buf = flat_buf->next;
2252 + off = (file_ptr_type == ADIO_INDIVIDUAL) ? fd->fp_ind :
2253 + fd->disp + etype_size * offset;
2256 + end_offset = start_off + bufsize - 1;
2257 + writebuf_off = start_off;
2258 + /* write stripe size buffer each time */
2259 + writebuf = (char *) ADIOI_Malloc(ADIOI_MIN(bufsize, stripe_size));
2260 + writebuf_len = (int) ADIOI_MIN(bufsize,
2261 + (writebuf_off / stripe_size + 1) *
2262 + stripe_size - writebuf_off);
2264 + /* if atomicity is true, lock the region to be accessed */
2265 + if (fd->atomicity)
2266 + ADIOI_WRITE_LOCK(fd, start_off, SEEK_SET, bufsize);
2268 + for (j = 0; j < count; j++) {
2269 + for (i = 0; i < flat_buf->count; i++) {
2270 + userbuf_off = j * buftype_extent + flat_buf->indices[i];
2272 + req_len = flat_buf->blocklens[i];
2273 + ADIOI_BUFFERED_WRITE_WITHOUT_READ
2274 + off += flat_buf->blocklens[i];
2278 + /* write the buffer out finally */
2279 + ADIO_WriteContig(fd, writebuf, writebuf_len, MPI_BYTE,
2280 + ADIO_EXPLICIT_OFFSET, writebuf_off, &status1,
2283 + if (fd->atomicity)
2284 + ADIOI_UNLOCK(fd, start_off, SEEK_SET, bufsize);
2285 + if (*error_code != MPI_SUCCESS) {
2286 + ADIOI_Free(writebuf);
2289 + ADIOI_Free(writebuf);
2290 + if (file_ptr_type == ADIO_INDIVIDUAL)
2293 + /* noncontiguous in file */
2294 + /* filetype already flattened in ADIO_Open */
2295 + flat_file = ADIOI_Flatlist;
2296 + while (flat_file->type != fd->filetype)
2297 + flat_file = flat_file->next;
2300 + if (file_ptr_type == ADIO_INDIVIDUAL) {
2301 + offset = fd->fp_ind; /* in bytes */
2306 + for (i = 0; i < flat_file->count; i++) {
2307 + if (disp + flat_file->indices[i] +
2308 + (ADIO_Offset) n_filetypes * filetype_extent +
2309 + flat_file->blocklens[i] >= offset) {
2311 + fwr_size = (int) (disp + flat_file->indices[i] +
2312 + (ADIO_Offset) n_filetypes *
2314 + flat_file->blocklens[i] -
2322 + n_etypes_in_filetype = filetype_size / etype_size;
2323 + n_filetypes = (int) (offset / n_etypes_in_filetype);
2324 + etype_in_filetype = (int) (offset % n_etypes_in_filetype);
2325 + size_in_filetype = etype_in_filetype * etype_size;
2328 + for (i = 0; i < flat_file->count; i++) {
2329 + sum += flat_file->blocklens[i];
2330 + if (sum > size_in_filetype) {
2332 + fwr_size = sum - size_in_filetype;
2333 + abs_off_in_filetype = flat_file->indices[i] +
2334 + size_in_filetype - (sum - flat_file->blocklens[i]);
2339 + /* abs. offset in bytes in the file */
2340 + offset = disp + (ADIO_Offset) n_filetypes *filetype_extent +
2341 + abs_off_in_filetype;
2344 + start_off = offset;
2346 + /* If the file bytes is actually contiguous, we do not need data sieve at all */
2347 + if (bufsize <= fwr_size) {
2348 + req_off = start_off;
2349 + req_len = bufsize;
2350 + end_offset = start_off + bufsize - 1;
2351 + writebuf = (char *) ADIOI_Malloc(ADIOI_MIN(bufsize, stripe_size));
2352 + memset(writebuf, -1, ADIOI_MIN(bufsize, stripe_size));
2356 + ADIOI_BUFFERED_WRITE_WITHOUT_READ
2358 + /* Calculate end_offset, the last byte-offset that will be accessed.
2359 + e.g., if start_offset=0 and 100 bytes to be write, end_offset=99 */
2360 + st_fwr_size = fwr_size;
2361 + st_n_filetypes = n_filetypes;
2365 + fwr_size = ADIOI_MIN(st_fwr_size, bufsize);
2366 + while (i < bufsize) {
2368 + end_offset = off + fwr_size - 1;
2370 + if (j < (flat_file->count - 1))
2377 + off = disp + flat_file->indices[j] +
2378 + (ADIO_Offset) n_filetypes * filetype_extent;
2379 + fwr_size = ADIOI_MIN(flat_file->blocklens[j], bufsize - i);
2384 + writebuf = (char *) ADIOI_Malloc(stripe_size);
2385 + memset(writebuf, -1, stripe_size);
2386 + /* if atomicity is true, lock the region to be accessed */
2387 + if (fd->atomicity)
2388 + ADIOI_WRITE_LOCK(fd, start_off, SEEK_SET, bufsize);
2390 + if (buftype_is_contig && !filetype_is_contig) {
2391 + /* contiguous in memory, noncontiguous in file. should be the most
2396 + n_filetypes = st_n_filetypes;
2397 + fwr_size = ADIOI_MIN(st_fwr_size, bufsize);
2398 + while (i < bufsize) {
2400 + /* TYPE_UB and TYPE_LB can result in
2401 + fwr_size = 0. save system call in such cases */
2403 + lseek(fd->fd_sys, off, SEEK_SET);
2404 + err = write(fd->fd_sys, ((char *) buf) + i, fwr_size);
2407 + req_len = fwr_size;
2409 + ADIOI_BUFFERED_WRITE
2413 + if (off + fwr_size < disp + flat_file->indices[j] +
2414 + flat_file->blocklens[j] +
2415 + (ADIO_Offset) n_filetypes * filetype_extent)
2417 + /* did not reach end of contiguous block in filetype.
2418 + no more I/O needed. off is incremented by fwr_size. */
2420 + if (j < (flat_file->count - 1))
2426 + off = disp + flat_file->indices[j] +
2427 + (ADIO_Offset) n_filetypes * filetype_extent;
2428 + fwr_size = ADIOI_MIN(flat_file->blocklens[j],
2433 + /* noncontiguous in memory as well as in file */
2434 + ADIOI_Flatten_datatype(datatype);
2435 + flat_buf = ADIOI_Flatlist;
2436 + while (flat_buf->type != datatype)
2437 + flat_buf = flat_buf->next;
2439 + k = num = buf_count = 0;
2440 + i = (int) (flat_buf->indices[0]);
2443 + n_filetypes = st_n_filetypes;
2444 + fwr_size = st_fwr_size;
2445 + bwr_size = flat_buf->blocklens[0];
2447 + while (num < bufsize) {
2448 + size = ADIOI_MIN(fwr_size, bwr_size);
2451 + lseek(fd->fd_sys, off, SEEK_SET);
2452 + err = write(fd->fd_sys, ((char *) buf) + i, size);
2457 + ADIOI_BUFFERED_WRITE
2460 + new_fwr_size = fwr_size;
2461 + new_bwr_size = bwr_size;
2463 + if (size == fwr_size) {
2464 + /* reached end of contiguous block in file */
2465 + if (j < (flat_file->count - 1)) {
2471 + off = disp + flat_file->indices[j] +
2472 + (ADIO_Offset) n_filetypes * filetype_extent;
2473 + new_fwr_size = flat_file->blocklens[j];
2474 + if (size != bwr_size) {
2476 + new_bwr_size -= size;
2479 + if (size == bwr_size) {
2480 + /* reached end of contiguous block in memory */
2481 + k = (k + 1) % flat_buf->count;
2483 + i = (int) (buftype_extent *
2484 + (buf_count / flat_buf->count) +
2485 + flat_buf->indices[k]);
2486 + new_bwr_size = flat_buf->blocklens[k];
2487 + if (size != fwr_size) {
2489 + new_fwr_size -= size;
2493 + fwr_size = new_fwr_size;
2494 + bwr_size = new_bwr_size;
2498 + /* write the buffer out finally */
2499 + if (writebuf_len) {
2500 + ADIO_WriteContig(fd, writebuf, writebuf_len,
2501 + MPI_BYTE, ADIO_EXPLICIT_OFFSET,
2502 + writebuf_off, &status1, error_code);
2503 + if (!(fd->atomicity))
2504 + ADIOI_UNLOCK(fd, writebuf_off, SEEK_SET, writebuf_len);
2505 + if (*error_code != MPI_SUCCESS) {
2506 + ADIOI_Free(writebuf);
2510 + if (fd->atomicity)
2511 + ADIOI_UNLOCK(fd, start_off, SEEK_SET, bufsize);
2513 + ADIOI_Free(writebuf);
2514 + if (file_ptr_type == ADIO_INDIVIDUAL)
2517 + fd->fp_sys_posn = -1; /* set it to null. */
2519 +#ifdef HAVE_STATUS_SET_BYTES
2520 + MPIR_Status_set_bytes(status, datatype, bufsize);
2521 + /* This is a temporary way of filling in status. The right way is to
2522 + keep track of how much data was actually written by ADIOI_BUFFERED_WRITE. */
2525 + if (!buftype_is_contig)
2526 + ADIOI_Delete_flattened(datatype);
2528 diff -ruN ad_lustre_orig/Makefile.in ad_lustre/Makefile.in
2529 --- ad_lustre_orig/Makefile.in 2008-09-17 14:36:57.000000000 +0800
2530 +++ ad_lustre/Makefile.in 2008-10-17 17:03:06.000000000 +0800
2534 AD_LUSTRE_OBJECTS = ad_lustre.o ad_lustre_open.o \
2535 - ad_lustre_rwcontig.o ad_lustre_hints.o
2536 + ad_lustre_rwcontig.o ad_lustre_wrcoll.o ad_lustre_wrstr.o \
2537 + ad_lustre_hints.o ad_lustre_aggregate.o
2541 @if [ "@ENABLE_SHLIB@" != "none" ] ; then \
2542 diff -ruN ad_lustre_orig/README ad_lustre/README
2543 --- ad_lustre_orig/README 2008-09-17 14:36:57.000000000 +0800
2544 +++ ad_lustre/README 2008-10-17 16:50:15.000000000 +0800
2546 o To post the code for ParColl (Partitioned collective IO)
2548 -----------------------------------------------------
2550 +-----------------------------------------------------
2551 +Improved data redistribution
2552 + o Improve I/O pattern identification. Besides checking interleaving,
2553 + if request I/O size is small, collective I/O will be performed.
2554 + The hint big_req_size can be used to define the req size value.
2555 + o Provide hint CO for load balancing to control the number of
2556 + IO clients for each OST
2557 + o Produce stripe-contiguous I/O pattern that Lustre prefers
2558 + o Reduce the collective overhead by hints contiguous_data and
2559 + same_io_size to remove unnecessary MPI_Alltoall()
2560 + o Control read-modify-write in data sieving in collective IO
2561 + by hint ds_in_coll.
2562 + o Reduce extent lock conflicts by make each OST accessed by one or
2563 + more constant clients.
2565 +-----------------------------------------------------
2567 -----------------------------------------------------
2568 o Direct IO and Lockless IO support
2569 --- common/ad_write_coll_orig.c 2008-10-15 11:24:31.000000000 +0800
2570 +++ common/ad_write_coll.c 2008-10-15 11:25:39.000000000 +0800
2572 int *send_buf_idx, int *curr_to_proc,
2573 int *done_to_proc, int iter,
2574 MPI_Aint buftype_extent);
2575 -static void ADIOI_Heap_merge(ADIOI_Access *others_req, int *count,
2576 +void ADIOI_Heap_merge(ADIOI_Access *others_req, int *count,
2577 ADIO_Offset *srt_off, int *srt_len, int *start_pos,
2578 int nprocs, int nprocs_recv, int total_elements);
2584 -static void ADIOI_Heap_merge(ADIOI_Access *others_req, int *count,
2585 +void ADIOI_Heap_merge(ADIOI_Access *others_req, int *count,
2586 ADIO_Offset *srt_off, int *srt_len, int *start_pos,
2587 int nprocs, int nprocs_recv, int total_elements)