| 1 |
/* |
| 2 |
* Copyright (C) by Argonne National Laboratory |
| 3 |
* See COPYRIGHT in top-level directory |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "ad_daos.h" |
| 7 |
|
| 8 |
#include "../../mpi-io/mpioimpl.h" |
| 9 |
#ifdef MPIO_BUILD_PROFILING |
| 10 |
#include "../../mpi-io/mpioprof.h" |
| 11 |
#endif |
| 12 |
#include "mpiu_greq.h" |
| 13 |
|
| 14 |
enum { |
| 15 |
DAOS_WRITE, |
| 16 |
DAOS_READ |
| 17 |
}; |
| 18 |
|
| 19 |
static MPIX_Grequest_class ADIOI_DAOS_greq_class = 0; |
| 20 |
|
| 21 |
static void DAOS_IOContig(ADIO_File fd, void *buf, MPI_Aint count, |
| 22 |
MPI_Datatype datatype, int file_ptr_type, |
| 23 |
ADIO_Offset offset, ADIO_Status * status, |
| 24 |
MPI_Request * request, int flag, int *error_code) |
| 25 |
{ |
| 26 |
MPI_Count datatype_size; |
| 27 |
uint64_t len; |
| 28 |
d_sg_list_t *sgl, loc_sgl; |
| 29 |
d_iov_t *iov, loc_iov; |
| 30 |
daos_size_t *nbytes, loc_nbytes; |
| 31 |
int ret; |
| 32 |
struct ADIO_DAOS_cont *cont = fd->fs_ptr; |
| 33 |
struct ADIO_DAOS_req *aio_req; |
| 34 |
static char myname[] = "ADIOI_DAOS_IOCONTIG"; |
| 35 |
|
| 36 |
MPI_Type_size_x(datatype, &datatype_size); |
| 37 |
len = (ADIO_Offset) datatype_size *(ADIO_Offset) count; |
| 38 |
|
| 39 |
if (request) { |
| 40 |
aio_req = (struct ADIO_DAOS_req *) ADIOI_Calloc(sizeof(struct ADIO_DAOS_req), 1); |
| 41 |
daos_event_init(&aio_req->daos_event, DAOS_HDL_INVAL, NULL); |
| 42 |
|
| 43 |
sgl = &aio_req->sgl; |
| 44 |
iov = &aio_req->iov; |
| 45 |
nbytes = &aio_req->nbytes; |
| 46 |
|
| 47 |
if (ADIOI_DAOS_greq_class == 0) { |
| 48 |
MPIX_Grequest_class_create(ADIOI_GEN_aio_query_fn, |
| 49 |
ADIOI_DAOS_aio_free_fn, MPIU_Greq_cancel_fn, |
| 50 |
ADIOI_DAOS_aio_poll_fn, ADIOI_DAOS_aio_wait_fn, |
| 51 |
&ADIOI_DAOS_greq_class); |
| 52 |
} |
| 53 |
MPIX_Grequest_class_allocate(ADIOI_DAOS_greq_class, aio_req, request); |
| 54 |
memcpy(&(aio_req->req), request, sizeof(MPI_Request)); |
| 55 |
} else { |
| 56 |
sgl = &loc_sgl; |
| 57 |
iov = &loc_iov; |
| 58 |
nbytes = &loc_nbytes; |
| 59 |
} |
| 60 |
|
| 61 |
if (len == 0) { |
| 62 |
*nbytes = 0; |
| 63 |
goto done; |
| 64 |
} |
| 65 |
|
| 66 |
if (file_ptr_type == ADIO_INDIVIDUAL) { |
| 67 |
offset = fd->fp_ind; |
| 68 |
} |
| 69 |
|
| 70 |
/** set memory location */ |
| 71 |
sgl->sg_nr = 1; |
| 72 |
sgl->sg_nr_out = 0; |
| 73 |
d_iov_set(iov, buf, len); |
| 74 |
sgl->sg_iovs = iov; |
| 75 |
#ifdef D_PRINT_IO_MEM |
| 76 |
printf("MEM : off %lld len %zu\n", buf, len); |
| 77 |
#endif |
| 78 |
|
| 79 |
#ifdef D_PRINT_IO |
| 80 |
int mpi_rank; |
| 81 |
|
| 82 |
MPI_Comm_rank(fd->comm, &mpi_rank); |
| 83 |
printf("(%d) CONTIG IO OP %d, Off %llu, Len %zu\n", mpi_rank, flag, offset, len); |
| 84 |
#endif |
| 85 |
|
| 86 |
if (flag == DAOS_WRITE) { |
| 87 |
ret = dfs_write(cont->dfs, cont->obj, sgl, offset, (request ? &aio_req->daos_event : NULL)); |
| 88 |
if (ret != 0) { |
| 89 |
PRINT_MSG(stderr, "dfs_write() failed with %d\n", ret); |
| 90 |
*error_code = ADIOI_DAOS_err(myname, cont->obj_name, __LINE__, ret); |
| 91 |
return; |
| 92 |
} |
| 93 |
*nbytes = len; |
| 94 |
} else if (flag == DAOS_READ) { |
| 95 |
ret = dfs_read(cont->dfs, cont->obj, sgl, offset, nbytes, |
| 96 |
(request ? &aio_req->daos_event : NULL)); |
| 97 |
if (ret != 0) { |
| 98 |
PRINT_MSG(stderr, "dfs_read() failed with %d\n", ret); |
| 99 |
*error_code = ADIOI_DAOS_err(myname, cont->obj_name, __LINE__, ret); |
| 100 |
return; |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
if (file_ptr_type == ADIO_INDIVIDUAL) { |
| 105 |
fd->fp_ind += len; |
| 106 |
} |
| 107 |
|
| 108 |
fd->fp_sys_posn = offset + len; |
| 109 |
|
| 110 |
done: |
| 111 |
#ifdef HAVE_STATUS_SET_BYTES |
| 112 |
if (request == NULL && status) |
| 113 |
MPIR_Status_set_bytes(status, datatype, *nbytes); |
| 114 |
#endif |
| 115 |
|
| 116 |
*error_code = MPI_SUCCESS; |
| 117 |
} |
| 118 |
|
| 119 |
void ADIOI_DAOS_ReadContig(ADIO_File fd, void *buf, MPI_Aint count, |
| 120 |
MPI_Datatype datatype, int file_ptr_type, |
| 121 |
ADIO_Offset offset, ADIO_Status * status, int *error_code) |
| 122 |
{ |
| 123 |
DAOS_IOContig(fd, buf, count, datatype, file_ptr_type, |
| 124 |
offset, status, NULL, DAOS_READ, error_code); |
| 125 |
} |
| 126 |
|
| 127 |
void ADIOI_DAOS_WriteContig(ADIO_File fd, const void *buf, MPI_Aint count, |
| 128 |
MPI_Datatype datatype, int file_ptr_type, |
| 129 |
ADIO_Offset offset, ADIO_Status * status, int *error_code) |
| 130 |
{ |
| 131 |
DAOS_IOContig(fd, (void *) buf, count, datatype, file_ptr_type, |
| 132 |
offset, status, NULL, DAOS_WRITE, error_code); |
| 133 |
} |
| 134 |
|
| 135 |
void ADIOI_DAOS_IReadContig(ADIO_File fd, void *buf, MPI_Aint count, |
| 136 |
MPI_Datatype datatype, int file_ptr_type, |
| 137 |
ADIO_Offset offset, MPI_Request * request, int *error_code) |
| 138 |
{ |
| 139 |
DAOS_IOContig(fd, buf, count, datatype, file_ptr_type, |
| 140 |
offset, NULL, request, DAOS_READ, error_code); |
| 141 |
} |
| 142 |
|
| 143 |
void ADIOI_DAOS_IWriteContig(ADIO_File fd, const void *buf, MPI_Aint count, |
| 144 |
MPI_Datatype datatype, int file_ptr_type, |
| 145 |
ADIO_Offset offset, MPI_Request * request, int *error_code) |
| 146 |
{ |
| 147 |
DAOS_IOContig(fd, (void *) buf, count, datatype, file_ptr_type, |
| 148 |
offset, NULL, request, DAOS_WRITE, error_code); |
| 149 |
} |
| 150 |
|
| 151 |
int ADIOI_DAOS_aio_free_fn(void *extra_state) |
| 152 |
{ |
| 153 |
struct ADIO_DAOS_req *aio_req = (struct ADIO_DAOS_req *) extra_state; |
| 154 |
|
| 155 |
if (aio_req->iovs) |
| 156 |
ADIOI_Free(aio_req->iovs); |
| 157 |
|
| 158 |
if (aio_req->rgs) |
| 159 |
ADIOI_Free(aio_req->rgs); |
| 160 |
|
| 161 |
ADIOI_Free(aio_req); |
| 162 |
|
| 163 |
return MPI_SUCCESS; |
| 164 |
} |
| 165 |
|
| 166 |
int ADIOI_DAOS_aio_poll_fn(void *extra_state, MPI_Status * status) |
| 167 |
{ |
| 168 |
struct ADIO_DAOS_req *aio_req = (struct ADIO_DAOS_req *) extra_state;; |
| 169 |
int ret; |
| 170 |
bool flag; |
| 171 |
|
| 172 |
ret = daos_event_test(&aio_req->daos_event, DAOS_EQ_NOWAIT, &flag); |
| 173 |
if (ret != 0) |
| 174 |
return MPI_UNDEFINED; |
| 175 |
|
| 176 |
if (flag) |
| 177 |
MPI_Grequest_complete(aio_req->req); |
| 178 |
else |
| 179 |
return ret; |
| 180 |
|
| 181 |
if (aio_req->daos_event.ev_error != 0) |
| 182 |
ret = ADIOI_DAOS_err("ADIOI_DAOS_aio_poll_fn", "DAOS Event Error", __LINE__, ret); |
| 183 |
else |
| 184 |
ret = MPI_SUCCESS; |
| 185 |
|
| 186 |
return ret; |
| 187 |
} |
| 188 |
|
| 189 |
/* wait for multiple requests to complete */ |
| 190 |
int ADIOI_DAOS_aio_wait_fn(int count, void **array_of_states, double timeout, MPI_Status * status) |
| 191 |
{ |
| 192 |
|
| 193 |
struct ADIO_DAOS_req **aio_reqlist; |
| 194 |
int i, nr_complete, ret; |
| 195 |
|
| 196 |
aio_reqlist = (struct ADIO_DAOS_req **) array_of_states; |
| 197 |
|
| 198 |
nr_complete = 0; |
| 199 |
while (nr_complete < count) { |
| 200 |
for (i = 0; i < count; i++) { |
| 201 |
bool flag; |
| 202 |
|
| 203 |
ret = daos_event_test(&aio_reqlist[i]->daos_event, |
| 204 |
(timeout > 0) ? (int64_t) timeout : DAOS_EQ_WAIT, &flag); |
| 205 |
if (ret != 0) |
| 206 |
return MPI_UNDEFINED; |
| 207 |
|
| 208 |
if (flag) { |
| 209 |
MPI_Grequest_complete(aio_reqlist[i]->req); |
| 210 |
nr_complete++; |
| 211 |
} |
| 212 |
} |
| 213 |
} |
| 214 |
return MPI_SUCCESS; /* TODO: no idea how to deal with errors */ |
| 215 |
} |