Commit d599c583 authored by Shane Snyder's avatar Shane Snyder

modifications for sorting module records

A common record comparision/sort routine is now defined in
darshan-common which can be used by any modules with fixed-length
records and whose records first field is the darshan_base_record.
The comparison was also updated to sort secondarily by darshan
record identifier to resolve a potential bug in the way we have
traditionally sorted the records.
parent 69c954df
......@@ -191,6 +191,11 @@ void darshan_iter_record_refs(
char* darshan_clean_file_path(
const char *path);
void darshan_record_sort(
void *rec_buf,
int rec_count,
int rec_size);
/* darshan_common_val_counter()
*
* Potentially increment an existing common value counter or allocate
......
......@@ -168,6 +168,34 @@ char* darshan_clean_file_path(const char* path)
return(newpath);
}
/* compare function for sorting file records by descending rank first, then
* by ascending record identifiers (which are just unsigned integers)
*/
static int darshan_base_record_compare(const void* a_p, const void* b_p)
{
const struct darshan_base_record *a = a_p;
const struct darshan_base_record *b = b_p;
if(a->rank < b->rank)
return(1);
if(a->rank > b->rank)
return(-1);
/* same rank, sort by ascending record ids */
if(a->id > b->id)
return(1);
if(a->id < b->id)
return(-1);
return(0);
}
void darshan_record_sort(void *rec_buf, int rec_count, int rec_size)
{
qsort(rec_buf, rec_count, rec_size, darshan_base_record_compare);
return;
}
/* HACK: global variables for determining 4 most common values */
static int64_t* walker_val_p = NULL;
static int64_t* walker_cnt_p = NULL;
......
......@@ -48,8 +48,6 @@ static void hdf5_runtime_initialize(
void);
static struct hdf5_file_record_ref *hdf5_track_new_file_record(
darshan_record_id rec_id, const char *path);
static int hdf5_record_compare(
const void* a, const void* b);
static void hdf5_record_reduction_op(
void* infile_v, void* inoutfile_v, int *len, MPI_Datatype *datatype);
static void hdf5_cleanup_runtime(
......@@ -282,20 +280,6 @@ static struct hdf5_file_record_ref *hdf5_track_new_file_record(
return(rec_ref);
}
/* compare function for sorting file records by descending rank */
static int hdf5_record_compare(const void* a_p, const void* b_p)
{
const struct darshan_hdf5_file* a = a_p;
const struct darshan_hdf5_file* b = b_p;
if(a->base_rec.rank < b->base_rec.rank)
return 1;
if(a->base_rec.rank > b->base_rec.rank)
return -1;
return 0;
}
static void hdf5_record_reduction_op(void* infile_v, void* inoutfile_v,
int *len, MPI_Datatype *datatype)
{
......@@ -397,12 +381,11 @@ static void hdf5_shutdown(
rec_ref->file_rec->base_rec.rank = -1;
}
/* sort the array of files descending by rank so that we get all of the
* shared files (marked by rank -1) in a contiguous portion at end
* of the array
/* sort the array of records so we get all of the shared records
* (marked by rank -1) in a contiguous portion at end of the array
*/
qsort(hdf5_rec_buf, hdf5_rec_count, sizeof(struct darshan_hdf5_file),
hdf5_record_compare);
darshan_record_sort(hdf5_rec_buf, hdf5_rec_count,
sizeof(struct darshan_hdf5_file));
/* make *send_buf point to the shared files at the end of sorted array */
red_send_buf = &(hdf5_rec_buf[hdf5_rec_count-shared_rec_count]);
......
......@@ -73,8 +73,6 @@ static void mpiio_runtime_initialize(
void);
static struct mpiio_file_record_ref *mpiio_track_new_file_record(
darshan_record_id rec_id, const char *path);
static int mpiio_record_compare(
const void* a, const void* b);
static void mpiio_finalize_file_records(
void *rec_ref_p);
static void mpiio_record_reduction_op(
......@@ -896,20 +894,6 @@ static struct mpiio_file_record_ref *mpiio_track_new_file_record(
return(rec_ref);
}
/* compare function for sorting file records by descending rank */
static int mpiio_record_compare(const void* a_p, const void* b_p)
{
const struct darshan_mpiio_file* a = a_p;
const struct darshan_mpiio_file* b = b_p;
if(a->base_rec.rank < b->base_rec.rank)
return 1;
if(a->base_rec.rank > b->base_rec.rank)
return -1;
return 0;
}
static void mpiio_finalize_file_records(void *rec_ref_p)
{
struct mpiio_file_record_ref *rec_ref =
......@@ -1349,12 +1333,11 @@ static void mpiio_shutdown(
rec_ref->file_rec->base_rec.rank = -1;
}
/* sort the array of files descending by rank so that we get all of the
* shared files (marked by rank -1) in a contiguous portion at end
* of the array
/* sort the array of records so we get all of the shared records
* (marked by rank -1) in a contiguous portion at end of the array
*/
qsort(mpiio_rec_buf, mpiio_rec_count, sizeof(struct darshan_mpiio_file),
mpiio_record_compare);
darshan_record_sort(mpiio_rec_buf, mpiio_rec_count,
sizeof(struct darshan_mpiio_file));
/* make send_buf point to the shared files at the end of sorted array */
red_send_buf = &(mpiio_rec_buf[mpiio_rec_count-shared_rec_count]);
......
......@@ -44,8 +44,6 @@ static void pnetcdf_runtime_initialize(
void);
static struct pnetcdf_file_record_ref *pnetcdf_track_new_file_record(
darshan_record_id rec_id, const char *path);
static int pnetcdf_record_compare(
const void* a, const void* b);
static void pnetcdf_record_reduction_op(
void* infile_v, void* inoutfile_v, int *len, MPI_Datatype *datatype);
static void pnetcdf_cleanup_runtime(
......@@ -279,20 +277,6 @@ static struct pnetcdf_file_record_ref *pnetcdf_track_new_file_record(
return(rec_ref);
}
/* compare function for sorting file records by descending rank */
static int pnetcdf_record_compare(const void* a_p, const void* b_p)
{
const struct darshan_pnetcdf_file* a = a_p;
const struct darshan_pnetcdf_file* b = b_p;
if(a->base_rec.rank < b->base_rec.rank)
return 1;
if(a->base_rec.rank > b->base_rec.rank)
return -1;
return 0;
}
static void pnetcdf_record_reduction_op(void* infile_v, void* inoutfile_v,
int *len, MPI_Datatype *datatype)
{
......@@ -395,12 +379,12 @@ static void pnetcdf_shutdown(
rec_ref->file_rec->base_rec.rank = -1;
}
/* sort the array of files descending by rank so that we get all of the
* shared files (marked by rank -1) in a contiguous portion at end
* of the array
/* sort the array of records so we get all of the shared records
* (marked by rank -1) in a contiguous portion at end of the array
*/
qsort(pnetcdf_rec_buf, pnetcdf_rec_count, sizeof(struct darshan_pnetcdf_file),
pnetcdf_record_compare);
darshan_record_sort(pnetcdf_rec_buf, pnetcdf_rec_count,
sizeof(struct darshan_pnetcdf_file));
/* make *send_buf point to the shared files at the end of sorted array */
red_send_buf = &(pnetcdf_rec_buf[pnetcdf_rec_count-shared_rec_count]);
......
......@@ -147,8 +147,6 @@ static void posix_aio_tracker_add(
int fd, void *aiocbp);
static struct posix_aio_tracker* posix_aio_tracker_del(
int fd, void *aiocbp);
static int posix_record_compare(
const void* a, const void* b);
static void posix_finalize_file_records(
void *rec_ref_p);
static void posix_record_reduction_op(
......@@ -1492,20 +1490,6 @@ static struct posix_file_record_ref *posix_track_new_file_record(
return(rec_ref);
}
/* compare function for sorting file records by descending rank */
static int posix_record_compare(const void* a_p, const void* b_p)
{
const struct darshan_posix_file* a = a_p;
const struct darshan_posix_file* b = b_p;
if(a->base_rec.rank < b->base_rec.rank)
return 1;
if(a->base_rec.rank > b->base_rec.rank)
return -1;
return 0;
}
/* finds the tracker structure for a given aio operation, removes it from
* the associated linked list for this file record, and returns a pointer.
*
......@@ -2045,12 +2029,11 @@ static void posix_shutdown(
rec_ref->file_rec->base_rec.rank = -1;
}
/* sort the array of files descending by rank so that we get all of the
* shared files (marked by rank -1) in a contiguous portion at end
* of the array
/* sort the array of records so we get all of the shared records
* (marked by rank -1) in a contiguous portion at end of the array
*/
qsort(posix_rec_buf, posix_rec_count, sizeof(struct darshan_posix_file),
posix_record_compare);
darshan_record_sort(posix_rec_buf, posix_rec_count,
sizeof(struct darshan_posix_file));
/* make send_buf point to the shared files at the end of sorted array */
red_send_buf = &(posix_rec_buf[posix_rec_count-shared_rec_count]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment