Skip to content

Commit

Permalink
Merge pull request ESMCI#1342 from jedwards4b/hashtables
Browse files Browse the repository at this point in the history
Hashtables
  • Loading branch information
jedwards4b authored Mar 13, 2019
2 parents f28f46f + 0062a18 commit 849ed55
Show file tree
Hide file tree
Showing 10 changed files with 1,342 additions and 193 deletions.
2 changes: 1 addition & 1 deletion src/clib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ include_HEADERS = pio.h
libpio_la_SOURCES = bget.c pioc_sc.c pio_darray.c pio_file.c \
pio_getput_int.c pio_msg.c pio_nc.c pio_rearrange.c pioc.c \
pioc_support.c pio_darray_int.c pio_get_nc.c pio_lists.c pio_nc4.c \
pio_put_nc.c pio_spmd.c pio_internal.h bget.h
pio_put_nc.c pio_spmd.c pio_internal.h bget.h uthash.h
20 changes: 11 additions & 9 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 @@ -144,8 +145,8 @@ typedef struct var_desc_t
/** The size in bytes of a datum of MPI type mpitype. */
int mpi_type_size;

/** Pointer to next var in list. */
struct var_desc_t *next;
UT_hash_handle hh;

} var_desc_t;

/**
Expand Down Expand Up @@ -380,8 +381,8 @@ typedef struct io_desc_t
* group. */
MPI_Comm subset_comm;

/** Pointer to the next io_desc_t in the list. */
struct io_desc_t *next;
UT_hash_handle hh;

} io_desc_t;

/**
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,16 +565,16 @@ 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;

/** PIO data type. */
int pio_type;

/** Pointer to the next file_desc_t in the list of open files. */
struct file_desc_t *next;
/* hash table entry */
UT_hash_handle hh;

/** True if this task should participate in IO (only true for one
* task with netcdf serial files. */
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
Loading

0 comments on commit 849ed55

Please sign in to comment.