diff --git a/CMake/cdat_modules/cffi_deps.cmake b/CMake/cdat_modules/cffi_deps.cmake index 757b6f38a6..3e06205106 100644 --- a/CMake/cdat_modules/cffi_deps.cmake +++ b/CMake/cdat_modules/cffi_deps.cmake @@ -1 +1 @@ -set(cffi_deps ${pip_pkg} ${six_pkg} ${ffi_pkg}) +set(CFFI_deps ${pip_pkg} ${six_pkg} ${ffi_pkg} ${pycparser_pkg} ) diff --git a/CMake/cdat_modules/cython_pkg.cmake b/CMake/cdat_modules/cython_pkg.cmake index d9d056574a..810010bab4 100644 --- a/CMake/cdat_modules/cython_pkg.cmake +++ b/CMake/cdat_modules/cython_pkg.cmake @@ -1,10 +1,10 @@ set(CYTHON_MAJOR 0) -set(CYTHON_MINOR 21) -set(CYTHON_PATCH 2) -set(CYTHON_VERSION ${CYTHON_MAJOR}.${CYTHON_MINOR}.${CYTHON_PATCH}) +set(CYTHON_MINOR 22) +set(CYTHON_PATCH ) +set(CYTHON_VERSION ${CYTHON_MAJOR}.${CYTHON_MINOR}) set(CYTHON_URL ${LLNL_URL} ) set(CYTHON_GZ Cython-${CYTHON_VERSION}.tar.gz) -set(CYTHON_MD5 d21adb870c75680dc857cd05d41046a4) +set(CYTHON_MD5 e67b03e8b3667c8e4e7c774ef2e2b638) set(CYTHON_SOURCE ${CYTHON_URL}/${CYTHON_GZ}) add_cdat_package_dependent(Cython "" "" OFF "CDAT_BUILD_LEAN" OFF) diff --git a/CMake/cdat_modules/hdf5_deps.cmake b/CMake/cdat_modules/hdf5_deps.cmake index 895eba1367..45a66d741a 100644 --- a/CMake/cdat_modules/hdf5_deps.cmake +++ b/CMake/cdat_modules/hdf5_deps.cmake @@ -1 +1,4 @@ set(HDF5_deps ${pkgconfig_pkg} ${libxml2_pkg} ${libxslt_pkg} ${zlib_pkg}) +if (CDAT_BUILD_PARALLEL) + list(APPEND HDF5_deps ${mpi_pkg}) +endif() diff --git a/CMake/cdat_modules/hdf5_external.cmake b/CMake/cdat_modules/hdf5_external.cmake index f89a5b1a11..7f20675f7d 100644 --- a/CMake/cdat_modules/hdf5_external.cmake +++ b/CMake/cdat_modules/hdf5_external.cmake @@ -5,7 +5,15 @@ set(HDF5_install "${cdat_EXTERNALS}") configure_file(${cdat_CMAKE_SOURCE_DIR}/cdat_modules_extra/hdf5_patch_step.cmake.in ${cdat_CMAKE_BINARY_DIR}/hdf5_patch_step.cmake @ONLY) - +if (CDAT_BUILD_PARALLEL) + set(hdf5_configure_args "--enable-parallel") + set(hdf5_additional_cflags "-w -fPIC") + set(configure_file "cdatmpi_configure_step.cmake") +else() + set(hdf5_configure_args "") + set(hdf5_additional_cflags "-w") + set(configure_file "cdat_configure_step.cmake") +endif() # we disable HDF5 warnings because it has way too many of them. ExternalProject_Add(HDF5 DOWNLOAD_DIR ${CDAT_PACKAGE_CACHE_DIR} @@ -15,7 +23,9 @@ ExternalProject_Add(HDF5 URL_MD5 ${HDF5_MD5} BUILD_IN_SOURCE 1 #PATCH_COMMAND ${CMAKE_COMMAND} -DWORKING_DIR= -P ${cdat_CMAKE_BINARY_DIR}/hdf5_patch_step.cmake - CONFIGURE_COMMAND ${CMAKE_COMMAND} -DADDITIONAL_CFLAGS=-w -DADDITIONAL_CPPFPAGS=-w -DINSTALL_DIR= -DWORKING_DIR= -P ${cdat_CMAKE_BINARY_DIR}/cdat_configure_step.cmake + CONFIGURE_COMMAND ${CMAKE_COMMAND} -DCONFIGURE_ARGS=${hdf5_configure_args} -DADDITIONAL_CFLAGS=${hdf5_additional_cflags} -DADDITIONAL_CPPFPAGS=-w -DINSTALL_DIR= -DWORKING_DIR= -P ${cdat_CMAKE_BINARY_DIR}/${configure_file} + BUILD_COMMAND ${CMAKE_COMMAND} -Dmake=$(MAKE) -DWORKING_DIR= -P ${cdat_CMAKE_BINARY_DIR}/cdat_make_step.cmake + INSTALL_COMMAND ${CMAKE_COMMAND} -DWORKING_DIR= -P ${cdat_CMAKE_BINARY_DIR}/cdat_install_step.cmake LOG_BUILD 1 DEPENDS ${HDF5_deps} ${ep_log_options} diff --git a/CMake/cdat_modules/hdf5_pkg.cmake b/CMake/cdat_modules/hdf5_pkg.cmake index 9970a01bdc..4599c9c95b 100644 --- a/CMake/cdat_modules/hdf5_pkg.cmake +++ b/CMake/cdat_modules/hdf5_pkg.cmake @@ -1,9 +1,9 @@ set(HDF5_MAJOR_SRC 1) set(HDF5_MINOR_SRC 8) -set(HDF5_PATCH_SRC 13) +set(HDF5_PATCH_SRC 15) set(HDF5_URL ${LLNL_URL}) set(HDF5_GZ hdf5-${HDF5_MAJOR_SRC}.${HDF5_MINOR_SRC}.${HDF5_PATCH_SRC}.tar.gz) -set(HDF5_MD5 c03426e9e77d7766944654280b467289) +set(HDF5_MD5 03cccb5b33dbe975fdcd8ae9dc021f24 ) set (nm HDF5) string(TOUPPER ${nm} uc_nm) diff --git a/CMake/cdat_modules/netcdf_deps.cmake b/CMake/cdat_modules/netcdf_deps.cmake index b37a27d263..c8da9fa7bf 100644 --- a/CMake/cdat_modules/netcdf_deps.cmake +++ b/CMake/cdat_modules/netcdf_deps.cmake @@ -1 +1,4 @@ set(NetCDF_deps ${pkgconfig_pkg} ${hdf5_pkg} ${curl_pkg} ${zlib_pkg} ${jpeg_pkg} ) +if (CDAT_BUILD_PARALLEL) + list(APPEND NetCDF_deps ${mpi_pkg} ) +endif() diff --git a/CMake/cdat_modules/netcdf_external.cmake b/CMake/cdat_modules/netcdf_external.cmake index eecfa97419..3135cff493 100644 --- a/CMake/cdat_modules/netcdf_external.cmake +++ b/CMake/cdat_modules/netcdf_external.cmake @@ -1,6 +1,11 @@ set(netcdf_source "${CMAKE_CURRENT_BINARY_DIR}/build/netcdf") set(netcdf_install "${cdat_EXTERNALS}") set(netcdf_configure_args "--enable-netcdf-4") +if (CDAT_BUILD_PARALLEL) + set(configure_file "cdatmpi_configure_step.cmake") +else() + set(configure_file "cdat_configure_step.cmake") +endif() configure_file(${cdat_CMAKE_SOURCE_DIR}/cdat_modules_extra/netcdf_patch_step.cmake.in ${cdat_CMAKE_BINARY_DIR}/netcdf_patch_step.cmake @@ -17,7 +22,9 @@ ExternalProject_Add(NetCDF URL_MD5 ${NC4_MD5} BUILD_IN_SOURCE 1 PATCH_COMMAND ${netcdf_PATCH_COMMAND} - CONFIGURE_COMMAND ${CMAKE_COMMAND} -DINSTALL_DIR= -DWORKING_DIR= -D CONFIGURE_ARGS=${netcdf_configure_args} -P ${cdat_CMAKE_BINARY_DIR}/cdat_configure_step.cmake + CONFIGURE_COMMAND ${CMAKE_COMMAND} -DINSTALL_DIR= -DWORKING_DIR= -DCONFIGURE_ARGS=${netcdf_configure_args} -P ${cdat_CMAKE_BINARY_DIR}/${configure_file} + BUILD_COMMAND ${CMAKE_COMMAND} -Dmake=$(MAKE) -DWORKING_DIR= -P ${cdat_CMAKE_BINARY_DIR}/cdat_make_step.cmake + INSTALL_COMMAND ${CMAKE_COMMAND} -DWORKING_DIR= -P ${cdat_CMAKE_BINARY_DIR}/cdat_install_step.cmake DEPENDS ${NetCDF_deps} ${ep_log_options} ) diff --git a/CMake/cdat_modules/netcdf_pkg.cmake b/CMake/cdat_modules/netcdf_pkg.cmake index 2792662978..9ea111ad8a 100644 --- a/CMake/cdat_modules/netcdf_pkg.cmake +++ b/CMake/cdat_modules/netcdf_pkg.cmake @@ -1,9 +1,9 @@ set(NC4_MAJOR_SRC 4) set(NC4_MINOR_SRC 3) -set(NC4_PATCH_SRC 2) +set(NC4_PATCH_SRC 3.1) set(NC4_URL ${LLNL_URL}) set(NC4_GZ netcdf-${NC4_MAJOR_SRC}.${NC4_MINOR_SRC}.${NC4_PATCH_SRC}.tar.gz) -set(NC4_MD5 2fd2365e1fe9685368cd6ab0ada532a0) +set(NC4_MD5 5c9dad3705a3408d27f696e5b31fb88c ) set (nm NC4) string(TOUPPER ${nm} uc_nm) diff --git a/CMake/cdat_modules/pnetcdf_deps.cmake b/CMake/cdat_modules/pnetcdf_deps.cmake new file mode 100644 index 0000000000..9b1966cce1 --- /dev/null +++ b/CMake/cdat_modules/pnetcdf_deps.cmake @@ -0,0 +1 @@ +set(PNETCDF_deps ${pkgconfig_pkg} ${mpi_pkg}) diff --git a/CMake/cdat_modules/pnetcdf_external.cmake b/CMake/cdat_modules/pnetcdf_external.cmake new file mode 100644 index 0000000000..431348b850 --- /dev/null +++ b/CMake/cdat_modules/pnetcdf_external.cmake @@ -0,0 +1,17 @@ +set(pnetcdf_source "${CMAKE_CURRENT_BINARY_DIR}/build/pnetcdf") +set(pnetcdf_install "${cdat_EXTERNALS}") +set(pnetcdf_configure_args "--with-mpi=${cdat_EXTERNALS}") +set(pnetcdf_additional_cflags "-fPIC") + +ExternalProject_Add(PNETCDF + LIST_SEPARATOR ^^ + DOWNLOAD_DIR ${CDAT_PACKAGE_CACHE_DIR} + SOURCE_DIR ${pnetcdf_source} + INSTALL_DIR ${pnetcdf_install} + URL ${PNETCDF_URL}/${PNETCDF_GZ} + URL_MD5 ${PNETCDF_MD5} + BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND ${CMAKE_COMMAND} -DADDITIONAL_CFLAGS=${pnetcdf_additional_cflags} -DINSTALL_DIR= -DWORKING_DIR= -D CONFIGURE_ARGS=${pnetcdf_configure_args} -P ${cdat_CMAKE_BINARY_DIR}/cdat_configure_step.cmake + DEPENDS ${PNETCDF_deps} + ${ep_log_options} +) diff --git a/CMake/cdat_modules/pnetcdf_pkg.cmake b/CMake/cdat_modules/pnetcdf_pkg.cmake new file mode 100644 index 0000000000..02cf48e192 --- /dev/null +++ b/CMake/cdat_modules/pnetcdf_pkg.cmake @@ -0,0 +1,13 @@ +set(PNETCDF_MAJOR_SRC 1) +set(PNETCDF_MINOR_SRC 6) +set(PNETCDF_PATCH_SRC 0) +set(PNETCDF_URL ${LLNL_URL}) +set(PNETCDF_GZ parallel-netcdf-${PNETCDF_MAJOR_SRC}.${PNETCDF_MINOR_SRC}.${PNETCDF_PATCH_SRC}.tar.gz) +set(PNETCDF_MD5 4893a50ddcd487a312c64383bdeb2631) + +set (nm PNETCDF) +string(TOUPPER ${nm} uc_nm) +set(${uc_nm}_VERSION ${${nm}_MAJOR_SRC}.${${nm}_MINOR_SRC}.${${nm}_PATCH_SRC}) +set(PNETCDF_SOURCE ${PNETCDF_URL}/${PNETCDF_GZ}) + +add_cdat_package(PNETCDF "" "" OFF) diff --git a/CMake/cdat_modules/pycparser_deps.cmake b/CMake/cdat_modules/pycparser_deps.cmake new file mode 100644 index 0000000000..3efd2d4eef --- /dev/null +++ b/CMake/cdat_modules/pycparser_deps.cmake @@ -0,0 +1 @@ +set(PYCPARSER_deps ${python_pkg} ${pip_pkg}) diff --git a/CMake/cdat_modules/pycparser_external.cmake b/CMake/cdat_modules/pycparser_external.cmake new file mode 100644 index 0000000000..f9b317f4f1 --- /dev/null +++ b/CMake/cdat_modules/pycparser_external.cmake @@ -0,0 +1,6 @@ + +# create an external project to install MyProxyClient, +# and configure and build it +set(nm PYCPARSER) + +include(pipinstaller) diff --git a/CMake/cdat_modules/pycparser_pkg.cmake b/CMake/cdat_modules/pycparser_pkg.cmake new file mode 100644 index 0000000000..873a293dde --- /dev/null +++ b/CMake/cdat_modules/pycparser_pkg.cmake @@ -0,0 +1,10 @@ +set(PYCPARSER_MAJOR_SRC 2) +set(PYCPARSER_MINOR_SRC 13) +set(PYCPARSER_PATCH_SRC ) + +set(PYCPARSER_VERSION ${PYCPARSER_MAJOR_SRC}.${PYCPARSER_MINOR_SRC}) +set(PYCPARSER_GZ pycparser-${PYCPARSER_VERSION}.tar.gz) +set(PYCPARSER_SOURCE ${LLNL_URL}/${PYCPARSER_GZ}) +set(PYCPARSER_MD5 e4fe1a2d341b22e25da0d22f034ef32f ) + +add_cdat_package_dependent(PYCPARSER "" "" ON "CDAT_BUILD_LEAN" OFF) diff --git a/CMake/cdat_modules/pyopenssl_deps.cmake b/CMake/cdat_modules/pyopenssl_deps.cmake index e85b77980b..6ab54642e1 100644 --- a/CMake/cdat_modules/pyopenssl_deps.cmake +++ b/CMake/cdat_modules/pyopenssl_deps.cmake @@ -1 +1 @@ -set(PYOPENSSL_deps ${python_pkg} ${pip_pkg}) +set(PYOPENSSL_deps ${python_pkg} ${pip_pkg} ${six_pkg} ${cryptography_pkg} ${cffi_pkg} ${ffi_pkg} ${pycparser_pkg} ) diff --git a/CMake/cdat_modules/scipy_pkg.cmake b/CMake/cdat_modules/scipy_pkg.cmake index 031e2b9c85..473ada7c01 100644 --- a/CMake/cdat_modules/scipy_pkg.cmake +++ b/CMake/cdat_modules/scipy_pkg.cmake @@ -1,12 +1,12 @@ set(SCIPY_MAJOR 0) -set(SCIPY_MINOR 10) +set(SCIPY_MINOR 16) set(SCIPY_PATCH 0) -set(SCIPY_MAJOR_SRC dde07a64407ffaa9442b3d8298c6c26ff91fb384) -set(SCIPY_MINOR_SRC) -set(SCIPY_PATCH_SRC) +set(SCIPY_MAJOR_SRC 0) +set(SCIPY_MINOR_SRC 16) +set(SCIPY_PATCH_SRC 0b2) set(SCIPY_URL ${LLNL_URL}) -set(SCIPY_GZ scipy-dde07a64407ffaa9442b3d8298c6c26ff91fb384.zip) -set(SCIPY_MD5 03fed4942984c0220615fac2d8d675c7) +set(SCIPY_GZ scipy-${SCIPY_MAJOR_SRC}.${SCIPY_MINOR_SRC}.${SCIPY_PATCH_SRC}.tar.gz) +set(SCIPY_MD5 cf2ca99b54a3951ecafb5c95730aa17f ) set(SCIPY_SOURCE ${SCIPY_URL}/${SCIPY_GZ}) set (nm SCIPY) diff --git a/CMake/cdat_modules_extra/cdat_common_environment.cmake.in b/CMake/cdat_modules_extra/cdat_common_environment.cmake.in index c9bf11dfbc..cdaeb524b6 100644 --- a/CMake/cdat_modules_extra/cdat_common_environment.cmake.in +++ b/CMake/cdat_modules_extra/cdat_common_environment.cmake.in @@ -1,12 +1,12 @@ message("[INFO] ADDITIONAL CFLAGS ${ADDITIONAL_CFLAGS}") set(ENV{PATH} "@cdat_EXTERNALS@/bin:$ENV{PATH}") -set(ENV{@LIBRARY_PATH@} "@CMAKE_INSTALL_PREFIX@/lib:@cdat_EXTERNALS@/lib:@cdat_EXTERNALS@/lib/paraview-@PARAVIEW_MAJOR@.@PARAVIEW_MINOR@:$ENV{@LIBRARY_PATH@}") +set(ENV{@LIBRARY_PATH@} "@CMAKE_INSTALL_PREFIX@/lib:@cdat_EXTERNALS@/lib:@cdat_EXTERNALS@/lib64:@cdat_EXTERNALS@/lib/paraview-@PARAVIEW_MAJOR@.@PARAVIEW_MINOR@:$ENV{@LIBRARY_PATH@}") if (NOT DEFINED SKIP_LDFLAGS) - set(ENV{LDFLAGS} "-L@cdat_EXTERNALS@/lib @cdat_external_link_directories@ @cdat_rpath_flag@@CMAKE_INSTALL_PREFIX@/lib @cdat_rpath_flag@@cdat_EXTERNALS@/lib") + set(ENV{LDFLAGS} "-L@cdat_EXTERNALS@/lib -L@cdat_EXTERNALS@/lib64 @cdat_external_link_directories@ -Wl,-rpath,@cdat_EXTERNALS@/lib64 @cdat_rpath_flag@@CMAKE_INSTALL_PREFIX@/lib @cdat_rpath_flag@@cdat_EXTERNALS@/lib") endif() -set(ENV{CFLAGS} "-I@cdat_EXTERNALS@/include @cdat_osx_flags@ @cdat_external_include_directories@ ${ADDITIONAL_CFLAGS}") -set(ENV{CPPFLAGS} "-I@cdat_EXTERNALS@/include @cdat_osx_cppflags@ @cdat_external_include_directories@ ${ADDITIONAL_CPPFLAGS}") -set(ENV{CXXFLAGS} "-I@cdat_EXTERNALS@/include @cdat_osx_cxxflags@ ${ADDITIONAL_CXXFLAGS}") +set(ENV{CFLAGS} "-I@cdat_EXTERNALS@/include -I@cdat_EXTERNALS@/lib/libffi-3.1/include @cdat_osx_flags@ @cdat_external_include_directories@ ${ADDITIONAL_CFLAGS}") +set(ENV{CPPFLAGS} "-I@cdat_EXTERNALS@/include -I@cdat_EXTERNALS@/lib/libffi-3.1/include @cdat_osx_cppflags@ @cdat_external_include_directories@ ${ADDITIONAL_CPPFLAGS}") +set(ENV{CXXFLAGS} "-I@cdat_EXTERNALS@/include -I@cdat_EXTERNALS@/lib/libffi-3.1/include @cdat_osx_cxxflags@ ${ADDITIONAL_CXXFLAGS}") set(ENV{PKG_CONFIG_PATH} "@cdat_EXTERNALS@/lib/pkgconfig:/usr/lib64/pkgconfig:/usr/lib/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/share/pkgconfig:$ENV{PKG_CONFIG_PATH}") set(ENV{PKG_CONFIG} "@cdat_PKG_CONFIG_EXECUTABLE@") set(ENV{FC} "") diff --git a/CMake/cdat_modules_extra/cdatmpi_configure_step.cmake.in b/CMake/cdat_modules_extra/cdatmpi_configure_step.cmake.in new file mode 100644 index 0000000000..826b0e209b --- /dev/null +++ b/CMake/cdat_modules_extra/cdatmpi_configure_step.cmake.in @@ -0,0 +1,21 @@ +set(ENV{PKG_CONFIG_PATH} "@cdat_EXTERNALS@/lib/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib64/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig:$ENV{PKG_CONFIG_PATH}") +set(ENV{PKG_CONFIG} "@cdat_PKG_CONFIG_EXECUTABLE@") + +include(@cdat_CMAKE_BINARY_DIR@/cdat_common_environment.cmake) + +set(ENV{CC} mpicc) + +message("CONFIGURE_ARGS IS ${CONFIGURE_ARGS}") +message("LD_ARGS IS $ENV{@LIBRARY_PATH@}") +message("CFLAGS : $ENV{CFLAGS}") + +execute_process( + COMMAND env CC=$ENV{CC} CFLAGS=$ENV{CFLAGS} LD_LIBRARY_PATH=$ENV{@LIBRARY_PATH@} DYLD_FALLBACK_LIBRARY_PATH=$ENV{@LIBRARY_PATH@} @LIBRARY_PATH@=$ENV{@LIBRARY_PATH@} PKG_CONFIG=$ENV{PKG_CONFIG} PKG_CONFIG_PATH=$ENV{PKG_CONFIG_PATH} sh configure --prefix=${INSTALL_DIR} ${CONFIGURE_ARGS} + WORKING_DIRECTORY "${WORKING_DIR}" + RESULT_VARIABLE res) + +if(NOT ${res} EQUAL 0) + message("Config Errors detected: \n${CDAT_OUT}\n${CDAT_ERR}") + message(FATAL_ERROR "Error in config") +endif() +message("Config succeeded.") diff --git a/CMake/cmake_modules/pipinstaller.cmake b/CMake/cmake_modules/pipinstaller.cmake index 2c0165ab5c..34ef1648fe 100644 --- a/CMake/cmake_modules/pipinstaller.cmake +++ b/CMake/cmake_modules/pipinstaller.cmake @@ -1,7 +1,7 @@ # create an external project to install MyProxyClient, # and configure and build it -include(@cdat_CMAKE_BINARY_DIR@/cdat_common_environment.cmake) +include(${cdat_CMAKE_BINARY_DIR}/cdat_common_environment.cmake) string(TOUPPER ${nm} uc_nm) if(NOPREFIXOPT ) @@ -33,7 +33,7 @@ ExternalProject_Add(${nm} BUILD_IN_SOURCE 1 CONFIGURE_COMMAND "" BUILD_COMMAND "" - INSTALL_COMMAND env PYTHONPATH=${PYTHONPATH} ${USR_ENVS} ${PYTHON_EXECUTABLE} setup.py install ${PRFX} + INSTALL_COMMAND env LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH} CFLAGS=$ENV{CFLAGS} LDFLAGS=$ENV{LDFLAGS} PKG_CONFIG_PATH=$ENV{PKG_CONFIG_PATH} PYTHONPATH=${PYTHONPATH} ${USR_ENVS} ${PYTHON_EXECUTABLE} setup.py install ${PRFX} DEPENDS ${${nm}_deps} ${ep_log_options} ) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ff1efb394..0e32c4a023 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -296,6 +296,7 @@ if (CDAT_BUILD_ESGF) endif() set(CDAT_BUILD_MODE "DEFAULT" CACHE STRING "Build mode for CDAT ") set_property(CACHE CDAT_BUILD_MODE PROPERTY STRINGS "DEFAULT" "ALL" "LEAN") +message([INFO] BUILD MODE} ${CDAT_BUILD_MODE}) # Set the state of LEAN all based on the MODE if (CDAT_BUILD_MODE STREQUAL "LEAN") @@ -304,9 +305,11 @@ if (CDAT_BUILD_MODE STREQUAL "LEAN") elseif (CDAT_BUILD_MODE STREQUAL "ALL") set(CDAT_BUILD_LEAN OFF) set(CDAT_BUILD_ALL ON) -else() +elseif (CDAT_BUILD_MODE STREQUAL "DEFAULT") set(CDAT_BUILD_LEAN OFF) set(CDAT_BUILD_ALL OFF) +else() + message(FATAL_ERROR "[ERROR] Unknown CDAT_BUILD_MODE \"${CDAT_BUILD_MODE}\" VALID MODES ARE \"DEFAULT\" \"ALL\" \"LEAN\"") endif() # First of all if LEAN then turn OFF GRAPHICS and PARALLEL @@ -486,8 +489,12 @@ include(libcf_pkg) include(libdrs_pkg) include(matplotlib_pkg) include(six_pkg) +include(cryptography_pkg) +include(cffi_pkg) +include(ffi_pkg) include(dateutils_pkg) include(pyparsing_pkg) +include(pycparser_pkg) include(md5_pkg) include(mpi4py_pkg) include(pyopenssl_pkg) @@ -601,8 +608,8 @@ configure_file(${cdat_CMAKE_SOURCE_DIR}/cdat_modules_extra/cleanenv_configure_st @ONLY ) -configure_file(${cdat_CMAKE_SOURCE_DIR}/cdat_modules_extra/cdat_configure_step.cmake.in - ${cdat_CMAKE_BINARY_DIR}/cdat_configure_step.cmake +configure_file(${cdat_CMAKE_SOURCE_DIR}/cdat_modules_extra/cdatmpi_configure_step.cmake.in + ${cdat_CMAKE_BINARY_DIR}/cdatmpi_configure_step.cmake @ONLY ) @@ -675,6 +682,7 @@ set(SETUP_LIBRARY_PATHS "Externals/lib/paraview-${PARAVIEW_MAJOR}.${PARAVIEW_MINOR} " "Externals/lib/R/lib " "Externals/lib " + "Externals/lib64 " "lib " ) string(REPLACE ";" " " SETUP_LIBRARY_PATHS ${SETUP_LIBRARY_PATHS}) diff --git a/Packages/cdms2/Lib/__init__.py b/Packages/cdms2/Lib/__init__.py index c1b560edbe..7287903472 100644 --- a/Packages/cdms2/Lib/__init__.py +++ b/Packages/cdms2/Lib/__init__.py @@ -27,7 +27,14 @@ from grid import createGenericGrid, createGlobalMeanGrid, createRectGrid, createUniformGrid, createZonalGrid, setClassifyGrids, createGaussianGrid, writeScripGrid, isGrid # Dataset functions -from dataset import createDataset, openDataset, useNetcdf3, getNetcdfClassicFlag, getNetcdfShuffleFlag, getNetcdfDeflateFlag, getNetcdfDeflateLevelFlag, setNetcdfClassicFlag, setNetcdfShuffleFlag, setNetcdfDeflateFlag, setNetcdfDeflateLevelFlag, setCompressionWarnings +from dataset import createDataset, openDataset, useNetcdf3, \ + getNetcdfClassicFlag, getNetcdfShuffleFlag, getNetcdfDeflateFlag, getNetcdfDeflateLevelFlag,\ + setNetcdfClassicFlag, setNetcdfShuffleFlag, setNetcdfDeflateFlag, setNetcdfDeflateLevelFlag,\ + setNetcdfUseNCSwitchModeFlag,getNetcdfUseNCSwitchModeFlag,\ + setCompressionWarnings,\ + setNetcdf4Flag, getNetcdf4Flag,\ + setNetcdfUseParallelFlag, getNetcdfUseParallelFlag + open = openDataset # Database functions diff --git a/Packages/cdms2/Lib/cdmsobj.py b/Packages/cdms2/Lib/cdmsobj.py index f60e82c72a..14c2d9bf0a 100644 --- a/Packages/cdms2/Lib/cdmsobj.py +++ b/Packages/cdms2/Lib/cdmsobj.py @@ -463,7 +463,11 @@ def _setatts(self,value): def __init__(self, node = None): if not hasattr(self,'___cdms_internals__'): - self.__dict__['___cdms_internals__']=['__cdms_internals__','___cdms_internals__','_node_','parent','attributes','shape','autoApiInfo'] + self.__dict__['___cdms_internals__']=[ + '__cdms_internals__','___cdms_internals__', + '_node_','_obj_', + '_numericType_','_grid_','_bounds_', + 'parent','attributes','shape','autoApiInfo'] self.attributes={} self._node_ = node if node is not None: diff --git a/Packages/cdms2/Lib/dataset.py b/Packages/cdms2/Lib/dataset.py index 6b13f646ab..9320567652 100644 --- a/Packages/cdms2/Lib/dataset.py +++ b/Packages/cdms2/Lib/dataset.py @@ -99,6 +99,33 @@ def setCompressionWarnings(value=None): raise CMDSError("setCompressionWarnings flags must be yes/no or 1/0, or None to invert it") return _showCompressWarnings +def setNetcdfUseNCSwitchModeFlag(value): + """ Tells cdms2 to switch constantly between netcdf define/write modes""" + if value not in [True,False,0,1]: + raise CDMSError("Error UseNCSwitchMode flag must be 1(can use)/0(do not use) or true/False") + if value in [0,False]: + Cdunif.CdunifSetNCFLAGS("use_define_mode",0) + else: + Cdunif.CdunifSetNCFLAGS("use_define_mode",1) + +def setNetcdfUseParallelFlag(value): + """ Sets NetCDF classic flag value""" + if value not in [True,False,0,1]: + raise CDMSError("Error UseParallel flag must be 1(can use)/0(do not use) or true/False") + if value in [0,False]: + Cdunif.CdunifSetNCFLAGS("use_parallel",0) + else: + Cdunif.CdunifSetNCFLAGS("use_parallel",1) + +def setNetcdf4Flag(value): + """ Sets NetCDF classic flag value""" + if value not in [True,False,0,1]: + raise CDMSError("Error NetCDF4 flag must be 1/0 or true/False") + if value in [0,False]: + Cdunif.CdunifSetNCFLAGS("netcdf4",0) + else: + Cdunif.CdunifSetNCFLAGS("netcdf4",1) + def setNetcdfClassicFlag(value): """ Sets NetCDF classic flag value""" if value not in [True,False,0,1]: @@ -132,6 +159,18 @@ def setNetcdfDeflateLevelFlag(value): raise CDMSError("Error NetCDF deflate_level flag must be an integer < 10") Cdunif.CdunifSetNCFLAGS("deflate_level",value) +def getNetcdfUseNCSwitchModeFlag(): + """ Returns NetCDF UseParallel flag value""" + return Cdunif.CdunifGetNCFLAGS("use_define_mode") + +def getNetcdfUseParallelFlag(): + """ Returns NetCDF UseParallel flag value""" + return Cdunif.CdunifGetNCFLAGS("use_parallel") + +def getNetcdf4Flag(): + """ Returns NetCDF4 flag value""" + return Cdunif.CdunifGetNCFLAGS("netcdf4") + def getNetcdfClassicFlag(): """ Returns NetCDF classic flag value""" return Cdunif.CdunifGetNCFLAGS("classic") @@ -217,7 +256,20 @@ def openDataset(uri,mode='r',template=None,dods=1,dpath=None, hostObj=None): datanode = load(path) else: # If the doesn't exist allow it to be created - if not os.path.exists(path): return CdmsFile(path,mode) + ##Ok mpi has issues with bellow we need to test this only with 1 rank + try: + import mpi4py + rk = mpi4py.MPI.COMM_WORLD.Get_rank() + except: + #no mpi + rk = 0 + + if not os.path.exists(path): + return CdmsFile(path,mode) + elif mode=="w": + if rk == 0 : + os.remove(path) + return CdmsFile(path,mode) # The file exists file1 = CdmsFile(path,"r") @@ -1129,7 +1181,7 @@ def createAxis(self,name,ar,unlimited=0): if self._status_=="closed": raise CDMSError(FileWasClosed + self.id) cufile = self._file_ - if ar is None or unlimited==1: + if ar is None or (unlimited==1 and getNetcdfUseParallelFlag()==0): cufile.createDimension(name,None) if ar is None: typecode = numpy.float @@ -1213,7 +1265,7 @@ def copyAxis(self, axis, newname=None, unlimited=0, index=None, extbounds=None): if newaxis.isVirtual(): if len(axis)!=len(newaxis): raise DuplicateAxisError(DuplicateAxis+newname) - elif unlimited==0: + elif unlimited==0 or (unlimited==1 and getNetcdfUseParallelFlag()!=0): if len(axis)!=len(newaxis) or numpy.alltrue(numpy.less(numpy.absolute(newaxis[:]-axis[:]),1.e-5))==0: raise DuplicateAxisError(DuplicateAxis+newname) else: @@ -1715,7 +1767,7 @@ def write(self, var, attributes=None, axes=None, extbounds=None, id=None, \ if _showCompressWarnings: if (Cdunif.CdunifGetNCFLAGS("shuffle")!=0) or (Cdunif.CdunifGetNCFLAGS("deflate")!=0) or (Cdunif.CdunifGetNCFLAGS("deflate_level")!=0): import warnings - warnings.warn("Since CDAT Version 5.2 File are now written with compression and shuffling\nYou can query different values of compression using the functions:\ncdms2.getNetcdfShuffleFlag() returning 1 if shuffling is enabled, 0 otherwise\ncdms2.getNetcdfDeflateFlag() returning 1 if deflate is used, 0 otherwise\ncdms2.getNetcdfDeflateLevelFlag() returning the level of compression for the deflate method\n\nIf you want to turn that off or set different values of compression use the functions:\ncdms2.setNetcdfShuffleFlag(value) ## where value is either 0 or 1\ncdms2.setNetcdfDeflateFlag(value) ## where value is either 0 or 1\ncdms2.setNetcdfDeflateLevelFlag(value) ## where value is a integer between 0 and 9 included\n\nTurning all values to 0 will produce NetCDF3 Classic files\n",Warning) + warnings.warn("Files are written with compression and shuffling\nYou can query different values of compression using the functions:\ncdms2.getNetcdfShuffleFlag() returning 1 if shuffling is enabled, 0 otherwise\ncdms2.getNetcdfDeflateFlag() returning 1 if deflate is used, 0 otherwise\ncdms2.getNetcdfDeflateLevelFlag() returning the level of compression for the deflate method\n\nIf you want to turn that off or set different values of compression use the functions:\nvalue = 0\ncdms2.setNetcdfShuffleFlag(value) ## where value is either 0 or 1\ncdms2.setNetcdfDeflateFlag(value) ## where value is either 0 or 1\ncdms2.setNetcdfDeflateLevelFlag(value) ## where value is a integer between 0 and 9 included\n\nTurning all values to 0 will produce NetCDF3 Classic files\nTo Force NetCDF4 output with classic format and no compressing use:\ncdms2.setNetcdf4Flag(1)\nNetCDF4 file with no shuffling or defalte and noclassic will be open for parallel i/o",Warning) # Make var an AbstractVariable if dtype is None and typecode is not None: diff --git a/Packages/cdms2/Lib/fvariable.py b/Packages/cdms2/Lib/fvariable.py index 2ebbe93cdd..4271e12c62 100644 --- a/Packages/cdms2/Lib/fvariable.py +++ b/Packages/cdms2/Lib/fvariable.py @@ -51,6 +51,7 @@ def assignValue(self,data): if self.parent is None: raise CDMSError, FileClosedWrite+self.id if numpy.ma.isMaskedArray(data): + if data.mask is not numpy.ma.nomask and not numpy.ma.allclose(data.mask,0): saveFill = data.fill_value if self.getMissing() is None: self.setMissing(saveFill) @@ -58,6 +59,7 @@ def assignValue(self,data): data.set_fill_value(self.getMissing()) self._obj_.assignValue(numpy.ma.filled(data)) if numpy.ma.isMaskedArray(data): + if data.mask is not numpy.ma.nomask and not numpy.ma.allclose(data.mask,0): data.set_fill_value(saveFill) def expertSlice (self, initslicelist): @@ -94,6 +96,7 @@ def __setitem__(self, index, value): if self.parent is None: raise CDMSError, FileClosedWrite+self.id if numpy.ma.isMaskedArray(value): + if value.mask is not numpy.ma.nomask and not numpy.ma.allclose(value.mask,0): saveFill = value.fill_value if self.getMissing() is None: self.setMissing(saveFill) @@ -101,6 +104,7 @@ def __setitem__(self, index, value): value.set_fill_value(self.getMissing()) apply(self._obj_.setitem,(index,numpy.ma.filled(value))) if numpy.ma.isMaskedArray(value): + if value.mask is not numpy.ma.nomask and not numpy.ma.allclose(value.mask,0): value.set_fill_value(saveFill) def __setslice__(self, low, high, value): @@ -109,8 +113,11 @@ def __setslice__(self, low, high, value): # Hack to prevent netCDF overflow error on 64-bit architectures high = min(Max32int, high) + if high == Max32int and self.rank()==0: + high=1 if numpy.ma.isMaskedArray(value): + if value.mask is not numpy.ma.nomask and not numpy.ma.allclose(value.mask,0): saveFill = value.fill_value if self.getMissing() is None: self.setMissing(saveFill) @@ -118,6 +125,7 @@ def __setslice__(self, low, high, value): value.set_fill_value(self.getMissing()) apply(self._obj_.setslice,(low,high,numpy.ma.filled(value))) if numpy.ma.isMaskedArray(value): + if value.mask is not numpy.ma.nomask and not numpy.ma.allclose(value.mask,0): value.set_fill_value(saveFill) def _getShape (self): @@ -132,7 +140,7 @@ def _getShape (self): def __setattr__(self, name, value): if hasattr(self, "parent") and self.parent is None: raise CDMSError, FileClosedWrite+self.id - if (not name in self.__cdms_internals__) and (value is not None) and (name[0]!='_'): + if (not name in self.__cdms_internals__) and (value is not None): try: setattr(self._obj_, name, value) except CdunifError: diff --git a/Packages/cdms2/Src/Cdunifmodule.c b/Packages/cdms2/Src/Cdunifmodule.c index b623597658..4d4c00da0e 100644 --- a/Packages/cdms2/Src/Cdunifmodule.c +++ b/Packages/cdms2/Src/Cdunifmodule.c @@ -12,6 +12,10 @@ /*#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION*/ #include "Python.h" #include "numpy/ndarrayobject.h" +#ifdef PARALLEL +#include "mpi.h" +#include "netcdf_par.h" +#endif #include "netcdf.h" #define _CDUNIF_MODULE @@ -25,7 +29,14 @@ int nc_def_var_deflate(int i,int j,int k,int l, int m) {return 0;}; int nc_def_var_chunking(int i,int j,int k,size_t *l) {return 0;}; #endif -int cdms_classic = 1; +int cdms_classic = 1 ; +int cdms_netcdf4 = 1 ; +int cdms_use_define_mode = 1 ; /* 0 (do not use) or 1 (can use) */ +#ifdef PARALLEL +int cdms_use_parallel = 1 ; /* 0 (do not use) or 1 (can use) */ +#else +int cdms_use_parallel = 0 ; /* 0 (do not use) or 1 (can use) */ +#endif int cdms_shuffle = 0 ; int cdms_deflate = 1 ; int cdms_deflate_level = 1 ; @@ -254,11 +265,21 @@ static int cdattname(PyCdunifFileObject *file, int varid, int attnum, char* name else return cuattname(file->id,varid,attnum,name); } + +#ifdef PARALLEL +/* function to test ncmode flags */ +int nc_flag_on(int mode, int flag) { + return ((mode & flag) == flag); +} +#endif + static int cdclose(PyCdunifFileObject *file){ - if (file->filetype==CuNetcdf) - return ncclose(file->id); - else - return cuclose(file->id); + if (file->filetype==CuNetcdf) { + return nc_close(file->id); + } + else { + return cuclose(file->id); + } } static int cddimget(PyCdunifFileObject *file, int dimid, void *values){ if (file->filetype==CuNetcdf){ @@ -279,7 +300,9 @@ static int cddimget(PyCdunifFileObject *file, int dimid, void *values){ int natts; cdfid = file->id; - if(ncdiminq(cdfid, dimid, dimname, &length)==-1){ + int ierr; + ierr = nc_inq_dim(cdfid, dimid, dimname, &length); + if(ierr != NC_NOERR ){ return -1; } @@ -323,8 +346,12 @@ static int cddimget(PyCdunifFileObject *file, int dimid, void *values){ return cudimget(file->id,dimid,values); } static int cddimid(PyCdunifFileObject *file, const char* name){ - if (file->filetype==CuNetcdf) - return ncdimid(file->id,name); + if (file->filetype==CuNetcdf) { + int ierr; + int dimid; + ierr = nc_inq_dimid(file->id,name,&dimid); + return dimid; + } else return cudimid(file->id,CU_GLOBAL,name); } @@ -348,7 +375,9 @@ static int cddiminq(PyCdunifFileObject *file, int dimid, char* dimname, char *di if (file->filetype==CuNetcdf) { cdfid = file->id; - if(ncdiminq(cdfid, dimid, dname, &len)==-1){ + int ierr; + ierr = nc_inq_dim(cdfid, dimid, dname, &len); + if(ierr != NC_NOERR){ return -1; } if(dimname) strncpy(dimname,dname,CU_MAX_NAME); @@ -417,8 +446,9 @@ static int cddiminq(PyCdunifFileObject *file, int dimid, char* dimname, char *di } } static int cdendef(PyCdunifFileObject *file){ - if (file->filetype==CuNetcdf) - return ncendef(file->id); + if (file->filetype==CuNetcdf) { + return nc_enddef(file->id); + } else return 0; } @@ -429,8 +459,16 @@ static int cdgeterr(PyCdunifFileObject *file){ return cugeterr(); } static int cdinquire(PyCdunifFileObject *file, int* ngdims, int* nvars, int* natts, int* recdim){ - if (file->filetype==CuNetcdf) - return ncinquire(file->id,ngdims,nvars,natts,recdim); + int ierr; + if (file->filetype==CuNetcdf) { + ierr = nc_inq(file->id,ngdims,nvars,natts,recdim); + if (ierr != NC_NOERR ) { + return -1; + } + else { + return ierr; + } + } else return cuinquire(file->id,ngdims,nvars,natts,recdim); } @@ -444,8 +482,19 @@ static int cdopen(const char* controlpath, int mode, CuFileType *filetype){ cuseterropts(saveopts); if (*filetype==CuUnknown) return -1; - if (*filetype==CuNetcdf) - return ncopen(controlpath,mode); + if (*filetype==CuNetcdf) { +#ifdef PARALLEL + int ierr; + int ncid; + ierr = nc_open_par(controlpath,NC_WRITE|NC_MPIIO,MPI_COMM_WORLD,MPI_INFO_NULL,&ncid); + if (ierr != NC_NOERR ) { /* ok it failed opening in regular netcdf*/ + ierr = nc_open(controlpath,mode,&ncid); + } + return ncid; +#else + return ncopen(controlpath,mode); +#endif + } else{ if (mode==NC_WRITE){ ncerr = 5; /* Write to read-only file */ @@ -456,8 +505,9 @@ static int cdopen(const char* controlpath, int mode, CuFileType *filetype){ } } static int cdredef(PyCdunifFileObject *file){ - if (file->filetype==CuNetcdf) - return ncredef(file->id); + if (file->filetype==CuNetcdf) { + return nc_redef(file->id); + } else return 0; } @@ -484,8 +534,10 @@ static int cdvarget1(PyCdunifFileObject *file, int varid, const long mindex[], v } } static int cdvargets(PyCdunifFileObject *file, int varid, const long start[], const long count[], const long stride[], void *values){ - if (file->filetype==CuNetcdf) - return ncvargetg(file->id,varid,start,count,stride,NULL,values); + if (file->filetype==CuNetcdf) { + int ierr; + return ncvargetg(file->id,varid,start,count,stride,NULL,values); + } else return cuvargets(file->id,varid,NULL,start,count,stride,0,values); } @@ -493,8 +545,15 @@ static int cdvarinq(PyCdunifFileObject *file, int varid, char* name, nc_type* da CuType cutype; int err; - if (file->filetype==CuNetcdf) - return ncvarinq(file->id,varid,name,datatype,ndims,dimids,natts); + if (file->filetype==CuNetcdf) { + err = nc_inq_var(file->id,varid,name,datatype,ndims,dimids,natts); + if (err != NC_NOERR ) { + return -1; + } + else { + return err; + } + } else{ err = cuvarinq(file->id,varid,name,&cutype,ndims,dimids,natts); if (datatype != NULL) @@ -536,67 +595,67 @@ nc_put_att_any(int ncid, int varid, const char *name, { switch (xtype) { case NC_BYTE: - return nc_put_att_uchar(ncid, varid, name, xtype, len, - (unsigned char *)data); + return nc_put_att_uchar(ncid, varid, name, xtype, len, + (unsigned char *)data); break; case NC_CHAR: - return nc_put_att_text(ncid, varid, name, len, - (char *)data); + return nc_put_att_text(ncid, varid, name, len, + (char *)data); break; case NC_SHORT: - return nc_put_att_short(ncid, varid, name, xtype, len, - (short *)data); + return nc_put_att_short(ncid, varid, name, xtype, len, + (short *)data); break; case NC_INT: - return nc_put_att_int(ncid, varid, name, xtype, len, - (int *)data); + return nc_put_att_int(ncid, varid, name, xtype, len, + (int *)data); break; case NC_FLOAT: - return nc_put_att_float(ncid, varid, name, xtype, len, - (float *)data); + return nc_put_att_float(ncid, varid, name, xtype, len, + (float *)data); break; case NC_DOUBLE: - return nc_put_att_double(ncid, varid, name, xtype, len, - (double *)data); + return nc_put_att_double(ncid, varid, name, xtype, len, + (double *)data); break; /* need the following #ifdef for linking against netcdf3 */ #ifdef NC_UBYTE case NC_UBYTE: - return nc_put_att_ubyte(ncid, varid, name, xtype, len, - (unsigned char *)data); + return nc_put_att_ubyte(ncid, varid, name, xtype, len, + (unsigned char *)data); break; #endif #ifdef NC_USHORT case NC_USHORT: - return nc_put_att_ushort(ncid, varid, name, xtype, len, - (unsigned short *)data); + return nc_put_att_ushort(ncid, varid, name, xtype, len, + (unsigned short *)data); break; #endif #ifdef NC_UINT case NC_UINT: - return nc_put_att_uint(ncid, varid, name, xtype, len, - (unsigned int *)data); + return nc_put_att_uint(ncid, varid, name, xtype, len, + (unsigned int *)data); break; #endif #ifdef NC_INT64 case NC_INT64: - return nc_put_att_longlong(ncid, varid, name, xtype, len, - (long long *)data); + return nc_put_att_longlong(ncid, varid, name, xtype, len, + (long long *)data); break; #endif #ifdef NC_UINT64 case NC_UINT64: - return nc_put_att_ulonglong(ncid, varid, name, xtype, len, - (unsigned long long *)data); + return nc_put_att_ulonglong(ncid, varid, name, xtype, len, + (unsigned long long *)data); break; #endif #ifdef NC_STRING case NC_STRING: - return nc_put_att_string(ncid, varid, name, len, - (char **)data); + return nc_put_att_string(ncid, varid, name, len, + (char **)data); break; - default: #endif + default: return NC_EINVAL; } } @@ -607,65 +666,64 @@ nc_put_var1_any(int ncid, int varid, nc_type xtype, const size_t *indexp, { switch (xtype) { case NC_BYTE: - return nc_put_var1_uchar(ncid, varid, indexp, (unsigned char *)data); + return nc_put_var1_uchar(ncid, varid, indexp, (unsigned char *)data); break; case NC_CHAR: - return nc_put_var1_text(ncid, varid, indexp, (char *)data); + return nc_put_var1_text(ncid, varid, indexp, (char *)data); break; case NC_SHORT: - return nc_put_var1_short(ncid, varid, indexp, (short *)data); + return nc_put_var1_short(ncid, varid, indexp, (short *)data); break; case NC_INT: - return nc_put_var1_int(ncid, varid, indexp, (int *)data); + return nc_put_var1_int(ncid, varid, indexp, (int *)data); break; case NC_FLOAT: - return nc_put_var1_float(ncid, varid, indexp, (float *)data); + return nc_put_var1_float(ncid, varid, indexp, (float *)data); break; case NC_DOUBLE: - return nc_put_var1_double(ncid, varid, indexp, (double *)data); + return nc_put_var1_double(ncid, varid, indexp, (double *)data); break; /* need the following #ifdef for linking against netcdf3 */ #ifdef NC_UBYTE case NC_UBYTE: - return nc_put_var1_ubyte(ncid, varid, indexp, - (unsigned char *)data); + return nc_put_var1_ubyte(ncid, varid, indexp, + (unsigned char *)data); break; #endif #ifdef NC_USHORT case NC_USHORT: - return nc_put_var1_ushort(ncid, varid, indexp, - (unsigned short *)data); + return nc_put_var1_ushort(ncid, varid, indexp, + (unsigned short *)data); break; #endif #ifdef NC_UINT case NC_UINT: - return nc_put_var1_uint(ncid, varid, indexp, - (unsigned int *)data); + return nc_put_var1_uint(ncid, varid, indexp, + (unsigned int *)data); break; #endif #ifdef NC_INT64 case NC_INT64: - return nc_put_var1_longlong(ncid, varid, indexp, - (long long *)data); + return nc_put_var1_longlong(ncid, varid, indexp, + (long long *)data); break; #endif #ifdef NC_UINT64 case NC_UINT64: - return nc_put_var1_ulonglong(ncid, varid, indexp, - (unsigned long long *)data); + return nc_put_var1_ulonglong(ncid, varid, indexp, + (unsigned long long *)data); break; #endif #ifdef NC_STRING case NC_STRING: - return nc_put_var1_string(ncid, varid, indexp, - (char **)data); + return nc_put_var1_string(ncid, varid, indexp, + (char **)data); break; #endif default: return NC_EINVAL; } } - static int nc_put_vars_any(int ncid, int varid, nc_type xtype, const size_t start[], const size_t count[], const ptrdiff_t stride[], @@ -673,67 +731,64 @@ nc_put_vars_any(int ncid, int varid, nc_type xtype, const size_t start[], { switch (xtype) { case NC_BYTE: - return nc_put_vars_uchar(ncid, varid, start, count, stride, - (unsigned char *)data); + return nc_put_vars_uchar(ncid, varid, start, count, stride, + (unsigned char *)data); break; case NC_CHAR: - return nc_put_vars_text(ncid, varid, start, count, stride, - (char *)data); + return nc_put_vars_text(ncid, varid, start, count, stride, + (char *)data); break; case NC_SHORT: - return nc_put_vars_short(ncid, varid, start, count, stride, - (short *)data); - break; + return nc_put_vars_short(ncid, varid, start, count, stride, + (short *)data); break; case NC_INT: - return nc_put_vars_int(ncid, varid, start, count, stride, - (int *)data); - break; + return nc_put_vars_int(ncid, varid, start, count, stride, + (int *)data); break; case NC_FLOAT: - return nc_put_vars_float(ncid, varid, start, count, stride, - (float *)data); - break; + return nc_put_vars_float(ncid, varid, start, count, stride, + (float *)data); break; case NC_DOUBLE: - return nc_put_vars_double(ncid, varid, start, count, stride, - (double *)data); + return nc_put_vars_double(ncid, varid, start, count, stride, + (double *)data); break; /* need the following #ifdef for linking against netcdf3 */ #ifdef NC_UBYTE case NC_UBYTE: - return nc_put_vars_ubyte(ncid, varid,start, count, stride, - (unsigned char *)data); + return nc_put_vars_ubyte(ncid, varid,start, count, stride, + (unsigned char *)data); break; #endif #ifdef NC_USHORT case NC_USHORT: - return nc_put_vars_ushort(ncid, varid,start, count, stride, - (unsigned short *)data); + return nc_put_vars_ushort(ncid, varid,start, count, stride, + (unsigned short *)data); break; #endif #ifdef NC_UINT case NC_UINT: - return nc_put_vars_uint(ncid, varid,start, count, stride, - (unsigned int *)data); + return nc_put_vars_uint(ncid, varid,start, count, stride, + (unsigned int *)data); break; #endif #ifdef NC_INT64 case NC_INT64: - return nc_put_vars_longlong(ncid, varid,start, count, stride, - (long long *)data); + return nc_put_vars_longlong(ncid, varid,start, count, stride, + (long long *)data); break; #endif #ifdef NC_UINT64 case NC_UINT64: - return nc_put_vars_ulonglong(ncid, varid,start, count, stride, - (unsigned long long *)data); + return nc_put_vars_ulonglong(ncid, varid,start, count, stride, + (unsigned long long *)data); break; #endif #ifdef NC_STRING case NC_STRING: - return nc_put_vars_string(ncid, varid,start, count, stride, - (char **)data); + return nc_put_vars_string(ncid, varid,start, count, stride, + (char **)data); break; #endif default: @@ -747,58 +802,58 @@ nc_get_att_any(int ncid, int varid, const char *name, { switch (xtype) { case NC_BYTE: - return nc_get_att_uchar(ncid, varid, name, (unsigned char *)data); + return nc_get_att_uchar(ncid, varid, name, (unsigned char *)data); break; case NC_CHAR: - return nc_get_att_text(ncid, varid, name, (char *)data); + return nc_get_att_text(ncid, varid, name, (char *)data); break; case NC_SHORT: - return nc_get_att_short(ncid, varid, name, (short *)data); + return nc_get_att_short(ncid, varid, name, (short *)data); break; case NC_INT: - return nc_get_att_int(ncid, varid, name, (int *)data); + return nc_get_att_int(ncid, varid, name, (int *)data); break; case NC_FLOAT: - return nc_get_att_float(ncid, varid, name, (float *)data); + return nc_get_att_float(ncid, varid, name, (float *)data); break; case NC_DOUBLE: - return nc_get_att_double(ncid, varid, name, (double *)data); + return nc_get_att_double(ncid, varid, name, (double *)data); break; /* need the following #ifdef for linking against netcdf3 */ #ifdef NC_UBYTE case NC_UBYTE: - return nc_get_att_ubyte(ncid, varid, name, - (unsigned char *)data); + return nc_get_att_ubyte(ncid, varid, name, + (unsigned char *)data); break; #endif #ifdef NC_USHORT case NC_USHORT: - return nc_get_att_ushort(ncid, varid, name, - (unsigned short *)data); + return nc_get_att_ushort(ncid, varid, name, + (unsigned short *)data); break; #endif #ifdef NC_UINT case NC_UINT: - return nc_get_att_uint(ncid, varid, name, - (unsigned int *)data); + return nc_get_att_uint(ncid, varid, name, + (unsigned int *)data); break; #endif #ifdef NC_INT64 case NC_INT64: - return nc_get_att_longlong(ncid, varid, name, - (long long *)data); + return nc_get_att_longlong(ncid, varid, name, + (long long *)data); break; #endif #ifdef NC_UINT64 case NC_UINT64: - return nc_get_att_ulonglong(ncid, varid, name, - (unsigned long long *)data); + return nc_get_att_ulonglong(ncid, varid, name, + (unsigned long long *)data); break; #endif #ifdef NC_STRING case NC_STRING: - return nc_get_att_string(ncid, varid, name, - (char **)data); + return nc_get_att_string(ncid, varid, name, + (char **)data); break; #endif default: @@ -814,10 +869,13 @@ define_mode(PyCdunifFileObject *file, int define_flag) if (file->define != define_flag) { Py_BEGIN_ALLOW_THREADS; acquire_Cdunif_lock(); - if (file->define) - cdendef(file); - else - cdredef(file); + if (cdms_use_define_mode == 1) { + int ierr; + if (file->define) + ierr = cdendef(file); + else + ierr = cdredef(file); + } release_Cdunif_lock(); file->define = define_flag; Py_END_ALLOW_THREADS; @@ -1032,6 +1090,11 @@ collect_attributes(PyCdunifFileObject *file, int varid, PyObject *attributes, in } } } +int cdms2_nc_put_att_text(int fileid, int varid, char *name, int len, char *string) { + int ret; + ret = nc_put_att_text(fileid, varid, name, len, string); + return ret; +} static int set_attribute(int fileid, int varid, PyObject *attributes, @@ -1046,7 +1109,7 @@ set_attribute(int fileid, int varid, PyObject *attributes, int ret; Py_BEGIN_ALLOW_THREADS; acquire_Cdunif_lock(); - ret = nc_put_att_text(fileid, varid, name, len, string); + ret = cdms2_nc_put_att_text(fileid, varid, name, len, string); release_Cdunif_lock(); Py_END_ALLOW_THREADS; if (ret != NC_NOERR) { @@ -1130,8 +1193,59 @@ PyCdunifFileObject_dealloc(PyCdunifFileObject *self) PyObject_Del(self); /* PyMem_Del segfaults in 2.5 */ } -/* Create file object */ +#ifdef PARALLEL +int my_mpi_size() { + int size; + MPI_Comm_size(MPI_COMM_WORLD,&size); + return size; +} +int my_mpi_rank() { + int rank; + MPI_Comm_rank(MPI_COMM_WORLD,&rank); + return rank; +} +#endif + +/* Create file object */ +int cdms2_nccreate(char *filename, int ncmode) { + int selfncid; + /* use netcdf4 is not using shuffle or not cdms classic */ + if ((cdms_classic == 0) || (cdms_shuffle !=0 ) || (cdms_deflate !=0 ) || (cdms_netcdf4 == 1)) { + ncmode = ncmode|NC_NETCDF4; +#ifdef PARALLEL + /* ok we can only use MPIIO if not using shuffle or deflate for reason + * why + * see http://www.hdfgroup.org/hdf5-quest.html#p5comp + * also classic and 64bit offset cannot be used for parallel + * see: https://www.unidata.ucar.edu/software/netcdf/docs/parallel_io.html */ + if ((cdms_classic==0) && (cdms_shuffle==0) && (cdms_deflate == 0 ) && + (cdms_use_parallel == 1) + ) { + ncmode = ncmode | NC_MPIIO; + } +#endif + } + else { + ncmode = ncmode | NC_64BIT_OFFSET; + } + if (cdms_classic==1) { + ncmode = ncmode | NC_CLASSIC_MODEL; + } +#ifdef PARALLEL + nc_set_log_level(3); + int ierrnc; + if (nc_flag_on(ncmode,NC_MPIIO)) { + ierrnc = nc_create_par(filename, ncmode,MPI_COMM_WORLD,MPI_INFO_NULL,&selfncid); + } + else { + selfncid = nccreate(filename, ncmode); + } +#else + selfncid = nccreate(filename, ncmode); +#endif + return selfncid; +} static PyCdunifFileObject * PyCdunifFile_Open(char *filename, char *mode) { @@ -1158,16 +1272,8 @@ PyCdunifFile_Open(char *filename, char *mode) if (mode[0] == 'w') { Py_BEGIN_ALLOW_THREADS; acquire_Cdunif_lock(); - ncmode = NC_CLOBBER|NC_64BIT_OFFSET; -#ifndef NONC4 - if ((cdms_shuffle!=0) || (cdms_deflate!=0)) { - ncmode = NC_CLOBBER|NC_NETCDF4; - } - if (cdms_classic==1) { - ncmode = ncmode | NC_CLASSIC_MODEL; - } -#endif - self->id = nccreate(filename, ncmode); + ncmode = NC_CLOBBER; + self->id = cdms2_nccreate(filename,ncmode); release_Cdunif_lock(); Py_END_ALLOW_THREADS; self->define = 1; @@ -1184,16 +1290,8 @@ PyCdunifFile_Open(char *filename, char *mode) self->id = cdopen(filename, NC_WRITE, &self->filetype); self->define = 0; if (self->id == -1) { - ncmode = NC_NOCLOBBER; -#ifndef NONC4 - if ((cdms_shuffle!=0) || (cdms_deflate!=0)) { - ncmode = NC_NOCLOBBER|NC_NETCDF4; - } - if (cdms_classic==1) { - ncmode = ncmode | NC_CLASSIC_MODEL; - } -#endif - self->id = nccreate(filename, ncmode); + ncmode = NC_NOCLOBBER; + self->id = cdms2_nccreate(filename, ncmode); self->filetype = CuNetcdf; self->define = 1; } @@ -1352,7 +1450,11 @@ PyCdunifFile_CreateDimension(PyCdunifFileObject *file, char *name, long size) define_mode(file, 1); Py_BEGIN_ALLOW_THREADS; acquire_Cdunif_lock(); - id = ncdimdef(file->id, name, (size == 0) ? NC_UNLIMITED : size); + int ierr; + ierr = nc_def_dim(file->id, name, (size == 0) ? NC_UNLIMITED : size, &id); + if ( ierr != NC_NOERR ) { + id = -1; + } release_Cdunif_lock(); Py_END_ALLOW_THREADS; if (id == -1) { @@ -1403,6 +1505,12 @@ static char createDimension_doc[] = ""; /* Create variable */ +int cdms2_nc_def_var(int id,char *name, int ntype, int ndim, int *dimids, int *i) { + int ret; + ret = nc_def_var(id, name, ntype, ndim, dimids, i); + return ret; +} + static PyCdunifVariableObject * PyCdunifFile_CreateVariable(PyCdunifFileObject *file, char *name, int typecode, char **dimension_names, int ndim) @@ -1440,7 +1548,8 @@ PyCdunifFile_CreateVariable(PyCdunifFileObject *file, char *name, int typecode, ntype = cdunif_type_from_code((char)typecode); Py_BEGIN_ALLOW_THREADS; acquire_Cdunif_lock(); - ret = nc_def_var(file->id, name, ntype, ndim, dimids, &i); + i=-999; + ret = cdms2_nc_def_var(file->id, name, ntype, ndim, dimids, &i); release_Cdunif_lock(); Py_END_ALLOW_THREADS; if (ret != NC_NOERR) { @@ -1449,7 +1558,6 @@ PyCdunifFile_CreateVariable(PyCdunifFileObject *file, char *name, int typecode, free(dimids); return NULL; } -#ifndef NONC4 Py_BEGIN_ALLOW_THREADS; /* try some compression thing here */ if (((cdms_shuffle!=0) || (cdms_deflate!=0))&& (ndim!=0)) { @@ -1458,7 +1566,6 @@ PyCdunifFile_CreateVariable(PyCdunifFileObject *file, char *name, int typecode, release_Cdunif_lock(); } Py_END_ALLOW_THREADS; -#endif if (ret != NC_NOERR) { cdunif_signalerror(ret); if (dimids != NULL) @@ -1611,10 +1718,6 @@ PyCdunifFileObject_read_dimension(PyCdunifFileObject *self, PyObject *args){ Py_DECREF(array); array=NULL; } - /* This is ugly, concatenate fails otherwise */ -#ifdef PCMDI_NUMERICS - generate_pcmdi_dims(&array,"DimensionArray"); -#endif return (PyObject *)array; } else { @@ -1982,7 +2085,6 @@ PyObject * PyCdunifVariableObject_setslice(PyCdunifVariableObject *self, PyObject *args) { int low, high; PyObject *value; - if (!PyArg_ParseTuple(args, "iiO", &low, &high, &value)) return NULL; if (PyCdunifVariableObject_ass_slice(self,low,high,value) != -1){ @@ -2526,7 +2628,7 @@ PyCdunifVariable_WriteString(PyCdunifVariableObject *self, define_mode(self->file, 0); Py_BEGIN_ALLOW_THREADS; acquire_Cdunif_lock(); - ret = nc_put_var_text(self->file->id, self->id, + ret = cdms2_nc_put_var_text(self->file->id, self->id, PyString_AsString((PyObject *)value)); release_Cdunif_lock(); Py_END_ALLOW_THREADS; @@ -2539,6 +2641,11 @@ PyCdunifVariable_WriteString(PyCdunifVariableObject *self, else return -1; } +int cdms2_nc_put_var_text(int fileid, int id, char *value) { + int ret; + ret = nc_put_var_text(fileid, id, value); + return ret; +} static PyObject * PyCdunifVariableObject_item(PyCdunifVariableObject *self, Py_ssize_t i) @@ -2671,10 +2778,12 @@ PyCdunifVariableObject_ass_slice(PyCdunifVariableObject *self, PyErr_SetString(PyExc_ValueError, "Can't delete elements."); return -1; } - if (self->nd == 0) { + /* I tweaked the python to send 0/1 and it works we don't need this anymore + * */ + /*if (self->nd == 0) { PyErr_SetString(PyExc_TypeError, "Not a sequence"); return -1; - } + }*/ if (low < -(long)self->dimensions[0]) low = -self->dimensions[0]; if (low < 0) @@ -2883,6 +2992,30 @@ PyCdunif_setncflags(PyObject *self, PyObject *args) { } cdms_deflate_level = flagval; } + else if (strcmp(flagname,"use_define_mode") == 0) { + if (flagval>1) { + sprintf(msg,"invalid flag for use_define_mode: '%i' valid flags are: 0 (do not use) or 1 (use)",flagval); + PyErr_SetString(PyExc_TypeError, msg); + return NULL; + } + cdms_use_define_mode = flagval; + } + else if (strcmp(flagname,"use_parallel") == 0) { + if (flagval>1) { + sprintf(msg,"invalid flag for use_parallel: '%i' valid flags are: 0 (do not use) or 1 (can use)",flagval); + PyErr_SetString(PyExc_TypeError, msg); + return NULL; + } + cdms_use_parallel = flagval; + } + else if (strcmp(flagname,"netcdf4") == 0) { + if (flagval>1) { + sprintf(msg,"invalid flag for necdf 4: '%i' valid flags are: 0 or 1",flagval); + PyErr_SetString(PyExc_TypeError, msg); + return NULL; + } + cdms_netcdf4 = flagval; + } else { sprintf(msg,"invalid compression flag: '%s' valid flags are: shuffle, deflate, deflate_level",flagname); PyErr_SetString(PyExc_TypeError, msg); @@ -2910,6 +3043,15 @@ PyCdunif_getncflags(PyObject *self, PyObject *args) { else if (strcmp(flagname,"deflate_level") == 0) { return Py_BuildValue("i",cdms_deflate_level); } + else if (strcmp(flagname,"netcdf4") == 0) { + return Py_BuildValue("i",cdms_netcdf4); + } + else if (strcmp(flagname,"use_define_mode") == 0) { + return Py_BuildValue("i",cdms_use_define_mode); + } + else if (strcmp(flagname,"use_parallel") == 0) { + return Py_BuildValue("i",cdms_use_parallel); + } else { sprintf(msg,"invalid compression flag: '%s' valid flags are: shuffle, deflate, deflate_level",flagname); PyErr_SetString(PyExc_TypeError, msg); diff --git a/Packages/cdms2/setup.py b/Packages/cdms2/setup.py index 8d6d361fea..b617a0e087 100644 --- a/Packages/cdms2/setup.py +++ b/Packages/cdms2/setup.py @@ -18,13 +18,22 @@ import numpy macros = [] +try: + import mpi4py + ## Ok we have mpi4py let's build with support for it + macros.append(("PARALLEL",None)) + os.environ["CC"]="mpicc" + os.environ["CFLAGS"]="-w -g" +except: + os.environ["CFLAGS"]="-w -g" + pass import cdat_info ## if cdat_info.CDMS_INCLUDE_DAP=='yes': ## macros.append(("NONC4",None)) - +print "MACROS PASSED:",macros setup (name = "cdms2", version='5.0', - description = "Clima1te Data Management System, Numpy version", + description = "Climate Data Management System, Numpy version", url = "http://cdat.sf.net", packages = ['cdms2'], package_dir = {'cdms2': 'Lib'}, diff --git a/testing/cdms2/CMakeLists.txt b/testing/cdms2/CMakeLists.txt index 6dc5a1f459..544a09aab5 100644 --- a/testing/cdms2/CMakeLists.txt +++ b/testing/cdms2/CMakeLists.txt @@ -125,6 +125,11 @@ cdat_add_test("test_cdms2_full_averagering_full_missing" ${cdat_SOURCE_DIR}/testing/cdms2/test_full_averaging.py ) +cdat_add_test("CDMS_Test_write_extended_dimension" + "${PYTHON_EXECUTABLE}" + ${cdat_SOURCE_DIR}/testing/cdms2/test_simple_write.py) + + # Tests which should fail # set_tests_properties(testSo2TasACCESSFails PROPERTIES PASS_REGULAR_EXPRESSION "FAILED") diff --git a/testing/cdms2/test_mpi_write.py b/testing/cdms2/test_mpi_write.py new file mode 100644 index 0000000000..7872d45984 --- /dev/null +++ b/testing/cdms2/test_mpi_write.py @@ -0,0 +1,31 @@ +import cdms2 +import numpy +try: + import mpi4py + + sz = mpi4py.MPI.COMM_WORLD.Get_size() + rk = mpi4py.MPI.COMM_WORLD.Get_rank() +except: + # not mpi enabled + sz = 1 + rk = 1 + +#cdms2.setNetcdfClassicFlag(0) +#cdms2.setNetcdf4Flag(1) +cdms2.setNetcdfShuffleFlag(0) +cdms2.setNetcdfDeflateFlag(0) +cdms2.setNetcdfDeflateLevelFlag(0) + +a=numpy.array([1,2,3,4,5,6,7,8.]) +a.shape=(1,2,2,2) +a=cdms2.MV2.array(a) +print a.shape +f=cdms2.open("test_mpi_write.nc","w") + + +#Ok now we are going to write variables, split accross or processors +nvars = 80 +for i in range(rk,nvars,sz): + #V=f.createVariableCopy(a,id="mpi_test_%i" % i) + f.write(a*i,id="test_mpi_%i" % i) +f.close() diff --git a/testing/cdms2/test_mpi_write_2.py b/testing/cdms2/test_mpi_write_2.py new file mode 100644 index 0000000000..4ab9317df5 --- /dev/null +++ b/testing/cdms2/test_mpi_write_2.py @@ -0,0 +1,24 @@ +import cdms2 +import numpy +import mpi4py + +sz = mpi4py.MPI.COMM_WORLD.Get_size() +rk = mpi4py.MPI.COMM_WORLD.Get_rank() + +cdms2.setNetcdfClassicFlag(0) +cdms2.setNetcdfShuffleFlag(0) +cdms2.setNetcdfDeflateFlag(0) +cdms2.setNetcdfDeflateLevelFlag(0) + +ntimes = 12000 +a=numpy.ones((ntimes,64,128),dtype=numpy.float32) +a=cdms2.MV2.array(a) +a.id = "test_mpi" +print a.shape +f=cdms2.open("test_mpi_write_2.nc","w") +V=f.createVariableCopy(a) +print type(V) +#Ok now we are going to rewrite the time slice accross processors +for i in range(rk,ntimes,sz): + V[i] = a[i].filled()*i +f.close() diff --git a/testing/cdms2/test_simple_write.py b/testing/cdms2/test_simple_write.py new file mode 100644 index 0000000000..9daebd5332 --- /dev/null +++ b/testing/cdms2/test_simple_write.py @@ -0,0 +1,13 @@ +import numpy +import MV2 +import cdms2 +import os + +f = cdms2.open("test_simple_write.nc", "w") + +data = numpy.random.random((20, 64, 128)) +data = MV2.array(data) +data.getAxis(0).designateTime() +f.write(data, dtype=numpy.float32, id="test_simple") +f.close() +os.remove("test_simple_write.nc")