GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dc_init_from_mpi.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 <cstdio>
26 #include <cstdlib>
27 #include <string>
28 #include <graphlab/rpc/dc.hpp>
29 #include <graphlab/rpc/dc_init_from_mpi.hpp>
30 #include <graphlab/util/stl_util.hpp>
31 #include <graphlab/util/net_util.hpp>
33 
34 #ifdef HAS_MPI
35 #include <graphlab/util/mpi_tools.hpp>
36 #endif
37 namespace graphlab {
38 
40 #ifdef HAS_MPI
41  ASSERT_MSG(commtype == TCP_COMM, "MPI initialization only supports TCP at the moment");
42  // Look for a free port to use.
43  std::pair<size_t, int> port_and_sock = get_free_tcp_port();
44  size_t port = port_and_sock.first;
45  int sock = port_and_sock.second;
46 
47  std::string ipaddr =
48  get_local_ip_as_str(mpi_tools::rank() == 0 /* print stuff only if I am master */);
49  ipaddr = ipaddr + ":" + tostr(port);
50  // now do an allgather
51  logstream(LOG_INFO) << "Will Listen on: " << ipaddr << std::endl;
52  std::vector<std::string> machines;
53  mpi_tools::all_gather(ipaddr, param.machines);
54  // set defaults
55  param.curmachineid = (procid_t)(mpi_tools::rank());
56 
58  param.commtype = commtype;
59  param.initstring = param.initstring + std::string(" __sockhandle__=") + tostr(sock) + " ";
60  return true;
61 #else
62  std::cerr << "MPI Support not compiled!" << std::endl;
63  exit(0);
64 #endif
65 }
66 
67 } // namespace graphlab
68 
69