增加了日志库,更好的输出

This commit is contained in:
YuhangQ 2023-04-04 09:29:26 +00:00
parent 9effe67a40
commit 2829204b3f
12 changed files with 7755 additions and 35 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
build
.nfs*
*.o
myeasylog.log
light

BIN
light

Binary file not shown.

2
run.sh
View File

@ -1,3 +1,3 @@
#!/bin/bash
make -j 16 && mpirun -q -np 4 --allow-run-as-root ./light -i data/class_1_easy_10_0.cnf --share=1 --threads=4 --times=1
make -j 16 && mpirun -q -np 4 --allow-run-as-root ./light -i data/class_1_easy_10_0.cnf --share=1 --threads=4 --times=60

View File

@ -8,6 +8,7 @@
#include "comm_tag.h"
#include "../light.hpp"
#include "../utils/cmdline.h"
#include "../utils/easylogging++.h"
#include "../paras.hpp"
#include "heartbeat.h"
@ -17,9 +18,15 @@ void leader_main(light* S, int num_procs, int rank) {
auto clk_st = std::chrono::high_resolution_clock::now();
el::Configurations defaultConf;
defaultConf.setGlobally(el::ConfigurationType::Format, "c %level [leader] %msg");
el::Loggers::reconfigureLogger("default", defaultConf);
LOG(INFO) << "start logging powered by easylogging++";
S->opt->print_change();
printf("c [leader] preprocess(simplify) input data\n");
LOG(INFO) << "c [leader] preprocess(simplify) input data";
// 进行化简
auto pre = new preprocess();
@ -33,7 +40,7 @@ void leader_main(light* S, int num_procs, int rank) {
// preprocess 证明了UNSAT 则不需要启动云计算
if(!start) {
printf("UNSAT!!!!!! by preprocess\n");
LOGGER->info("UNSAT!!!!!! by preprocess");
return;
}
@ -50,7 +57,7 @@ void leader_main(light* S, int num_procs, int rank) {
const auto& str_ref = ss.str();
char* cstr = const_cast<char *>(str_ref.c_str());
printf("c [leader] hand out length of cnf instance to all nodes\n");
LOGGER->info("hand out length of cnf instance to all nodes");
int cnf_length = str_ref.size();
@ -60,13 +67,13 @@ void leader_main(light* S, int num_procs, int rank) {
MPI_Barrier(MPI_COMM_WORLD);
printf("c [leader] hand out cnf instance to all nodes\n");
LOGGER->info("hand out cnf instance to all nodes");
MPI_Bcast(cstr, cnf_length, MPI_CHAR, 0, MPI_COMM_WORLD);
MPI_Barrier(MPI_COMM_WORLD);
printf("c [leader] hand out done!\n");
LOGGER->info("hand out done!");
int is_sat;
MPI_Request solved;
@ -80,7 +87,7 @@ void leader_main(light* S, int num_procs, int rank) {
auto clk_now = std::chrono::high_resolution_clock::now();
int solve_time = std::chrono::duration_cast<std::chrono::seconds>(clk_now - clk_st).count();
if (solve_time >= S->opt->times) {
printf("c [leader] solve time out\n");
LOGGER->info("solve time out");
break;
}
@ -100,8 +107,8 @@ void leader_main(light* S, int num_procs, int rank) {
// send signal for getting solution(model) when sat
if(is_sat) {
printf("recive model size: %d\n", pre->vars);
printf("SAT!!!!!!\n");
LOGGER->info("recived model size: %v", pre->vars);
LOGGER->info("SAT!!!!!!");
MPI_Send(NULL, 0, MPI_INT, status.MPI_SOURCE, MODEL_REPORT_TAG, MPI_COMM_WORLD);
int* sol = new int[pre->vars];
@ -114,7 +121,7 @@ void leader_main(light* S, int num_procs, int rank) {
delete []sol;
} else {
printf("UNSAT!!!!!!\n");
LOGGER->info("UNSAT!!!!!!");
}
break;
}

View File

@ -6,6 +6,7 @@
#include "../light.hpp"
#include "../utils/cmdline.h"
#include "../utils/easylogging++.h"
#include "../paras.hpp"
#include "comm_tag.h"
@ -13,11 +14,17 @@ void worker_main(light* S, int num_procs, int rank) {
auto clk_st = std::chrono::high_resolution_clock::now();
el::Configurations defaultConf;
char tmp_format[1024];
sprintf(tmp_format, "c %%level [worker%d] %%msg", rank);
defaultConf.setGlobally(el::ConfigurationType::Format, tmp_format);
el::Loggers::reconfigureLogger("default", defaultConf);
// 阻塞接收初始化信号
int start;
MPI_Recv(&start, 1, MPI_INT, 0, START_TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
if(!start) {
printf("c worker%d has no need to start\n", rank);
LOGGER->info("I has no need to start");
return;
}
@ -42,6 +49,8 @@ void worker_main(light* S, int num_procs, int rank) {
int res = S->run();
LOGGER->info("kissat exit with result: %v", res);
MPI_Request solved_request, model_request;
MPI_Irecv(NULL, 0, MPI_INT, 0, MODEL_REPORT_TAG, MPI_COMM_WORLD, &model_request);
@ -57,21 +66,21 @@ void worker_main(light* S, int num_procs, int rank) {
auto clk_now = std::chrono::high_resolution_clock::now();
int solve_time = std::chrono::duration_cast<std::chrono::seconds>(clk_now - clk_st).count();
if (solve_time >= S->opt->times) {
printf("c [worker%d] solve time out\n", rank);
LOGGER->info("solve time out");
break;
}
// when getting terminate signal
if(MPI_Test(&S->terminal_request, &flag, MPI_STATUS_IGNORE) == MPI_SUCCESS && flag == 1) {
printf(">>>>>>> worker%d : terminate\n", rank);
LOGGER->info("getting terminate signal");
break;
}
// when getting model signal
if(MPI_Test(&model_request, &flag, MPI_STATUS_IGNORE) == MPI_SUCCESS && flag == 1) {
printf(">>>>>>> worker%d : get send signal\n", rank);
LOGGER->info("getting send model signal");
// send model and break;
MPI_Send(S->model.data, S->model.size(), MPI_INT, 0, MODEL_REPORT_TAG, MPI_COMM_WORLD);

View File

@ -1,7 +1,7 @@
#ifndef _light_hpp_INCLUDED
#define _light_hpp_INCLUDED
#include "utils/easylogging++.h"
#include "utils/parse.hpp"
#include "preprocess/preprocess.hpp"
#include "paras.hpp"
@ -14,6 +14,8 @@
#include <mpi.h>
typedef long long ll;
#define LOGGER el::Loggers::getLogger("default")
class basesolver;
class sharer;

View File

@ -11,8 +11,9 @@
#include "distributed/leader.hpp"
#include "distributed/worker.hpp"
int main(int argc, char **argv) {
INITIALIZE_EASYLOGGINGPP
int main(int argc, char **argv) {
int num_procs, rank;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &num_procs);

View File

@ -7,6 +7,7 @@
#include <algorithm>
#include <mutex>
#include "mpi.h"
#include "utils/easylogging++.h"
auto clk_st = std::chrono::high_resolution_clock::now();
char* worker_sign = "";
@ -29,22 +30,22 @@ void * solve_worker(void *arg) {
while (!terminated) {
int res = sq->solve();
if (sq->controller->opt->DPS) {
printf("c %d solved, res is %d\n", sq->id, res);
//printf("c %d solved, res is %d\n", sq->id, res);
if (res) {
terminated = 1;
result = res;
printf("c %d solved 1\n", sq->id);
//printf("c %d solved 1\n", sq->id);
sq->internal_terminate();
printf("c %d solved 2\n", sq->id);
//printf("c %d solved 2\n", sq->id);
sq->controller->update_winner(sq->id, sq->period);
printf("c %d solved 3\n", sq->id);
//printf("c %d solved 3\n", sq->id);
if (res == 10) sq->get_model(sq->model);
}
printf("c %d really solved, period is %d\n", sq->id, sq->period);
//printf("c %d really solved, period is %d\n", sq->id, sq->period);
}
else {
if (res && !terminated) {
printf("c result: %d, winner is %d, winner run %d confs\n", res, sq->id, sq->get_conflicts());
//printf("c result: %d, winner is %d, winner run %d confs\n", res, sq->id, sq->get_conflicts());
terminated = 1;
sq->controller->terminate_workers();
result = res;
@ -52,7 +53,7 @@ void * solve_worker(void *arg) {
winner_conf = sq->get_conflicts();
if (res == 10) sq->get_model(sq->model);
}
printf("get result %d with res %d\n", sq->id, res);
//printf("get result %d with res %d\n", sq->id, res);
}
}
return NULL;
@ -113,7 +114,7 @@ void light::diversity_workers() {
}
void light::terminate_workers() {
printf("c controller reach limit\n");
// printf("c controller reach limit\n");
for (int i = 0; i < OPT(threads); i++) {
if (OPT(share) == 1 && OPT(DPS) == 1)
workers[i]->external_terminate();
@ -139,7 +140,9 @@ void light::parse_input() {
}
int light::solve() {
printf("c -----------------solve start----------------------\n");
// printf("c -----------------solve start----------------------\n");
LOG(INFO) << "solve start";
pthread_t *ptr = new pthread_t[OPT(threads)];
for (int i = 0; i < OPT(threads); i++) {
pthread_create(&ptr[i], NULL, solve_worker, workers[i]);
@ -166,23 +169,23 @@ int light::solve() {
terminate_workers();
}
}
printf("ending solve\n");
// printf("ending solve\n");
// terminate_workers(); //important, need combine nps/dps !!!!!!!!!!!!!!!!
for (int i = 0; i < OPT(threads); i++) {
pthread_join(ptr[i], NULL);
}
printf("ending join\n");
// printf("ending join\n");
if (result == 10)
workers[winner_id]->model.copyTo(model);
auto clk_now = std::chrono::high_resolution_clock::now();
double solve_time = std::chrono::duration_cast<std::chrono::milliseconds>(clk_now - clk_sol_st).count();
solve_time = 0.001 * solve_time;
printf("c solve time: %.2lf\nwinner is %d, period is %d\n", solve_time, winner_id, winner_period);
for (int i = 0; i < OPT(threads); i++) {
printf("c thread %d waiting time: %.2lf\n", i, workers[i]->get_waiting_time());
}
// printf("c solve time: %.2lf\nwinner is %d, period is %d\n", solve_time, winner_id, winner_period);
// for (int i = 0; i < OPT(threads); i++) {
// printf("c thread %d waiting time: %.2lf\n", i, workers[i]->get_waiting_time());
// }
delete []ptr;
return result;
}

3120
src/utils/easylogging++.cc Normal file

File diff suppressed because it is too large Load Diff

4576
src/utils/easylogging++.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -16,7 +16,7 @@ void basekissat::add(int l) {
}
void basekissat::configure(const char* name, int val) {
printf("c %d set %s to %d\n", id, name, val);
// printf("c %d set %s to %d\n", id, name, val);
kissat_set_option(solver, name, val);
}

View File

@ -15,7 +15,7 @@ void * share_worker(void *arg) {
usleep(sq->share_intv);
auto clk_now = std::chrono::high_resolution_clock::now();
int solve_time = std::chrono::duration_cast<std::chrono::milliseconds>(clk_now - clk_st).count();
printf("c round %d, time: %d.%03d\n", nums, solve_time / 1000, solve_time % 1000);
LOGGER->info("round %v, time: %v.%v", nums, solve_time / 1000, solve_time % 1000);
if (terminated) break;
// printf("start sharing %d\n", sq->share_intv);
for (int i = 0; i < sq->producers.size(); i++) {
@ -114,7 +114,7 @@ int sharer::sort_clauses(int x) {
}
void light::share() {
printf("c sharing start\n");
// printf("c sharing start\n");
if (OPT(DPS)) {
sharer* s = new sharer(0, OPT(share_intv), OPT(share_lits), OPT(DPS));
s->margin = OPT(margin);