Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/clib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ project (PIOC C)
if (CMAKE_BUILD_TYPE)
define_property(
SOURCE
PROPERTY COMPILE_FLAGS
INHERITED
PROPERTY COMPILE_FLAGS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid adding unneeded whitespace.

INHERITED
BRIEF_DOCS "brief-doc"
FULL_DOCS "full-doc"
)
Expand All @@ -28,16 +28,19 @@ set (src topology.c pio_file.c pioc_support.c pio_lists.c
if (NETCDF_INTEGRATION)
set (src ${src} ../ncint/nc_get_vard.c ../ncint/ncintdispatch.c ../ncint/ncint_pio.c ../ncint/nc_put_vard.c)
endif ()
#<<THIS IS NOT YET IMPLEMENTED - MSL>> if (GDAL_INTEGRATION)
set (src ${src} pio_gdal.c)
#endif ()

add_library (pioc ${src})

# Always use -fPIC
set_property(TARGET pioc PROPERTY POSITION_INDEPENDENT_CODE ON)

set_source_files_properties(
pioc_async.c
set_source_files_properties(
pioc_async.c
PROPERTIES
COMPILE_FLAGS -O0
COMPILE_FLAGS -O0
)


Expand All @@ -63,7 +66,7 @@ target_compile_definitions (pioc

# Compiler-specific compiler options
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
string(APPEND CMAKE_C_FLAGS " -std=gnu99 " )
string(APPEND CMAKE_C_FLAGS " -std=c99 " )
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "PGI")
string(APPEND CMAKE_C_FLAGS " -c99 ")
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "Intel")
Expand Down Expand Up @@ -173,6 +176,14 @@ if (PIO_USE_MPISERIAL)
endif ()
endif ()

#===== GDAL ===== <M.Long>
#if (GDAL_Found)
target_include_directories (pioc
PUBLIC ${GDAL_INCLUDE_DIR})
target_link_libraries (pioc
PUBLIC ${GDAL_LIBRARY})
#endif ()

include(CheckTypeSize)
check_type_size("size_t" SIZEOF_SIZE_T)
CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
Expand Down
24 changes: 12 additions & 12 deletions src/clib/parallel_sort.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* c.f.: https://raw.githubusercontent.com/rabauke/mpl/main/examples/parallel_sort_mpi.c
* c.f.: https://raw.githubusercontent.com/rabauke/mpl/master/examples/parallel_sort_mpi.c
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for correcting.

* parallel sort algorithm for distributed memory computers
*
* algorithm works as follows:
Expand Down Expand Up @@ -96,8 +96,8 @@ bool is_unique(CVector v) {
* @param comm the MPI communicator over which v is distributed
* @param v A CVector distributed over comm
* @param ierr indicates an error was encountered
* @return A CVector sorted over comm, the size of the new vector may be different
* than v with a worst case of the entire result on one task.
* @return A CVector sorted over comm, the size of the new vector may be different
* than v with a worst case of the entire result on one task.
*/

CVector parallel_sort(MPI_Comm comm, CVector v, int *ierr) {
Expand Down Expand Up @@ -130,7 +130,7 @@ CVector parallel_sort(MPI_Comm comm, CVector v, int *ierr) {

if(!(pivot_pos = malloc((size + 1) * sizeof(*pivot_pos))))
*ierr = pio_err(NULL, NULL, PIO_ENOMEM, __FILE__,__LINE__);

pivot_pos[0] = v.data;
for (size_t i = 0; i < size - 1; ++i)
pivot_pos[i + 1] = partition(pivot_pos[i], v.data + v.N, local_pivots[i]);
Expand Down Expand Up @@ -189,29 +189,29 @@ CVector parallel_sort(MPI_Comm comm, CVector v, int *ierr) {
*/
int run_unique_check(MPI_Comm comm, size_t N,datatype *v, bool *has_dups)
{
int rank, size;
int mpierr=MPI_SUCCESS;
int rank, size, i, r;
int mpierr=MPI_SUCCESS, mpierr2;
int ierr;
if ((mpierr = MPI_Comm_rank(comm, &rank)))
check_mpi(NULL, NULL, mpierr, __FILE__, __LINE__);
check_mpi(NULL, NULL, mpierr2, __FILE__, __LINE__);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong, mpierr is an input to check_mpi.


if ((mpierr = MPI_Comm_size(comm, &size)))
check_mpi(NULL, NULL, mpierr, __FILE__, __LINE__);

check_mpi(NULL, NULL, mpierr2, __FILE__, __LINE__);
srand(time(NULL) * rank);

CVector sorted = parallel_sort(comm, (CVector){v, N}, &ierr);

int i_have_dups = is_unique(sorted) ? 0:1;
int global_dups;
if ((mpierr = MPI_Allreduce(&i_have_dups, &global_dups, 1, MPI_INT, MPI_MAX, comm)))
check_mpi(NULL, NULL, mpierr, __FILE__, __LINE__);

check_mpi(NULL, NULL, mpierr2, __FILE__, __LINE__);
if(global_dups > 0)
*has_dups = true;
else
*has_dups = false;

#ifdef DEBUG_PARALLEL_SORT
for (r=0; r<size; r++)
{
Expand Down
75 changes: 33 additions & 42 deletions src/clib/pio.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,9 @@
#include <uthash.h>

#include <netcdf.h>
#include <netcdf_meta.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this removed?


#define NETCDF_VERSION_LE(Maj, Min, Pat) \
(((NC_VERSION_MAJOR == Maj) && (NC_VERSION_MINOR == Min) && (NC_VERSION_PATCH <= Pat)) || \
((NC_VERSION_MAJOR == Maj) && (NC_VERSION_MINOR < Min)) || (NC_VERSION_MAJOR < Maj))

#define NETCDF_VERSION_GE(Maj, Min, Pat) \
(((NC_VERSION_MAJOR == Maj) && (NC_VERSION_MINOR == Min) && (NC_VERSION_PATCH >= Pat)) || \
((NC_VERSION_MAJOR == Maj) && (NC_VERSION_MINOR > Min)) || (NC_VERSION_MAJOR > Maj))

#include <gdal.h>
//#include <ogr_api.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the commented include?


/** PIO_OFFSET is an integer type of size sufficient to represent the
* size (in bytes) of the largest file supported by MPI. This is not
Expand Down Expand Up @@ -124,7 +117,7 @@ typedef struct var_desc_t
int record;

/** ID of each outstanding pnetcdf request for this variable. */
// int *request;
int *request;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no longer used, should be removed.


/** Number of requests pending with pnetcdf. */
int nreqs;
Expand Down Expand Up @@ -316,7 +309,7 @@ typedef struct io_desc_t
* sort it. */
bool needssort;

/** If the decomp has repeated values it can only be used for reading
/** If the decomp has repeated values it can only be used for reading
since it doesn't make sense to write a single value from more than one location. */
bool readonly;

Expand Down Expand Up @@ -460,13 +453,13 @@ typedef struct iosystem_desc_t
* process is not part of the IO communicator. */
int io_rank;

/** Set to MPI_ROOT if this task is the main of IO communicator, 0
/** Set to MPI_ROOT if this task is the master of IO communicator, 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case it should be main and not master, I think maybe you started with an older pio tag but somehow broke the history so git is trying to bring in a bunch of old code along with your changes. A straightforward way to fix this might be to do a git diff in the esmf version then add only the diffs to the ParallelIO branch.

* otherwise. */
int iomain;
int iomaster;

/** Set to MPI_ROOT if this task is the main of comp communicator, 0
/** Set to MPI_ROOT if this task is the master of comp communicator, 0
* otherwise. */
int compmain;
int compmaster;

/** Rank of IO root task (which is rank 0 in io_comm) in the union
* communicator. */
Expand Down Expand Up @@ -606,6 +599,13 @@ typedef struct file_desc_t
* feature. One consequence is that PIO_IOTYPE_NETCDF4C files will
* not have deflate automatically turned on for each var. */
int ncint_file;

/** GDAL specific vars - M.Long */
GDALDatasetH *hDS;
int dateVarID; // Index of field with type OFTDate
int timeVarID; // Index of field with type OFTTime
int datetimeVarID; // Index of field with type OFTDatetime

} file_desc_t;

/**
Expand All @@ -624,7 +624,10 @@ enum PIO_IOTYPE
PIO_IOTYPE_NETCDF4C = 3,

/** NetCDF4 (HDF5) parallel */
PIO_IOTYPE_NETCDF4P = 4
PIO_IOTYPE_NETCDF4P = 4,

/** GDAL (serial only) */
PIO_IOTYPE_GDAL = 5
};

/**
Expand Down Expand Up @@ -687,13 +690,6 @@ enum PIO_ERROR_HANDLERS
#define PIO_64BIT_OFFSET NC_64BIT_OFFSET /**< Use large (64-bit) file offsets. Mode flag for nc_create(). */
#define PIO_64BIT_DATA NC_64BIT_DATA /**< CDF5 format. */

#ifdef NC_HAS_QUANTIZE
#define PIO_NOQUANTIZE NC_NOQUANTIZE
#define PIO_QUANTIZE_BITGROOM NC_QUANTIZE_BITGROOM
#define PIO_QUANTIZE_GRANULARBR NC_QUANTIZE_GRANULARBR
#define PIO_QUANTIZE_BITROUND NC_QUANTIZE_BITROUND /**< Use BitRound quantization. */
#endif

/** Define the netCDF-based error codes. */
#define PIO_NOERR NC_NOERR /**< No Error */
#define PIO_EBADID NC_EBADID /**< Bad ncid */
Expand Down Expand Up @@ -784,7 +780,7 @@ enum PIO_ERROR_HANDLERS
#define PIO_FILL_UINT64 NC_FILL_UINT64 /**< Default fill value for this type. */

#define PIO_EINDEP (-203) /**< independent access error. */
#define PIO_EINSUFFBUF (-219) /**< Insufficient buffer size (pnetcdf only) */

#define PIO_FIRST_ERROR_CODE (-500) /**< The first error code for PIO. */
#define PIO_EBADIOTYPE (-500) /**< Bad IOTYPE error. */
#define PIO_EVARDIMMISMATCH (-501) /**< Variable dimensions do not match in a multivar call. */
Expand Down Expand Up @@ -963,13 +959,6 @@ extern "C" {
int PIOc_set_fill(int ncid, int fillmode, int *old_modep);
int PIOc_def_var_fill(int ncid, int varid, int no_fill, const void *fill_value);
int PIOc_inq_var_fill(int ncid, int varid, int *no_fill, void *fill_valuep);
#ifdef NC_HAS_BZ2
int PIOc_inq_var_bzip2(int ncid, int varid, int* hasfilterp, int *levelp);
#endif
#ifdef NC_HAS_ZSTD
int PIOc_def_var_zstandard(int ncid, int varid, int level);
int PIOc_inq_var_zstandard(int ncid, int varid, int* hasfilterp, int *levelp);
#endif
int PIOc_rename_var(int ncid, int varid, const char *name);

/* These variable settings only apply to netCDF-4 files. */
Expand Down Expand Up @@ -1268,17 +1257,6 @@ extern "C" {
int PIOc_put_vard_ulonglong(int ncid, int varid, int decompid, const PIO_Offset recnum,
const unsigned long long *op);

#ifdef NC_HAS_PAR_FILTERS
int PIOc_def_var_filter(int ncid, int varid,unsigned int id, size_t nparams, unsigned int *params);
int PIOc_inq_var_filter_ids(int ncid, int varid, size_t *nfiltersp, unsigned int *ids);
int PIOc_inq_var_filter_info(int ncid, int varid, unsigned int id, size_t *nparamsp, unsigned int *params );
int PIOc_inq_filter_avail(int ncid, unsigned int id );
#endif
#ifdef NC_HAS_QUANTIZE
int PIOc_def_var_quantize(int ncid, int varid, int quantize_mode, int nsd );
int PIOc_inq_var_quantize(int ncid, int varid, int *quantize_mode, int *nsdp );
#endif

/* These functions are for the netCDF integration layer. */
int nc_def_iosystem(MPI_Comm comp_comm, int num_iotasks, int stride, int base, int rearr,
int *iosysidp);
Expand Down Expand Up @@ -1357,6 +1335,19 @@ extern "C" {
int nc_put_vard_ulonglong(int ncid, int varid, int decompid, const size_t recnum,
const unsigned long long *op);

/* These functions are for the GDAL integration layer. MSL - 9/7/2023 */
int GDALc_inq_fieldid(int fileid, const char *name, int *varidp);
int GDALc_inq_timeid(int fileid, int *timeid); // Is there a field of type OFTDate, OFTTime, or OFTDateTime?
// int GDALc_openfile(int iosysid, GDALDatasetH *hDSp, int *iotype, const char *fname, bool mode);
int GDALc_openfile(int iosysid, int *fileIDp, GDALDatasetH *hDSp, int *iotype, const char *fname, bool mode);
int GDALc_sync(int fileid);
int GDALc_shp_get_int_field(int fileid);
int GDALc_shp_get_double_field(int fileid, int varid, const size_t *startp,
const size_t *countp, double *ip);
int GDALc_createfile(int iosysid, int *fileidp, int *iotype, const char *fname, bool mode);
int GDALc_createfile_shp(int iosysid, int *fileidp, int *iotype, const char *filename, bool mode);
int GDALc_def_field(int fileid, const char *name, int xtype, int *varidp);

#if defined(__cplusplus)
}
#endif
Expand Down
Loading