Skip to content
Snippets Groups Projects
Commit 1d210aa6 authored by Benjamin Lindner2's avatar Benjamin Lindner2
Browse files

manual MPI serialization for database, params,sample unit test

parent 8da63594
No related branches found
No related tags found
No related merge requests found
/*
* This file is part of the software sassena
*
* Authors:
* Benjamin Lindner, ben@benlabs.net
*
* Copyright 2008-2010 Benjamin Lindner
*
*/
#ifndef MPI__WRAPPER_HPP_
#define MPI__WRAPPER_HPP_
#include "boost/mpi.hpp"
namespace mpi {
namespace wrapper {
void broadcast_stream(boost::mpi::communicator& comm,std::stringstream& stream, size_t root);
}
}
#endif
// end of file
\ No newline at end of file
/*
* This file is part of the software sassena
*
* Authors:
* Benjamin Lindner, ben@benlabs.net
*
* Copyright 2008-2010 Benjamin Lindner
*
*/
// direct header
#include <sstream>
#include <boost/mpi.hpp>
using namespace std;
namespace mpi {
namespace wrapper {
void broadcast_stream(boost::mpi::communicator& comm,std::stringstream& stream, size_t root) {
char* buffer = NULL;
size_t buffersize = 0;
if (comm.rank()==root) {
buffer = const_cast<char*>(stream.str().c_str());
buffersize = stream.str().size();
}
boost::mpi::broadcast(comm,&buffersize,1,root);
if (comm.rank()!=root) {
buffer = (char*) malloc(buffersize*sizeof(char));
}
boost::mpi::broadcast(comm,buffer,buffersize,root);
if (comm.rank()!=root) {
for(size_t i = 0; i < buffersize; ++i) stream << buffer[i];
free(buffer);
}
}
}
}
// end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment