GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rpc_example6.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 <vector>
27 #include <graphlab/rpc/dc.hpp>
28 #include <graphlab/util/generics/any.hpp>
29 using namespace graphlab;
30 
31 
32 void print(any val) {
33  val.print(std::cout);
34  std::cout << std::endl;
35 }
36 
37 
38 int main(int argc, char ** argv) {
39  mpi_tools::init(argc, argv);
41 
42  if (dc.numprocs() != 2) {
43  std::cout<< "RPC Example 6: Asynchronous RPC with any \n";
44  std::cout << "Run with exactly 2 MPI nodes.\n";
45  return 0;
46  }
47 
48  if (dc.procid() == 0) {
49  dc.remote_call(1, print, any(15));
50  dc.remote_call(1, print, any(10.5));
51  dc.remote_call(1, print, any(std::string("hello world")));
52  }
53 
54  int i = dc.procid() == 0 ? 10 : 100;
55  dc.broadcast(i, dc.procid() == 0);
56  std::cout << i << std::endl;
57  assert(i == 10);
58 
59  mpi_tools::finalize();
60 }