/* Copyright 2013--2018 James E. McClure, Virginia Polytechnic & State University This file is part of the Open Porous Media project (OPM). OPM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OPM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OPM. If not, see . */ /* Copyright 2013--2018 James E. McClure, Virginia Polytechnic & State University This file is part of the Open Porous Media project (OPM). OPM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OPM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OPM. If not, see . */ // This file contains wrappers for MPI routines and functions to pack/unpack data structures #ifndef MPI_WRAPPERS_HPP #define MPI_WRAPPERS_HPP #include "common/MPI_Helpers.h" #include #include #include #include /******************************************************** * Default instantiations for std::vector * ********************************************************/ template size_t packsize( const std::vector& rhs ) { size_t bytes = sizeof(size_t); for (size_t i=0; i void pack( const std::vector& rhs, char *buffer ) { size_t size = rhs.size(); memcpy(buffer,&size,sizeof(size_t)); size_t pos = sizeof(size_t); for (size_t i=0; i void unpack( std::vector& data, const char *buffer ) { size_t size; memcpy(&size,buffer,sizeof(size_t)); data.clear(); data.resize(size); size_t pos = sizeof(size_t); for (size_t i=0; i size_t packsize( const std::pair& rhs ) { return packsize(rhs.first)+packsize(rhs.second); } template void pack( const std::pair& rhs, char *buffer ) { pack(rhs.first,buffer); pack(rhs.second,&buffer[packsize(rhs.first)]); } template void unpack( std::pair& data, const char *buffer ) { unpack(data.first,buffer); unpack(data.second,&buffer[packsize(data.first)]); } /******************************************************** * Default instantiations for std::map * ********************************************************/ template size_t packsize( const std::map& rhs ) { size_t bytes = sizeof(size_t); typename std::map::const_iterator it; for (it=rhs.begin(); it!=rhs.end(); ++it) { bytes += packsize(it->first); bytes += packsize(it->second); } return bytes; } template void pack( const std::map& rhs, char *buffer ) { size_t N = rhs.size(); pack(N,buffer); size_t pos = sizeof(size_t); typename std::map::const_iterator it; for (it=rhs.begin(); it!=rhs.end(); ++it) { pack(it->first,&buffer[pos]); pos+=packsize(it->first); pack(it->second,&buffer[pos]); pos+=packsize(it->second); } } template void unpack( std::map& data, const char *buffer ) { size_t N = 0; unpack(N,buffer); size_t pos = sizeof(size_t); data.clear(); for (size_t i=0; i tmp; unpack(tmp.first,&buffer[pos]); pos+=packsize(tmp.first); unpack(tmp.second,&buffer[pos]); pos+=packsize(tmp.second); data.insert(tmp); } } /******************************************************** * Default instantiations for std::set * ********************************************************/ template size_t packsize( const std::set& rhs ) { size_t bytes = sizeof(size_t); typename std::set::const_iterator it; for (it=rhs.begin(); it!=rhs.end(); ++it) { bytes += packsize(*it); } return bytes; } template void pack( const std::set& rhs, char *buffer ) { size_t N = rhs.size(); pack(N,buffer); size_t pos = sizeof(size_t); typename std::set::const_iterator it; for (it=rhs.begin(); it!=rhs.end(); ++it) { pack(*it); pos+=packsize(*it); } } template void unpack( std::set& data, const char *buffer ) { size_t N = 0; unpack(N,buffer); size_t pos = sizeof(size_t); data.clear(); for (size_t i=0; i