Skip to content

Commit

Permalink
better but still has issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards4b committed Dec 15, 2018
1 parent 8061b90 commit 87e57b5
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 29 deletions.
25 changes: 20 additions & 5 deletions src/clib/pio_darray.c
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
Expand Down Expand Up @@ -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__);
Expand Down Expand Up @@ -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);
Expand Down
35 changes: 16 additions & 19 deletions src/clib/pio_darray_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -1906,21 +1906,17 @@ 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:
for (int v=0; v < nvars; v++)
{
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;
Expand All @@ -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;
Expand All @@ -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];
}
}

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion src/clib/pio_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/clib/pio_rearrange.c
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
Expand Down
2 changes: 1 addition & 1 deletion src/clib/pio_spmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
}
Expand Down
4 changes: 1 addition & 3 deletions src/clib/pioc.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ void pio_map_sort(const PIO_Offset *map, int *remap, int maplen)
switched = false;
for(int i=1; i<maplen; i++)
{
if (map[remap[i-1]] < map[remap[i]])
if (map[remap[i-1]] > map[remap[i]])
{
int remaptemp = remap[i];
remap[i] = remap[i-1];
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 87e57b5

Please sign in to comment.