Skip to content

Commit

Permalink
replace linked list with hash lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards4b committed Mar 11, 2019
1 parent ebd44d3 commit 23d71d3
Show file tree
Hide file tree
Showing 5 changed files with 1,251 additions and 29 deletions.
8 changes: 5 additions & 3 deletions src/clib/pio.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <stdbool.h>
#include <string.h> /* memcpy */
#include <mpi.h>
#include <uthash.h>

#ifdef _NETCDF
#include <netcdf.h>
Expand Down Expand Up @@ -528,8 +529,9 @@ typedef struct wmulti_buffer
/** Pointer to the data. */
void *data;

/** Pointer to the next multi-buffer in the list. */
struct wmulti_buffer *next;
/** uthash handle for hash of buffers **/
int htid;
UT_hash_handle hh;
} wmulti_buffer;

/**
Expand Down Expand Up @@ -563,7 +565,7 @@ typedef struct file_desc_t

/** The wmulti_buffer is used to aggregate multiple variables with
* the same communication pattern prior to a write. */
struct wmulti_buffer buffer;
struct wmulti_buffer *buffer;

/** Data buffer for this file. */
void *iobuf;
Expand Down
19 changes: 10 additions & 9 deletions src/clib/pio_darray.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <config.h>
#include <pio.h>
#include <pio_internal.h>

#include <uthash.h>
/* 10MB default limit. */
PIO_Offset pio_buffer_size_limit = PIO_BUFFER_SIZE;

Expand Down Expand Up @@ -619,6 +619,7 @@ int PIOc_write_darray(int ncid, int varid, int ioid, PIO_Offset arraylen, void *
bufsize totfree; /* Amount of free space in the buffer. */
bufsize maxfree; /* Max amount of free space in buffer. */
#endif
int hashid;
int mpierr = MPI_SUCCESS; /* Return code from MPI functions. */
int ierr = PIO_NOERR; /* Return code. */
size_t io_data_size; /* potential size of data on io task */
Expand Down Expand Up @@ -673,29 +674,29 @@ int PIOc_write_darray(int ncid, int varid, int ioid, PIO_Offset arraylen, void *
return pio_err(ios, file, PIO_EINVAL, __FILE__, __LINE__);

/* Move to end of list or the entry that matches this ioid. */
for (wmb = &file->buffer; wmb->next; wmb = wmb->next)
if (wmb->ioid == ioid && wmb->recordvar == vdesc->rec_var)
break;
LOG((3, "wmb->ioid = %d wmb->recordvar = %d", wmb->ioid, wmb->recordvar));
hashid = ioid*10 + vdesc->rec_var;
HASH_FIND_INT( file->buffer, &hashid, wmb);
if (wmb)
LOG((3, "wmb->ioid = %d wmb->recordvar = %d", wmb->ioid, wmb->recordvar));

/* If we did not find an existing wmb entry, create a new wmb. */
if (wmb->ioid != ioid || wmb->recordvar != vdesc->rec_var)
if (!wmb)
{
/* Allocate a buffer. */
if (!(wmb->next = bget((bufsize)sizeof(wmulti_buffer))))
if (!(wmb = bget((bufsize)sizeof(wmulti_buffer))))
return pio_err(ios, file, PIO_ENOMEM, __FILE__, __LINE__);

/* Set pointer to newly allocated buffer and initialize.*/
wmb = wmb->next;
wmb->recordvar = vdesc->rec_var;
wmb->next = NULL;
wmb->ioid = ioid;
wmb->num_arrays = 0;
wmb->arraylen = arraylen;
wmb->vid = NULL;
wmb->data = NULL;
wmb->frame = NULL;
wmb->fillvalue = NULL;
wmb->htid = hashid;
HASH_ADD_INT( file->buffer, htid, wmb );
}
LOG((2, "wmb->num_arrays = %d arraylen = %d iodesc->mpitype_size = %d\n",
wmb->num_arrays, arraylen, iodesc->mpitype_size));
Expand Down
24 changes: 8 additions & 16 deletions src/clib/pio_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <config.h>
#include <pio.h>
#include <pio_internal.h>

#include <uthash.h>
/* This is the next ncid that will be used when a file is opened or
created. We start at 16 so that it will be easy for us to notice
that it's not netcdf (starts at 4), pnetcdf (starts at 0) or
Expand Down Expand Up @@ -386,25 +386,17 @@ int PIOc_sync(int ncid)
wmulti_buffer *wmb, *twmb;

LOG((3, "PIOc_sync checking buffers"));
wmb = &file->buffer;
while (wmb)
{
HASH_ITER(hh, file->buffer, wmb, twmb)
{
/* If there are any data arrays waiting in the
* multibuffer, flush it. */
if (wmb->num_arrays > 0)
flush_buffer(ncid, wmb, true);
twmb = wmb;
wmb = wmb->next;
if (twmb == &file->buffer)
{
twmb->ioid = -1;
twmb->next = NULL;
}
else
{
brel(twmb);
}
}
HASH_DEL(file->buffer, wmb);
brel(wmb);

}
file->buffer = NULL;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/clib/pioc_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -1755,7 +1755,7 @@ int PIOc_createfile_int(int iosysid, int *ncidp, int *iotype, const char *filena
file->fh = -1;
file->iosystem = ios;
file->iotype = *iotype;
file->buffer.ioid = -1;
file->buffer = NULL;
file->writable = 1;

/* Set to true if this task should participate in IO (only true for
Expand Down
Loading

0 comments on commit 23d71d3

Please sign in to comment.