diff --git a/src/checkpoint/checkpoint.h b/src/checkpoint/checkpoint.h index 4b3f6fcd..1ffdc125 100644 --- a/src/checkpoint/checkpoint.h +++ b/src/checkpoint/checkpoint.h @@ -56,6 +56,7 @@ #include "checkpoint/container/function_serialize.h" #include "checkpoint/container/list_serialize.h" #include "checkpoint/container/map_serialize.h" +#include "checkpoint/container/ompi_serialize.h" #include "checkpoint/container/queue_serialize.h" #include "checkpoint/container/raw_ptr_serialize.h" #include "checkpoint/container/shared_ptr_serialize.h" diff --git a/src/checkpoint/container/ompi_serialize.h b/src/checkpoint/container/ompi_serialize.h new file mode 100644 index 00000000..aa4ff3f5 --- /dev/null +++ b/src/checkpoint/container/ompi_serialize.h @@ -0,0 +1,116 @@ +/* +//@HEADER +// ***************************************************************************** +// +// ompi_serialize.h +// DARMA Toolkit v. 1.0.0 +// DARMA/checkpoint => Serialization Library +// +// Copyright 2020 National Technology & Engineering Solutions of Sandia, LLC +// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S. +// Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact darma@sandia.gov +// +// ***************************************************************************** +//@HEADER +*/ + +#if !defined INCLUDED_CHECKPOINT_CONTAINER_OMPI_SERIALIZE_H +#define INCLUDED_CHECKPOINT_CONTAINER_OMPI_SERIALIZE_H + +#include "checkpoint/common.h" + +struct ompi_communicator_t; +struct ompi_group_t; +struct ompi_request_t; +struct ompi_win_t; + +namespace checkpoint { + +/** + * Simplified footprinting is supported for certain Open MPI structures to avoid + * workarounds in application code. + */ + +template < + typename SerializerT, + typename = std::enable_if_t< + std::is_same< + SerializerT, + checkpoint::Footprinter + >::value + > +> +void serialize(SerializerT& s, ompi_communicator_t* req) { + s.countBytes(req); +} + +template < + typename SerializerT, + typename = std::enable_if_t< + std::is_same< + SerializerT, + checkpoint::Footprinter + >::value + > +> +void serialize(SerializerT& s, ompi_group_t* req) { + s.countBytes(req); +} + +template < + typename SerializerT, + typename = std::enable_if_t< + std::is_same< + SerializerT, + checkpoint::Footprinter + >::value + > +> +void serialize(SerializerT& s, ompi_request_t* req) { + s.countBytes(req); +} + +template < + typename SerializerT, + typename = std::enable_if_t< + std::is_same< + SerializerT, + checkpoint::Footprinter + >::value + > +> +void serialize(SerializerT& s, ompi_win_t* req) { + s.countBytes(req); +} + +} /* end namespace checkpoint */ + +#endif /*INCLUDED_CHECKPOINT_CONTAINER_OMPI_SERIALIZE_H*/ diff --git a/tests/unit/test_footprinter.cc b/tests/unit/test_footprinter.cc index 5bae4858..754ea8e6 100644 --- a/tests/unit/test_footprinter.cc +++ b/tests/unit/test_footprinter.cc @@ -50,6 +50,11 @@ #include #include +struct ompi_communicator_t; +struct ompi_group_t; +struct ompi_request_t; +struct ompi_win_t; + namespace checkpoint { namespace tests { namespace unit { struct TestFootprinter : TestHarness { }; @@ -543,4 +548,42 @@ TEST_F(TestFootprinter, test_virtual_serialize) { } } +TEST_F(TestFootprinter, test_ompi) { + { + std::vector v(3); + + EXPECT_EQ( + checkpoint::getMemoryFootprint(v), + sizeof(v) + v.capacity() * sizeof(ompi_communicator_t*) + ); + } + + { + std::vector v(5); + + EXPECT_EQ( + checkpoint::getMemoryFootprint(v), + sizeof(v) + v.capacity() * sizeof(ompi_group_t*) + ); + } + + { + std::vector v(7); + + EXPECT_EQ( + checkpoint::getMemoryFootprint(v), + sizeof(v) + v.capacity() * sizeof(ompi_request_t*) + ); + } + + { + std::vector v(9); + + EXPECT_EQ( + checkpoint::getMemoryFootprint(v), + sizeof(v) + v.capacity() * sizeof(ompi_win_t*) + ); + } +} + }}} // end namespace checkpoint::tests::unit