#include "main.h" long long int total_memory_allocation_calls=0; void * emalloc(size_t sz) { void *p; if ( (p=malloc(sz)) == 0) std::cerr << "Emalloc error." << std::endl; memset(p,0,sz); total_memory_allocation_calls++; return p; } void efree (void * pt) { total_memory_allocation_calls--; free(pt); } void my_Terminate_Handler (void) { std::cerr<<"####################################################"<(foo.size()) + 1; try { // This is wasteful. It would be much better to concatenate all // values that one wanted to pass into a string and pass that string. // At the other end, one would need to parse said string and make sure // all the value make sense. MPI::COMM_WORLD.Send(&max, 1, MPI_DOUBLE, dest, tag); MPI::COMM_WORLD.Send(&i, 1, MPI_INT, dest, tag); MPI::COMM_WORLD.Send(foo.c_str(), i, MPI_CHAR, dest, tag); } catch (MPI::Exception e) { std::cout << "RSP MPI ERROR [" << e.Get_error_code() << "] : \"" << e.Get_error_string() << "\"" << std::endl; throw e; } catch (...) { std::cerr << "Unknown expection" << std::endl; throw; } } void foobar::mpi_recv() { int i; MPI::Status status; try { MPI::COMM_WORLD.Recv(&max, 1, MPI_DOUBLE, MPI_ANY_SOURCE, MPI_ANY_TAG,status); MPI::COMM_WORLD.Recv(&i, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG,status); char *buf; buf = static_cast(emalloc(sizeof(char) * i)); MPI::COMM_WORLD.Recv(buf, i, MPI_CHAR, MPI_ANY_SOURCE, MPI_ANY_TAG, status); name = buf; efree(static_cast(buf)); } catch (MPI::Exception e) { std::cout << "RSP MPI ERROR [" << e.Get_error_code() << "] : \"" << e.Get_error_string() << "\"" << std::endl; throw e; } catch (...) { std::cerr << "Unknown expection" << std::endl; throw; } } int main (int argc, char **argv) { int size, rank; foobar test; MPI::Datatype foobar_type; MPI::Status status; try { MPI::Init(argc, argv); std::set_terminate(my_Terminate_Handler); size = MPI::COMM_WORLD.Get_size(); rank = MPI::COMM_WORLD.Get_rank(); } catch (MPI::Exception e) { std::cout << "RSP MPI ERROR [" << e.Get_error_code() << "] : \"" << e.Get_error_string() << "\"" << std::endl; throw e; } catch (...) { std::cout << "Unknown exception"; throw; } std::cout << "Node " << rank << " gives: \"" << test.get_str() << "\"" << std::endl; if (0 == rank) { std::cout << "Node " << rank << " setting string..." << std::endl; test.set_str("This is M_PI"); test.set_max(3.14159265359); for (int i=1; i