From 87e57b5b89469327bd54a1fac88d58a4921d22c3 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Fri, 14 Dec 2018 18:43:11 -0700 Subject: [PATCH] better but still has issues --- src/clib/pio_darray.c | 25 ++++++++++++++++++++----- src/clib/pio_darray_int.c | 35 ++++++++++++++++------------------- src/clib/pio_internal.h | 2 +- src/clib/pio_rearrange.c | 1 + src/clib/pio_spmd.c | 2 +- src/clib/pioc.c | 4 +--- 6 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/clib/pio_darray.c b/src/clib/pio_darray.c index 014770b2f3f..747bb27c94a 100644 --- a/src/clib/pio_darray.c +++ b/src/clib/pio_darray.c @@ -267,14 +267,15 @@ int PIOc_write_darray_multi(int ncid, const int *varids, int ioid, int nvars, } if (iodesc->needssort) { - tmparray = pio_sorted_copy(iodesc, array, arraylen, nvars); + if (!(tmparray = malloc(arraylen*nvars*iodesc->piotype_size))) + return pio_err(ios, NULL, PIO_ENOMEM, __FILE__, __LINE__); + pio_sorted_copy(array, tmparray, iodesc, nvars); } else { tmparray = array; } - /* Move data from compute to IO tasks. */ if ((ierr = rearrange_comp2io(ios, iodesc, tmparray, file->iobuf, nvars))) return pio_err(ios, file, ierr, __FILE__, __LINE__); @@ -844,8 +845,8 @@ int PIOc_read_darray(int ncid, int varid, int ioid, PIO_Offset arraylen, io_desc_t *iodesc; /* Pointer to IO description information. */ void *iobuf = NULL; /* holds the data as read on the io node. */ size_t rlen = 0; /* the length of data in iobuf. */ - int ierr; /* Return code. */ - + int ierr; /* Return code. */ + void *tmparray; /* unsorted copy of array buf if required */ /* Get the file info. */ if ((ierr = pio_get_file(ncid, &file))) return pio_err(NULL, NULL, PIO_EBADID, __FILE__, __LINE__); @@ -885,10 +886,24 @@ int PIOc_read_darray(int ncid, int varid, int ioid, PIO_Offset arraylen, return pio_err(NULL, NULL, PIO_EBADIOTYPE, __FILE__, __LINE__); } + if (iodesc->needssort) + { + if (!(tmparray = malloc(iodesc->piotype_size*iodesc->maplen))) + return pio_err(ios, NULL, PIO_ENOMEM, __FILE__, __LINE__); + } + else + tmparray = array; + /* Rearrange the data. */ - if ((ierr = rearrange_io2comp(ios, iodesc, iobuf, array))) + if ((ierr = rearrange_io2comp(ios, iodesc, iobuf, tmparray))) return pio_err(ios, file, ierr, __FILE__, __LINE__); + if (iodesc->needssort) + { + pio_sorted_copy(tmparray, array, iodesc, 1); + free(tmparray); + } + /* Free the buffer. */ if (rlen > 0) brel(iobuf); diff --git a/src/clib/pio_darray_int.c b/src/clib/pio_darray_int.c index 337dba265e6..eed9d975231 100644 --- a/src/clib/pio_darray_int.c +++ b/src/clib/pio_darray_int.c @@ -1906,13 +1906,9 @@ int flush_buffer(int ncid, wmulti_buffer *wmb, bool flushtodisk) return PIO_NOERR; } -void *pio_sorted_copy(io_desc_t *iodesc, void *array, PIO_Offset arraylen, int nvars) +int pio_sorted_copy(const void *array, void *sortedarray, io_desc_t *iodesc, int nvars) { - void *tmparray; - if (!(tmparray = malloc(iodesc->piotype_size * arraylen))) - return NULL; - - int maplen = arraylen / nvars; + int maplen = iodesc->maplen; switch (iodesc->piotype) { case PIO_BYTE: @@ -1920,7 +1916,7 @@ void *pio_sorted_copy(io_desc_t *iodesc, void *array, PIO_Offset arraylen, int n { for (int m=0; m < maplen; m++) { - ((signed char *)tmparray)[iodesc->remap[m]] = ((signed char *)array)[m+maplen*v]; + ((signed char *)sortedarray)[iodesc->remap[m]] = ((signed char *)array)[m+maplen*v]; } } break; @@ -1929,7 +1925,7 @@ void *pio_sorted_copy(io_desc_t *iodesc, void *array, PIO_Offset arraylen, int n { for (int m=0; m < maplen; m++) { - ((char *)tmparray)[iodesc->remap[m]] = ((char *)array)[m+maplen*v]; + ((char *)sortedarray)[iodesc->remap[m]] = ((char *)array)[m+maplen*v]; } } break; @@ -1938,7 +1934,7 @@ void *pio_sorted_copy(io_desc_t *iodesc, void *array, PIO_Offset arraylen, int n { for (int m=0; m < maplen; m++) { - ((short *)tmparray)[iodesc->remap[m]] = ((short *)array)[m+maplen*v]; + ((short *)sortedarray)[iodesc->remap[m]] = ((short *)array)[m+maplen*v]; } } @@ -1948,7 +1944,7 @@ void *pio_sorted_copy(io_desc_t *iodesc, void *array, PIO_Offset arraylen, int n { for (int m=0; m < maplen; m++) { - ((int *)tmparray)[iodesc->remap[m]] = ((int *)array)[m+maplen*v]; + ((int *)sortedarray)[iodesc->remap[m]] = ((int *)array)[m+maplen*v]; } } break; @@ -1957,7 +1953,7 @@ void *pio_sorted_copy(io_desc_t *iodesc, void *array, PIO_Offset arraylen, int n { for (int m=0; m < maplen; m++) { - ((float *)tmparray)[iodesc->remap[m]] = ((float *)array)[m+maplen*v]; + ((float *)sortedarray)[iodesc->remap[m]] = ((float *)array)[m+maplen*v]; } } break; @@ -1966,7 +1962,7 @@ void *pio_sorted_copy(io_desc_t *iodesc, void *array, PIO_Offset arraylen, int n { for (int m=0; m < maplen; m++) { - ((double *)tmparray)[iodesc->remap[m]] = ((double *)array)[m+maplen*v]; + ((double *)sortedarray)[iodesc->remap[m]] = ((double *)array)[m+maplen*v]; } } break; @@ -1975,7 +1971,7 @@ void *pio_sorted_copy(io_desc_t *iodesc, void *array, PIO_Offset arraylen, int n { for (int m=0; m < maplen; m++) { - ((unsigned char *)tmparray)[iodesc->remap[m]] = ((unsigned char *)array)[m+maplen*v]; + ((unsigned char *)sortedarray)[iodesc->remap[m]] = ((unsigned char *)array)[m+maplen*v]; } } break; @@ -1984,7 +1980,7 @@ void *pio_sorted_copy(io_desc_t *iodesc, void *array, PIO_Offset arraylen, int n { for (int m=0; m < maplen; m++) { - ((unsigned short *)tmparray)[iodesc->remap[m]] = ((unsigned short *)array)[m+maplen*v]; + ((unsigned short *)sortedarray)[iodesc->remap[m]] = ((unsigned short *)array)[m+maplen*v]; } } break; @@ -1993,7 +1989,7 @@ void *pio_sorted_copy(io_desc_t *iodesc, void *array, PIO_Offset arraylen, int n { for (int m=0; m < maplen; m++) { - ((unsigned int *)tmparray)[iodesc->remap[m]] = ((unsigned int *)array)[m+maplen*v]; + ((unsigned int *)sortedarray)[iodesc->remap[m]] = ((unsigned int *)array)[m+maplen*v]; } } break; @@ -2002,7 +1998,7 @@ void *pio_sorted_copy(io_desc_t *iodesc, void *array, PIO_Offset arraylen, int n { for (int m=0; m < maplen; m++) { - ((long long *)tmparray)[iodesc->remap[m]] = ((long long *)array)[m+maplen*v]; + ((long long *)sortedarray)[iodesc->remap[m]] = ((long long *)array)[m+maplen*v]; } } break; @@ -2011,7 +2007,7 @@ void *pio_sorted_copy(io_desc_t *iodesc, void *array, PIO_Offset arraylen, int n { for (int m=0; m < maplen; m++) { - ((unsigned long long *)tmparray)[iodesc->remap[m]] = ((unsigned long long *)array)[m+maplen*v]; + ((unsigned long long *)sortedarray)[iodesc->remap[m]] = ((unsigned long long *)array)[m+maplen*v]; } } break; @@ -2020,11 +2016,12 @@ void *pio_sorted_copy(io_desc_t *iodesc, void *array, PIO_Offset arraylen, int n { for (int m=0; m < maplen; m++) { - ((char **)tmparray)[iodesc->remap[m]] = ((char **)array)[m+maplen*v]; + ((char **)sortedarray)[iodesc->remap[m]] = ((char **)array)[m+maplen*v]; } } break; default: - return NULL; + return pio_err(NULL, NULL, PIO_EBADTYPE, __FILE__, __LINE__); } + return PIO_NOERR; } diff --git a/src/clib/pio_internal.h b/src/clib/pio_internal.h index 11840018d17..d2a85be6e2e 100644 --- a/src/clib/pio_internal.h +++ b/src/clib/pio_internal.h @@ -361,7 +361,7 @@ extern "C" { int determine_procs(int num_io_procs, int component_count, int *num_procs_per_comp, int **proc_list, int **my_proc_list); - void *pio_sorted_copy(io_desc_t *iodesc, void *array, PIO_Offset arraylen, int nvars); + int pio_sorted_copy(const void *array, void *tmparray, io_desc_t *iodesc, int nvars); #if defined(__cplusplus) } #endif diff --git a/src/clib/pio_rearrange.c b/src/clib/pio_rearrange.c index dbda0744bfe..1ad4c1817fc 100644 --- a/src/clib/pio_rearrange.c +++ b/src/clib/pio_rearrange.c @@ -986,6 +986,7 @@ int rearrange_io2comp(iosystem_desc_t *ios, io_desc_t *iodesc, void *sbuf, int niotasks; int mpierr; /* Return code from MPI calls. */ int ret; + void *tmparray; /* Check inputs. */ pioassert(ios && iodesc, "invalid input", __FILE__, __LINE__); diff --git a/src/clib/pio_spmd.c b/src/clib/pio_spmd.c index da2eef333b0..515cdd7da8e 100644 --- a/src/clib/pio_spmd.c +++ b/src/clib/pio_spmd.c @@ -113,7 +113,7 @@ int pio_swapm(void *sendbuf, int *sendcounts, int *sdispls, MPI_Datatype *sendty #if PIO_ENABLE_LOGGING { for (int p = 0; p < ntasks; p++) - LOG((3, "sendcounts[%d] = %d sdispls[%d] = %d sendtypes[%d] = %d recvcounts[%d] = %d " + LOG((4, "sendcounts[%d] = %d sdispls[%d] = %d sendtypes[%d] = %d recvcounts[%d] = %d " "rdispls[%d] = %d recvtypes[%d] = %d", p, sendcounts[p], p, sdispls[p], p, sendtypes[p], p, recvcounts[p], p, rdispls[p], p, recvtypes[p])); } diff --git a/src/clib/pioc.c b/src/clib/pioc.c index 39bdbb0212a..87cda84f37f 100644 --- a/src/clib/pioc.c +++ b/src/clib/pioc.c @@ -370,7 +370,7 @@ void pio_map_sort(const PIO_Offset *map, int *remap, int maplen) switched = false; for(int i=1; i map[remap[i]]) { int remaptemp = remap[i]; remap[i] = remap[i-1]; @@ -531,9 +531,7 @@ int PIOc_InitDecomp(int iosysid, int pio_type, int ndims, const int *gdimlen, in iodesc->remap[m] = m; pio_map_sort(compmap, iodesc->remap, maplen); for (int m=0; m < maplen; m++) - { iodesc->map[iodesc->remap[m]] = compmap[m]; - } } else {