From 43f641eaf382f3bb248411a23908f537dd149a65 Mon Sep 17 00:00:00 2001 From: Michael Buehlmann <buehlmann.michi@gmail.com> Date: Tue, 29 Mar 2022 17:51:05 -0500 Subject: [PATCH] add static routines to python interface --- docs/python/readwrite.rst | 14 +++++++++++++- python/genericio.cpp | 5 +++++ python/pygio/__init__.py | 30 +++++++++++++++++++++++++----- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/docs/python/readwrite.rst b/docs/python/readwrite.rst index 402e0be..2f4e5af 100644 --- a/docs/python/readwrite.rst +++ b/docs/python/readwrite.rst @@ -111,4 +111,16 @@ References .. autofunction:: read_phys_origin -.. autofunction:: write_genericio \ No newline at end of file +.. autofunction:: write_genericio + +.. autoclass:: FileIO + :noindex: + +.. autoclass:: MismatchBehavior + :noindex: + +.. autofunction:: setDefaultShouldCompress + +.. autofunction:: setNaturalDefaultPartition + +.. autofunction:: setCollectiveMPIIOThreshold \ No newline at end of file diff --git a/python/genericio.cpp b/python/genericio.cpp index 089951b..53df6f5 100644 --- a/python/genericio.cpp +++ b/python/genericio.cpp @@ -338,6 +338,7 @@ PYBIND11_MODULE(pygio, m) { py::class_<PyGenericIO> pyGenericIO(m, "PyGenericIO"); + // ENUMS py::enum_<PyGenericIO::FileIO>(pyGenericIO, "FileIO") .value("FileIOMPI", PyGenericIO::FileIO::FileIOMPI) .value("FileIOPOSIX", PyGenericIO::FileIO::FileIOPOSIX) @@ -369,8 +370,12 @@ PYBIND11_MODULE(pygio, m) { .def("read_variable_names", &PyGenericIO::read_variable_names) .def("read_variable_dtypes", &PyGenericIO::read_variable_dtypes) .def("get_source_ranks", &PyGenericIO::getSourceRanks) + .def_static("setDefaultShouldCompress", &PyGenericIO::setDefaultShouldCompress) + .def_static("setNaturalDefaultPartition", &PyGenericIO::setNaturalDefaultPartition) + .def_static("setDefaultFileIOType", &PyGenericIO::setDefaultFileIOType) #ifndef GENERICIO_NO_MPI .def("rebalance_source_ranks", &PyGenericIO::rebalanceSourceRanks) + .def_static("setCollectiveMPIIOThreshold", &PyGenericIO::setCollectiveMPIIOThreshold) #endif ; diff --git a/python/pygio/__init__.py b/python/pygio/__init__.py index 17ea249..ce4f4fb 100644 --- a/python/pygio/__init__.py +++ b/python/pygio/__init__.py @@ -2,19 +2,39 @@ from __future__ import print_function import os _GENERICIO_NO_MPI = False -if 'GENERICIO_NO_MPI' in os.environ: - _GENERICIO_NO_MPI = os.environ['GENERICIO_NO_MPI'].lower() in ['true', 'yes', 'y'] +if "GENERICIO_NO_MPI" in os.environ: + _GENERICIO_NO_MPI = os.environ["GENERICIO_NO_MPI"].lower() in ["true", "yes", "y"] if _GENERICIO_NO_MPI: - print("WARNING: the pygio module without MPI support has been loaded (due to the GENERICIO_NO_MPI env variable). Writing GenericIO files not supported.") + print( + "WARNING: the pygio module without MPI support has been loaded (due to the GENERICIO_NO_MPI env variable). Writing GenericIO files not supported." + ) from .pygio_nompi import * else: # try to load the MPI library (or the no-mpi library, in case of missing MPI during compilation) from . import pygio as _pygio + try: _pygio._init_mpi() except: - print("WARNING: The pygio module has been compiled without MPI support. Writing GenericIO files not supported.") + print( + "WARNING: The pygio module has been compiled without MPI support. Writing GenericIO files not supported." + ) + _GENERICIO_NO_MPI = True + from .pygio import * + + +# move some ENUMs and static functions up to the module namespace +FileIO = PyGenericIO.FileIO +MismatchBehavior = PyGenericIO.MismatchBehavior +setDefaultShouldCompress = PyGenericIO.setDefaultShouldCompress +setNaturalDefaultPartition = PyGenericIO.setNaturalDefaultPartition +setDefaultFileIOType = PyGenericIO.setDefaultFileIOType +if not _GENERICIO_NO_MPI: + setCollectiveMPIIOThreshold = PyGenericIO.setCollectiveMPIIOThreshold - from .pygio import * \ No newline at end of file +# sensible defaults? +if not _GENERICIO_NO_MPI: + setNaturalDefaultPartition() + setDefaultFileIOType(FileIO.FileIOMPICollective) -- GitLab