修改了OPT配置的实现,但存在BUG

This commit is contained in:
YuhangQ 2023-04-18 14:01:11 +08:00
parent bfc3567323
commit 65f4c77a7e
13 changed files with 120 additions and 131 deletions

3
.gitignore vendored
View File

@ -3,4 +3,5 @@ build
*.o
myeasylog.log
light
exp-result*
exp-result*
experiment

5
bug.txt Normal file
View File

@ -0,0 +1,5 @@
退出太慢了:
3fb045f58aaf394165735c39c49fad92-linked_list_swap_contents_safety_unwind56.cnf
预处理退出了:
59e596f5f845a2487370950b37ec3db2-aws-encryption-sdk-c:aws_cryptosdk_enc_ctx_size.cnf

View File

@ -6,7 +6,7 @@ OBJECTS := $(addprefix build/,$(SOURCES:%=%.o))
# 声明编译器和编译选项
CXX := mpicxx
CXXFLAGS := -O3 -Wall -Wextra -MMD -MP -march=native -mtune=native -g
CXXFLAGS := -O3 -Wall -Wextra -MMD -MP -march=native -mtune=native -g
LIBS := -Wl,-Bstatic -lkissat -L kissat-inc/build -I kissat-inc/ \
-lm4ri -L m4ri-20140914/.libs -I m4ri-20140914/ \

26
run_docker.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
make -j 8
cd ./docker
cp ../light .
DOCKER_NETWORK="mallob-test"
docker build --no-cache -f common.dockerfile -t light:common .
docker build --no-cache -f leader.dockerfile -t light:leader .
docker build --no-cache -f worker.dockerfile -t light:worker .
docker stop worker1
docker stop worker2
docker stop worker3
docker run -d --name worker1 --network $DOCKER_NETWORK --entrypoint bash --rm -t light:worker -c "/competition/init_solver.sh; exec bash"
docker run -d --name worker2 --network $DOCKER_NETWORK --entrypoint bash --rm -t light:worker -c "/competition/init_solver.sh; exec bash"
docker run -d --name worker3 --network $DOCKER_NETWORK --entrypoint bash --rm -t light:worker -c "/competition/init_solver.sh; exec bash"
docker stop leader
docker run -i --name leader --network $DOCKER_NETWORK --entrypoint bash --rm -t light:leader -c "/competition/init_solver.sh; exec bash"

View File

@ -15,13 +15,13 @@ void leader_main(light* S, int num_procs, int rank) {
auto clk_st = std::chrono::high_resolution_clock::now();
S->opt->print_change();
__global_paras.print_change();
printf("c [leader] preprocess(simplify) input data\n");
// 进行化简
auto pre = new preprocess();
char *filename = const_cast<char*>(S->opt->instance.c_str());
char *filename = const_cast<char*>(OPT(instance).c_str());
int start = pre->do_preprocess(filename);
// 给每个 worker 发布是否启动计算流程的信息
@ -82,7 +82,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) {
if (solve_time >= OPT(times)) {
printf("c [leader] solve time out\n");
break;
}

View File

@ -60,7 +60,7 @@ 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) {
if (solve_time >= OPT(times)) {
printf("c [worker%d] solve time out\n", rank);
break;
}

View File

@ -12,8 +12,8 @@ light::light():
winner_id (-1),
maxtime (5000)
{
opt = new paras();
opt->init_paras();
// opt = new paras();
//opt->init_paras();
}
light::~light() {
@ -21,48 +21,48 @@ light::~light() {
workers.clear(true);
}
void light::configure_from_file(const char* file) {
if (!strcmp(file, "")) {
configure_name = new vec<char*>[OPT(threads)];
configure_val = new vec<double>[OPT(threads)];
return;
}
printf("c Get configure file: %s\n", file);
std::ifstream fin(file);
char buf[1000];
fin.getline(buf, 1000);
char *p = buf + 6;
int ws, ss, id = 0;
p = read_int(p, &ws);
p = read_int(p, &ss);
printf("%d %d\n", ws, ss);
opt->set_para("threads", ws);
configure_name = new vec<char*>[ws];
configure_val = new vec<double>[ws];
while (fin.getline(buf, 1000)) {
p = strtok(buf, " ");
printf("%s\n", p);
solver_type.push(0);
while (p) {
p = strtok(NULL, " ");
printf("%s\n", p);
if (!p) break;
int l = strlen(p), pos = 0;
for (int i = 1; i < l; i++)
if (p[i] == '=') pos = i;
char *name = new char[pos];
strncpy(name, p, pos);
printf("%s\n", name);
configure_name[id].push(name);
char *val = p + pos + 1;
double v = atof(val);
printf("%.2lf\n", v);
configure_val[id].push(v);
}
printf("out\n");
id++;
}
}
// void light::configure_from_file(const char* file) {
// if (!strcmp(file, "")) {
// configure_name = new vec<char*>[OPT(threads)];
// configure_val = new vec<double>[OPT(threads)];
// return;
// }
// printf("c Get configure file: %s\n", file);
// std::ifstream fin(file);
// char buf[1000];
// fin.getline(buf, 1000);
// char *p = buf + 6;
// int ws, ss, id = 0;
// p = read_int(p, &ws);
// p = read_int(p, &ss);
// printf("%d %d\n", ws, ss);
// opt->set_para("threads", ws);
// configure_name = new vec<char*>[ws];
// configure_val = new vec<double>[ws];
// while (fin.getline(buf, 1000)) {
// p = strtok(buf, " ");
// printf("%s\n", p);
// solver_type.push(0);
// while (p) {
// p = strtok(NULL, " ");
// printf("%s\n", p);
// if (!p) break;
// int l = strlen(p), pos = 0;
// for (int i = 1; i < l; i++)
// if (p[i] == '=') pos = i;
// char *name = new char[pos];
// strncpy(name, p, pos);
// printf("%s\n", name);
// configure_name[id].push(name);
// char *val = p + pos + 1;
// double v = atof(val);
// printf("%.2lf\n", v);
// configure_val[id].push(v);
// }
// printf("out\n");
// id++;
// }
// }
void light::arg_parse(int argc, char **argv) {
cmdline::parser parser;
@ -95,6 +95,4 @@ void light::arg_parse(int argc, char **argv) {
filename = new char[file_string.size() + 1];
memcpy(filename, file_string.c_str(), file_string.length());
filename[file_string.length()] = '\0';
configure_from_file(OPT(config).c_str());
}

View File

@ -36,7 +36,7 @@ struct light
public:
light();
~light();
paras *opt;
// paras *opt;
preprocess *pre;
vec<int> solver_type;
vec<basesolver *> workers;
@ -73,7 +73,6 @@ public:
return winner_period;
}
void arg_parse(int argc, char **argv);
void configure_from_file(const char* file);
void init_workers();
void diversity_workers();
void parse_input();
@ -82,6 +81,7 @@ public:
int solve();
void terminate_workers();
void print_model();
};
#endif

View File

@ -2,46 +2,9 @@
#include <cstdio>
#include <iostream>
#include <string>
paras __global_paras;
void paras::init_paras() {
#define PARA(N, T, S, M, D, L, H, C) \
if (!strcmp(#T, "int")) map_int[#N] = D; \
else map_double[#N] = D;
PARAS
#undef PARA
#define STR_PARA(N, S, M, D, C) \
map_string[#N] = D;
STR_PARAS
#undef STR_PARA
}
void paras::sync_paras() {
#define PARA(N, T, S, M, D, L, H, C) \
if (!strcmp(#T, "int")) N = map_int[#N]; \
else N = map_double[#N];
PARAS
#undef PARA
#define STR_PARA(N, S, M, D, C) \
N = map_string[#N];
STR_PARAS
#undef STR_PARAs
}
void paras::set_para(char *name, int val) {
map_int[name] = val;
}
void paras::set_para(char *name, double val) {
map_double[name] = val;
}
void paras::set_para(char *name, char* val) {
map_string[name] = val;
}
void paras::print_change() {
printf("c ------------------- Paras list -------------------\n");
printf("c %-20s\t %-10s\t %-10s\t %-10s\t %s\n",
@ -59,4 +22,4 @@ void paras::print_change() {
#undef STR_PARA
printf("c --------------------------------------------------\n");
}
}

View File

@ -43,15 +43,11 @@ struct paras
std::unordered_map<std::string, int> map_int;
std::unordered_map<std::string, double> map_double;
std::unordered_map<std::string, char*> map_string;
void init_paras ();
void sync_paras ();
void print_change ();
void set_para (char *arg, int val);
void set_para (char *arg, double val);
void set_para (char *arg, char* val);
};
#define OPT(N) (opt->N)
extern paras __global_paras;
#define OPT(N) (__global_paras.N)
#endif

View File

@ -29,7 +29,7 @@ void * solve_worker(void *arg) {
basesolver * sq = (basesolver *)arg;
while (!terminated) {
int res = sq->solve();
if (sq->controller->opt->DPS) {
if (OPT(DPS)) {
//printf("c %d solved, res is %d\n", sq->id, res);
if (res) {
terminated = 1;

View File

@ -101,13 +101,13 @@ basekissat::basekissat(int id, light* light) : basesolver(id, light) {
solver -> cbkImportClause = NULL;
solver -> cbkExportClause = NULL;
solver -> cbk_start_new_period = NULL;
if (light->opt->share) {
if (OPT(share)) {
solver -> cbkImportClause = call_back_in;
solver -> cbkExportClause = call_back_out;
solver -> cbk_start_new_period = cbk_start_new_period;
solver -> cbk_free_clauses = cbk_free_clauses;
solver -> dps = light->opt->DPS;
solver -> dps_period = light->opt->DPS_period;
solver -> dps = OPT(DPS);
solver -> dps_period = OPT(DPS_period);
}
}

View File

@ -16,12 +16,12 @@ std::vector<std::pair<MPI_Request*, int*>> send_data_struct;
MPI_Request receive_request;
int buf[BUF_SIZE];
int num_received_clauses_by_network = 0;
int num_skip_clauses_by_network = 0;
// int num_received_clauses_by_network = 0;
// int num_skip_clauses_by_network = 0;
// 记录子句是否已经导入过
// // 记录子句是否已经导入过
std::unordered_map<int, bool> clause_imported;
// std::unordered_map<int, bool> clause_imported;
void share_clauses_to_next_node(int from, const std::vector<shared_ptr<clause_store>> &cls) {
@ -99,7 +99,7 @@ bool receive_clauses_from_last_node(std::vector<shared_ptr<clause_store>> &claus
from = buf[index++];
while(index < count) {
num_received_clauses_by_network++;
//num_received_clauses_by_network++;
shared_ptr<clause_store> cl = std::make_shared<clause_store>(buf[index++]);
@ -108,11 +108,11 @@ bool receive_clauses_from_last_node(std::vector<shared_ptr<clause_store>> &claus
cl->data[i] = buf[index++];
}
if(clause_imported[cl->hash_code()]) {
// if(clause_imported[cl->hash_code()]) {
num_skip_clauses_by_network++;
continue;
}
// num_skip_clauses_by_network++;
// continue;
// }
clauses.push_back(cl);
}
@ -138,9 +138,9 @@ void sharer::clause_sharing_init() {
void sharer::clause_sharing_end() {
printf("c sharing nums: %d\nc sharing time: %.2lf\n", nums, share_time);
printf("c sharing received_num_by_network: %d\n", num_received_clauses_by_network);
printf("c sharing skip_num_by_network: %d\n", num_skip_clauses_by_network);
printf("c sharing unique reduce percentage: %.2f%%\n", (double) num_skip_clauses_by_network / num_received_clauses_by_network * 100);
// printf("c sharing received_num_by_network: %d\n", num_received_clauses_by_network);
// printf("c sharing skip_num_by_network: %d\n", num_skip_clauses_by_network);
// printf("c sharing unique reduce percentage: %.2f%%\n", (double) num_skip_clauses_by_network / num_received_clauses_by_network * 100);
}
void sharer::do_clause_sharing() {
@ -163,9 +163,9 @@ void sharer::do_clause_sharing() {
consumers[j]->import_clauses_from(clauses);
}
for (int k = 0; k < clauses.size(); k++) {
clause_imported[clauses[k]->hash_code()] = true;
}
// for (int k = 0; k < clauses.size(); k++) {
// clause_imported[clauses[k]->hash_code()] = true;
// }
// 传递外部网络传输的子句给下个节点
share_clauses_to_next_node(from, clauses);
@ -177,14 +177,14 @@ void sharer::do_clause_sharing() {
producers[i]->export_clauses_to(cls);
// 删除掉重复的学习子句
int t_size = cls.size();
for(int i=0; i<t_size; i++) {
if(clause_imported[cls[i]->hash_code()]) {
std::swap(cls[i], cls[t_size-1]);
t_size--;
}
}
cls.resize(t_size);
// int t_size = cls.size();
// for(int i=0; i<t_size; i++) {
// if(clause_imported[cls[i]->hash_code()]) {
// std::swap(cls[i], cls[t_size-1]);
// t_size--;
// }
// }
// cls.resize(t_size);
//分享当前节点产生的子句
if(cls.size() > 0) share_clauses_to_next_node(rank, cls);
@ -205,9 +205,9 @@ void sharer::do_clause_sharing() {
if (producers[i]->id == consumers[j]->id) continue;
consumers[j]->import_clauses_from(cls);
}
for (int k = 0; k < cls.size(); k++) {
clause_imported[cls[k]->hash_code()] = true;
}
// for (int k = 0; k < cls.size(); k++) {
// clause_imported[cls[k]->hash_code()] = true;
// }
}
auto clk_ed = std::chrono::high_resolution_clock::now();