44 lines
948 B
C++
44 lines
948 B
C++
|
|
#include <chrono>
|
|
#include <thread>
|
|
#include <fstream>
|
|
#include <mpi.h>
|
|
|
|
#include "light.hpp"
|
|
#include "utils/cmdline.h"
|
|
#include "paras.hpp"
|
|
|
|
#include "distributed/leader.hpp"
|
|
#include "distributed/worker.hpp"
|
|
|
|
#include "workers/clause.hpp"
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
int num_procs, rank;
|
|
MPI_Init(&argc, &argv);
|
|
MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
|
|
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
|
|
|
light* S = new light();
|
|
S->arg_parse(argc, argv);
|
|
|
|
// 初始化环形节点关系
|
|
S->rank = rank;
|
|
S->num_procs = num_procs;
|
|
if(rank == 0) {
|
|
S->last_node = S->next_node = 0;
|
|
} else {
|
|
S->last_node = (rank - 2 + num_procs - 1) % (num_procs - 1) + 1;
|
|
S->next_node = rank % (num_procs - 1) + 1;
|
|
}
|
|
|
|
// leader
|
|
if(rank == 0) leader_main(S, num_procs, rank);
|
|
else worker_main(S, num_procs, rank);
|
|
|
|
MPI_Barrier(MPI_COMM_WORLD);
|
|
MPI_Finalize();
|
|
|
|
return 0;
|
|
} |