diff --git a/src/workers/sharer.cpp b/src/workers/sharer.cpp index b4cf0df..55329fb 100644 --- a/src/workers/sharer.cpp +++ b/src/workers/sharer.cpp @@ -6,7 +6,12 @@ #include "../distributed/comm_tag.h" #include -void share_clauses_to_next_node(std::vector> &send_data_struct, const vec &cls) { +const int BUF_SIZE = 1024 * 1024; +std::vector> send_data_struct; +MPI_Request receive_request; +int buf[BUF_SIZE]; + +void share_clauses_to_next_node(const vec &cls) { // 清理 send_data_struct,把发送完毕的发送数据结构清理掉 for(int i=0; i> &send_ LOGGER->info("send clauses: %v", send_length); } -const int BUF_SIZE = 1024 * 1024; -bool receive_clauses_from_last_node(MPI_Request &receive_request, int *buf, vec &clauses) { + +bool receive_clauses_from_last_node(vec &clauses) { clauses.clear(); int flag; @@ -115,18 +120,12 @@ void * share_worker(void *arg) { auto clk_st = std::chrono::high_resolution_clock::now(); double share_time = 0; - std::vector> send_data_struct; + // int num_procs, rank; + // MPI_Comm_size(MPI_COMM_WORLD, &num_procs); + // MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Request receive_request; - - int buf[BUF_SIZE]; - - int num_procs, rank; - MPI_Comm_size(MPI_COMM_WORLD, &num_procs); - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - - int from = (rank - 2 + num_procs - 1) % (num_procs - 1) + 1; - MPI_Irecv(buf, BUF_SIZE, MPI_INT, from, SHARE_CLAUSES_TAG, MPI_COMM_WORLD, &receive_request); + // int from = (rank - 2 + num_procs - 1) % (num_procs - 1) + 1; + // MPI_Irecv(buf, BUF_SIZE, MPI_INT, from, SHARE_CLAUSES_TAG, MPI_COMM_WORLD, &receive_request); while (true) { ++nums; @@ -139,31 +138,31 @@ void * share_worker(void *arg) { for (int i = 0; i < sq->producers.size(); i++) { sq->cls.clear(); sq->producers[i]->export_clauses_to(sq->cls); - printf("c size %d\n", sq->cls.size()); + + //printf("c size %d\n", sq->cls.size()); + int number = sq->cls.size(); LOGGER->info("thread-%v: get %v exported clauses", i, number); - - //分享当前节点产生的子句 - //if(sq->cls.size() > 0) share_clauses_to_next_node(send_data_struct, sq->cls); + // //分享当前节点产生的子句 + // if(sq->cls.size() > 0) share_clauses_to_next_node(sq->cls); + // // 导入外部网络传输的子句 + // vec clauses; + // if(receive_clauses_from_last_node(clauses)) { + // for (int j = 0; j < sq->consumers.size(); j++) { + // for (int k = 0; k < clauses.size(); k++) + // clauses[k]->increase_refs(1); + // sq->consumers[j]->import_clauses_from(clauses); + // } - // 导入外部网络传输的子句 - //vec clauses; - // if(receive_clauses_from_last_node(receive_request, buf, clauses)) { - // // for (int j = 0; j < sq->consumers.size(); j++) { - // // for (int k = 0; k < clauses.size(); k++) - // // clauses[k]->increase_refs(1); - // // sq->consumers[j]->import_clauses_from(clauses); - // // } + // // 传递外部网络传输的子句给下个节点 + // share_clauses_to_next_node(clauses); - // // // 传递外部网络传输的子句给下个节点 - // // share_clauses_to_next_node(send_data_struct, clauses); - - // // for (int k = 0; k < clauses.size(); k++) { - // // clauses[k]->free_clause(); - // // } + // for (int k = 0; k < clauses.size(); k++) { + // clauses[k]->free_clause(); + // } // } // 导入当前节点产生的子句 @@ -172,15 +171,15 @@ void * share_worker(void *arg) { sq->producers[i]->broaden_export_limit(); } else if (percent > 98) { - //sq->producers[i]->restrict_export_limit(); + sq->producers[i]->restrict_export_limit(); } - // for (int j = 0; j < sq->consumers.size(); j++) { - // if (sq->producers[i]->id == sq->consumers[j]->id) continue; - // for (int k = 0; k < sq->cls.size(); k++) - // sq->cls[k]->increase_refs(1); - // sq->consumers[j]->import_clauses_from(sq->cls); - // } + for (int j = 0; j < sq->consumers.size(); j++) { + if (sq->producers[i]->id == sq->consumers[j]->id) continue; + for (int k = 0; k < sq->cls.size(); k++) + sq->cls[k]->increase_refs(1); + sq->consumers[j]->import_clauses_from(sq->cls); + } for (int k = 0; k < sq->cls.size(); k++) { sq->cls[k]->free_clause(); }