Implementing generalized deep-copy in MPI

View article
PeerJ Computer Science

Main article text

 

Introduction

  • We introduce the MPI Extension Library (MEL), a C++ header-only wrapper around the MPI standard which aims to give a simplified programming interface with consistent type-safety and compile time error handling, along with providing efficient implementations of higher level parallel constructs such as deep copy.

  • As a part of MEL, we provide generic implementations of deep copy semantics that can be easily applied to existing code to enable complex structured data to be deep copied transparently as either a send, receive, broadcast, or file access operation with minimal programmer intervention. The latter can also be used for the purpose of check-pointing when writing fault tolerant MPI code.

Related Work

When to Use Deep Copy

Buffered vs. non-buffered

MEL–The MPI Extension Library

  • Remain true to the underlying design of MPI, by keeping to an imperative function interface that does not fundamentally change the way in which the programmer interacts with the MPI run-time.

  • To provide a type-safe, consistent, and unified function syntax that allows distributions of MPI from all vendors to behave in a common and predictable way at both compile-time and run-time.

  • To be soluble, allowing the compiler to remove the abstractions MEL provides to achieve the same performance as native MPI code.

  • To be memory efficient by minimizing the use of intermediate buffers whenever possible.

  • To make use of modern C++ language features and advanced template meta programming to both ensure correctness at compile-time and to generate boiler-plate values that programmers have to provide themselves with native MPI code.

  • To give higher-level functionality that is not available from the MPI standard such as deep copy Semantics (our focus in this paper).

MEL deep copy

  • Unallocated pointers are initialized to nullptr.

  • Dynamic Memory must be allocated using MPI_Alloc_mem and freed using MPI_Free_mem, or the equivalent MEL calls:

  • Pointers refer to distinct allocations. E.g. It is erroneous to have an allocation of the form char *ptr = new char[100] in one object, and to then have a weak-pointer into the array in subsequent objects: char *mySubPtr = &ptr[50]. In these situations, it is best to store integer offsets into the array, rather than the pointer address itself.

Top-Level interface

Detecting objects that require deep copy

template<typename MSG> void DeepCopy(MSG &msg)

that describes how to resolve the dependencies of a given object type. The template parameter MSG is a shorthand for MEL::Deep::Message<TRANSPORT_METHOD, HASH_MAP> where TRANSPORT_METHOD and HASH_MAP are types satisfying the constraints described in sections Transport Method and Hashing Shared Pointers, respectively. A detailed example of the method used to detect the presence of a matching member function is given in section Detecting the Deep Copy Function using Template Meta-Programming.

Message Transport-API

An example copy

Transport method

template<typename T> inline void transport(T *&ptr, const int len)

that describes how to move a region of memory, and a public-static-member variable static constexpr bool SOURCE which tells the compiler whether or not this is a sending or a receiving transport method. This boolean is important as it tells the Message object whether or not it needs to make allocations as it traverses the deep structure. The transport method should also store any state variables need to maintain the transport over the duration of the deep copy. Such state variables may be but are not limited to an MPI communicator and process rank, a file handle, or a pointer to an array used for buffering.

Hashing shared pointers

template<typename T> inline bool find(T* oldPtr, T* &ptr)

template<typename T> inline void insert(T* oldPtr, T* ptr)

External deep copy functions

template<typename MSG> inline void MyTypeDeepCopy(MyType &obj, MSG &msg)

that takes by reference an instance of the object to transport and a Message object to perform the deep copy.

MEL Implementation Details

Detecting the deep copy function using template meta-programming

Transport-API implementation

Message::packVar

Message::packPtr

Message::packSharedPtr

Message::packSTL

Message::packRootVar, Message::packRootPtr, & Message::packRootSTL

Transport method implementation & usage

template<typename T> inline void transport(T *&ptr, const int len)

which defines how to move len objects of type T from a given pointer ptr. Listing 18 shows the implementation of the TransportSend transport method, which defines how to move data using a discrete MPI_Send for each transport. An instance of a transport method carries any state needed to represent the data movement over the duration of the deep copy. In the case of TransportSend the state needed to represent the transfer are the MPI rank of the destination process, a tag to use for the communication, and the MPI communicator over which the data will be transferred. For other transport methods the state may be a file handle, or a pointer to an array used for buffering.

Hash-Map implementation

template<typename T> inline bool find(T* oldPtr, T* &ptr)

template<typename T> inline void insert(T* oldPtr, T* ptr)

Benchmarks

Case study: ray-tracing scene structure

Broadcast–MPI vs. MEL

File Write/Read–MEL vs. Boost

Case study: graphs with cycles

Fully connected graphs

Random graph

Ring graph

Binary tree

Conclusions and Future Work

Appendices

Experiment 1: broadcasting a large tree structure

Scene object containing MEL deep copy methods

Hand coded non-buffered Bcast of scene object

Hand coded buffered Bcast of scene object

Experiment 2: communicating generic directed graph structures

Factory functions for building directed graphs in different shaped structures

Generic implementation of directed graph container

Additional Information and Declarations

Competing Interests

The authors declare that they have no competing interests.

Author Contributions

Joss Whittle conceived and designed the experiments, performed the experiments, analyzed the data, contributed reagents/materials/analysis tools, wrote the paper, prepared figures and/or tables, performed the computation work.

Rita Borgo conceived and designed the experiments, analyzed the data, contributed reagents/materials/analysis tools, wrote the paper, reviewed drafts of the paper.

Mark W. Jones conceived and designed the experiments, analyzed the data, contributed reagents/materials/analysis tools, wrote the paper, reviewed drafts of the paper.

Data Deposition

The following information was supplied regarding data availability:

Source code available at: https://github.com/CS-Swansea/MEL.

Funding

Joss Whittle is funded by an EPSRC PhD studentship. The funders had no role in study design, data collection and analysis, decision to publish, or preparation of the manuscript.

 
Ask a question
2,360 Visitors 2,761 Views 1,858 Downloads

Your institution may have Open Access funds available for qualifying authors. See if you qualify

Publish for free

Comment on Articles or Preprints and we'll waive your author fee
Learn more

Five new journals in Chemistry

Free to publish • Peer-reviewed • From PeerJ
Find out more