Skip to content

Commit

Permalink
#156: footprinting: support Open MPI structures
Browse files Browse the repository at this point in the history
  • Loading branch information
cz4rs committed Nov 19, 2020
1 parent 53f5c27 commit 02c45a7
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/checkpoint/checkpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
116 changes: 116 additions & 0 deletions src/checkpoint/container/ompi_serialize.h
Original file line number Diff line number Diff line change
@@ -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*/
43 changes: 43 additions & 0 deletions tests/unit/test_footprinter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
#include <thread>
#include <checkpoint/checkpoint.h>

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 { };
Expand Down Expand Up @@ -529,4 +534,42 @@ TEST_F(TestFootprinter, test_virtual_serialize) {
}
}

TEST_F(TestFootprinter, test_ompi) {
{
std::vector<ompi_communicator_t*> v(3);

EXPECT_EQ(
checkpoint::getMemoryFootprint(v),
sizeof(v) + v.capacity() * sizeof(ompi_communicator_t*)
);
}

{
std::vector<ompi_group_t*> v(5);

EXPECT_EQ(
checkpoint::getMemoryFootprint(v),
sizeof(v) + v.capacity() * sizeof(ompi_group_t*)
);
}

{
std::vector<ompi_request_t*> v(7);

EXPECT_EQ(
checkpoint::getMemoryFootprint(v),
sizeof(v) + v.capacity() * sizeof(ompi_request_t*)
);
}

{
std::vector<ompi_win_t*> v(9);

EXPECT_EQ(
checkpoint::getMemoryFootprint(v),
sizeof(v) + v.capacity() * sizeof(ompi_win_t*)
);
}
}

}}} // end namespace checkpoint::tests::unit

0 comments on commit 02c45a7

Please sign in to comment.