GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rpc_example4.cpp
1 /*
2  * Copyright (c) 2009 Carnegie Mellon University.
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an "AS
13  * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14  * express or implied. See the License for the specific language
15  * governing permissions and limitations under the License.
16  *
17  * For more about this software visit:
18  *
19  * http://www.graphlab.ml.cmu.edu
20  *
21  */
22 
23 
24 #include <iostream>
25 #include <string>
26 #include <map>
27 #include <graphlab/rpc/dc.hpp>
28 #include <graphlab/serialization/serialization_includes.hpp>
29 
30 using namespace graphlab;
31 
32 struct teststruct{
33  int a;
34  double b;
35  std::vector<std::string> name;
36 
37  void save(oarchive &arc) const {
38  arc << a << b << name;
39  };
40  void load(iarchive &arc) {
41  arc >> a >> b >> name;
42  };
43 };
44 
45 
46 void print(std::map<int, teststruct> &data1,
47  std::string data2) {
48  std::cout << "1.a = " << data1[1].a << std::endl;
49  std::cout << "2.b = " << data1[2].b << std::endl;
50  std::cout << "string = " << data2 << std::endl;
51 }
52 
53 
54 
55 int main(int argc, char ** argv) {
56  mpi_tools::init(argc, argv);
58 
59  if (dc.numprocs() != 2) {
60  std::cout<< "RPC Example 4: Asynchronous RPC with Manual Serialization\n";
61  std::cout << "Run with exactly 2 MPI nodes.\n";
62  return 0;
63  }
64 
65  if (dc.procid() == 0) {
66  std::map<int, teststruct> data;
67  data[1].a = 10;
68  data[2].b = 15.0;
69  dc.remote_call(1, print, data, "hello world!");
70  }
71  dc.barrier();
72 
73  mpi_tools::finalize();
74 }