GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
mpi_tools.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 <graphlab/util/net_util.hpp>
25 #include <graphlab/util/mpi_tools.hpp>
26 
27 namespace graphlab {
28  namespace mpi_tools {
29  void get_master_ranks(std::set<size_t>& master_ranks) {
30  uint32_t local_ip = get_local_ip();
31  std::vector<uint32_t> all_ips;
32  all_gather(local_ip, all_ips);
33  std::set<uint32_t> visited_ips;
34  master_ranks.clear();
35  for(size_t i = 0; i < all_ips.size(); ++i) {
36  if(visited_ips.count(all_ips[i]) == 0) {
37  visited_ips.insert(all_ips[i]);
38  master_ranks.insert(i);
39  }
40  }
41  }
42  }
43 }
44