~ubuntu-branches/ubuntu/saucy/rheolef/saucy

« back to all changes in this revision

Viewing changes to skit/ptst2/mpi_boost_pair_exchange_tst.cc

  • Committer: Bazaar Package Importer
  • Author(s): Pierre Saramito
  • Date: 2011-02-08 10:00:06 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110208100006-jg8rarizvhdm8e82
Tags: 5.92-1
* New upstream release:
  - "rheolef" suffix added to all unix manuals (Closes: #607117)
  - minor source code fixes for g++-4.5 (Closes: #607184)
  - minor reference manual fix (Closes: #607038)
* debian/control: libboost-iostreams-dev dependency added, as required
  by the new upstream version.
 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
///
 
2
/// This file is part of Rheolef.
 
3
///
 
4
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
 
5
///
 
6
/// Rheolef is free software; you can redistribute it and/or modify
 
7
/// it under the terms of the GNU General Public License as published by
 
8
/// the Free Software Foundation; either version 2 of the License, or
 
9
/// (at your option) any later version.
 
10
///
 
11
/// Rheolef is distributed in the hope that it will be useful,
 
12
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
/// GNU General Public License for more details.
 
15
///
 
16
/// You should have received a copy of the GNU General Public License
 
17
/// along with Rheolef; if not, write to the Free Software
 
18
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
///
 
20
/// =========================================================================
 
21
#include "rheolef/config.h"
 
22
#ifndef _RHEOLEF_HAVE_MPI
 
23
int main() {return 0;}
 
24
#else // _RHEOLEF_HAVE_MPI
 
25
 
 
26
#include <rheolef/distributor.h>
 
27
using namespace rheolef;
 
28
using namespace std;
 
29
// -------------------------------------------------------------
 
30
// send a pair<size_t,T> via mpi & serialization
 
31
// -------------------------------------------------------------
 
32
// non-intrusive version of serialization for pair<size_t,T> 
 
33
namespace boost {
 
34
 namespace serialization {
 
35
  template<class T, class Archive>
 
36
  void serialize (Archive & ar, std::pair<size_t, T>& g, const unsigned int version) {
 
37
    ar & g.first;
 
38
    ar & g.second;
 
39
  }
 
40
 } // namespace serialization
 
41
} // namespace boost
 
42
// -------------------------------------------------------------
 
43
// usage
 
44
// -------------------------------------------------------------
 
45
typedef pair<size_t,double> pair_t;
 
46
int main(int argc, char* argv[]) {
 
47
  environment parallel(argc, argv);
 
48
  mpi::communicator comm;
 
49
  if (comm.size() != 2) return 0;
 
50
  if (comm.rank() == 0) {
 
51
    pair_t p_send (1,1.1);
 
52
    comm.send(1, 0, p_send);
 
53
    pair_t p_recv;
 
54
    comm.recv(1, 1, p_recv);
 
55
    cout << "[0]{" << p_recv.first << "," << p_recv.second << "}" << endl << flush;
 
56
  } else {
 
57
    pair_t p_recv;
 
58
    comm.recv(0, 0, p_recv);
 
59
    cout << "[1]{" << p_recv.first << "," << p_recv.second << "}" << endl << flush;
 
60
    pair_t p_send (2,2.2);
 
61
    comm.send(0, 1, p_send);
 
62
  }
 
63
}
 
64
#endif // _RHEOLEF_HAVE_MPI