linkers_mpi.cpp 860 Bytes
Newer Older
Guolin Ke's avatar
Guolin Ke committed
1
2
3
4
5
#ifdef USE_MPI
#include "linkers.h"

namespace LightGBM {

Guolin Ke's avatar
Guolin Ke committed
6
Linkers::Linkers(Config) {
7
  is_init_ = false;
Guolin Ke's avatar
Guolin Ke committed
8
9
10
11
12
13
14
15
16
17
18
19
20
  int argc = 0;
  char**argv = nullptr;
  int flag = 0;
  MPI_SAFE_CALL(MPI_Initialized(&flag));  // test if MPI has been initialized
  if (!flag) {  // if MPI not started, start it
    MPI_SAFE_CALL(MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &flag));
  }
  MPI_SAFE_CALL(MPI_Comm_size(MPI_COMM_WORLD, &num_machines_));
  MPI_SAFE_CALL(MPI_Comm_rank(MPI_COMM_WORLD, &rank_));
  // wait for all client start up
  MPI_SAFE_CALL(MPI_Barrier(MPI_COMM_WORLD));
  bruck_map_ = BruckMap::Construct(rank_, num_machines_);
  recursive_halving_map_ = RecursiveHalvingMap::Construct(rank_, num_machines_);
21
  is_init_ = true;
Guolin Ke's avatar
Guolin Ke committed
22
23
24
}

Linkers::~Linkers() {
25
26
27
  if (is_init_) {
    MPI_SAFE_CALL(MPI_Finalize());
  }
Guolin Ke's avatar
Guolin Ke committed
28
29
30
31
}


}  // namespace LightGBM
32
#endif  // USE_MPI