使用 share_ptr 解决了共享子句内存泄漏
This commit is contained in:
parent
f130694965
commit
918ae6817d
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -88,6 +88,7 @@
|
|||||||
"concepts": "cpp",
|
"concepts": "cpp",
|
||||||
"numbers": "cpp",
|
"numbers": "cpp",
|
||||||
"semaphore": "cpp",
|
"semaphore": "cpp",
|
||||||
"stop_token": "cpp"
|
"stop_token": "cpp",
|
||||||
|
"*.ipp": "cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
7
bug.txt
7
bug.txt
@ -1,3 +1,10 @@
|
|||||||
|
|
||||||
|
|
||||||
|
preprocess 占了特别大内存
|
||||||
|
/pub/data/chenzh/data/sat2022/04157f716c1e9606c6a530657bf8f957-Kakuro-easy-125-ext.xml.hg_4.cnf
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
==2320428==
|
==2320428==
|
||||||
==2320428== Process terminating with default action of signal 15 (SIGTERM)
|
==2320428== Process terminating with default action of signal 15 (SIGTERM)
|
||||||
==2320428== at 0x4DF912F: poll (poll.c:29)
|
==2320428== at 0x4DF912F: poll (poll.c:29)
|
||||||
|
32
cal.py
32
cal.py
@ -12,7 +12,7 @@ from time import monotonic, sleep
|
|||||||
from tokenize import Number
|
from tokenize import Number
|
||||||
|
|
||||||
# global limit
|
# global limit
|
||||||
CUTOFF = 5000
|
CUTOFF = 3600
|
||||||
PUNISH = 2 #PAR2
|
PUNISH = 2 #PAR2
|
||||||
MEMS_MAX = 61440 # 60G
|
MEMS_MAX = 61440 # 60G
|
||||||
|
|
||||||
@ -106,19 +106,19 @@ class solver_SAT_standard_gnomon(solver):
|
|||||||
self.datas[ins_name].res = "sat"
|
self.datas[ins_name].res = "sat"
|
||||||
|
|
||||||
if(not self.datas[ins_name].res == "unknown"):
|
if(not self.datas[ins_name].res == "unknown"):
|
||||||
self.datas[ins_name].time = float(re.findall(r"c process-time:.*seconds", fstr)[0].split()[-2])
|
timestr = re.findall(r"real.*m.*s", fstr)[-1]
|
||||||
|
minute = int(timestr.split('m')[0].split()[-1])
|
||||||
|
second = float(timestr.split('m')[-1].split('s')[0])
|
||||||
|
self.datas[ins_name].time = minute * 60 + second
|
||||||
if (self.datas[ins_name].time > CUTOFF*PUNISH):
|
if (self.datas[ins_name].time > CUTOFF*PUNISH):
|
||||||
self.datas[ins_name].res="unknown"
|
self.datas[ins_name].res="unknown"
|
||||||
|
# confstr = re.findall(r"c conflicts:.*per second", fstr)[-1]
|
||||||
|
# self.datas[ins_name].time = int(confstr.split()[-4])
|
||||||
|
|
||||||
return super().cal_soln(ins_name)
|
return super().cal_soln(ins_name)
|
||||||
def to_string(self, state):
|
def to_string(self, state):
|
||||||
return super().to_string(state)
|
return super().to_string(state)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SOLVER_LEN = 20
|
SOLVER_LEN = 20
|
||||||
SAMPLE_LEN = 20
|
SAMPLE_LEN = 20
|
||||||
NUMBER_LEN = 8
|
NUMBER_LEN = 8
|
||||||
@ -143,6 +143,8 @@ class calculater(object):
|
|||||||
title += " | PAR2_t".ljust(NUMBER_LEN+3)
|
title += " | PAR2_t".ljust(NUMBER_LEN+3)
|
||||||
title += " | best".ljust(NUMBER_LEN+3)
|
title += " | best".ljust(NUMBER_LEN+3)
|
||||||
title += " | mono".ljust(NUMBER_LEN+3)
|
title += " | mono".ljust(NUMBER_LEN+3)
|
||||||
|
title += " | s".ljust(NUMBER_LEN+3)
|
||||||
|
title += " | TIME".ljust(NUMBER_LEN+3)
|
||||||
title += " |"
|
title += " |"
|
||||||
print(title)
|
print(title)
|
||||||
|
|
||||||
@ -156,12 +158,22 @@ class calculater(object):
|
|||||||
split += " | " + '-'*(NUMBER_LEN)
|
split += " | " + '-'*(NUMBER_LEN)
|
||||||
split += " | " + '-'*(NUMBER_LEN)
|
split += " | " + '-'*(NUMBER_LEN)
|
||||||
split += " | " + '-'*(NUMBER_LEN)
|
split += " | " + '-'*(NUMBER_LEN)
|
||||||
|
split += " | " + '-'*(NUMBER_LEN)
|
||||||
|
split += " | " + '-'*(NUMBER_LEN)
|
||||||
split += " |"
|
split += " |"
|
||||||
self.split_line = split
|
self.split_line = split
|
||||||
print(split)
|
print(split)
|
||||||
|
|
||||||
|
#sota = self.solvers[0].solved_num * self.solvers[0].PAR_solved_time + CUTOFF * PUNISH * (self.sample_ins_ct - self.solvers[0].solved_num)
|
||||||
|
sota = self.solvers[0].PAR_all_time * self.sample_ins_ct
|
||||||
|
|
||||||
for slv in self.solvers:
|
for slv in self.solvers:
|
||||||
|
|
||||||
|
s = (sota - CUTOFF * PUNISH * (self.sample_ins_ct - slv.solved_num)) / (slv.solved_num * slv.PAR_solved_time)
|
||||||
|
|
||||||
|
time = slv.solved_num * slv.PAR_solved_time + CUTOFF * PUNISH * (self.sample_ins_ct - slv.solved_num) / 1.5
|
||||||
|
time = time / self.sample_ins_ct
|
||||||
|
|
||||||
line = "| " + (samp_name + "("+str(self.sample_ins_ct) + ")").ljust(SAMPLE_LEN)
|
line = "| " + (samp_name + "("+str(self.sample_ins_ct) + ")").ljust(SAMPLE_LEN)
|
||||||
line += " | " + slv.print_name.ljust(SOLVER_LEN)
|
line += " | " + slv.print_name.ljust(SOLVER_LEN)
|
||||||
line += " | " + str(slv.sat_num).ljust(NUMBER_LEN)
|
line += " | " + str(slv.sat_num).ljust(NUMBER_LEN)
|
||||||
@ -172,6 +184,8 @@ class calculater(object):
|
|||||||
line += " | " + str(round(slv.PAR_all_time,2)).ljust(NUMBER_LEN)
|
line += " | " + str(round(slv.PAR_all_time,2)).ljust(NUMBER_LEN)
|
||||||
line += " | " + str(slv.best_num).ljust(NUMBER_LEN)
|
line += " | " + str(slv.best_num).ljust(NUMBER_LEN)
|
||||||
line += " | " + str(slv.mono_num).ljust(NUMBER_LEN)
|
line += " | " + str(slv.mono_num).ljust(NUMBER_LEN)
|
||||||
|
line += " | " + str(round(s,2)).ljust(NUMBER_LEN)
|
||||||
|
line += " | " + str(round(time,2)).ljust(NUMBER_LEN)
|
||||||
line += " |"
|
line += " |"
|
||||||
print(line)
|
print(line)
|
||||||
|
|
||||||
@ -224,12 +238,12 @@ class calculater(object):
|
|||||||
if(not all_can_solve and not no_answer):
|
if(not all_can_solve and not no_answer):
|
||||||
have_diff_res = True
|
have_diff_res = True
|
||||||
|
|
||||||
|
# if(True):
|
||||||
if(True):
|
if(True):
|
||||||
# if(False):
|
|
||||||
# if(no_answer):
|
# if(no_answer):
|
||||||
# if(all_can_solve):
|
# if(all_can_solve):
|
||||||
# if(have_diff_res):
|
# if(have_diff_res):
|
||||||
# if(answer_this == "sat"):
|
# if(have_diff_res and answer_this == "sat"):
|
||||||
# if(self.solvers[-2].datas[ins_name].res != self.solvers[-1].datas[ins_name].res):
|
# if(self.solvers[-2].datas[ins_name].res != self.solvers[-1].datas[ins_name].res):
|
||||||
print_line_ct += 1
|
print_line_ct += 1
|
||||||
print(line)
|
print(line)
|
||||||
|
24
nohup.log
Normal file
24
nohup.log
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
exp-result 002a0330958a14deb23dcc84b5489e8a-traffic_f_unknown.cnf --share=1 --threads=32 --times=3600
|
||||||
|
exp-result 004b0f451f7d96f6a572e9e76360f51a-spg_420_280.cnf --share=1 --threads=32 --times=3600
|
||||||
|
exp-result 00a62eb89afbf27e1addf8f5c437da9b-ortholatin-7.cnf --share=1 --threads=32 --times=3600
|
||||||
|
exp-result 00aefd1fc30c425075166ca051e57218-barman-pfile10-038.sas.ex.15.cnf --share=1 --threads=32 --times=3600
|
||||||
|
exp-result 0151bedac526ee195bc52e4134cd80e7-ssAES_4-4-8_round_8-10_faultAt_8_fault_injections_2_seed_1579630418.cnf --share=1 --threads=32 --times=3600
|
||||||
|
exp-result 01813075a2ddb68ae1fc655ca003437e-sha256__zeroOut_12__freeIn_16__seed_1.cnf --share=1 --threads=32 --times=3600
|
||||||
|
exp-result 01d142c43f3ce9a8c5ef7a1ecdbb6cba-urquhart3_25bis.shuffled.cnf --share=1 --threads=32 --times=3600
|
||||||
|
exp-result 0205e0724a8a912dde9ad7dfba2aee0b-003-23-80.cnf --share=1 --threads=32 --times=3600
|
||||||
|
exp-result 02223564bd2f5c20768e63cf28c785e3-mp1-squ_ali_s10x10_c39_abio_SAT.cnf --share=1 --threads=32 --times=3600
|
||||||
|
exp-result 0240f5bddc39ad2f0a786c811fc434a8-SC21_Timetable_C_542_E_71_Cl_36_S_35.cnf --share=1 --threads=32 --times=3600
|
||||||
|
exp-result 024af9416f8c1dad1b4f974757e38d51-8-5-6.cnf --share=1 --threads=32 --times=3600
|
||||||
|
exp-result 02627689047d06fbb642eef14768d751-ps_200_300_70.cnf --share=1 --threads=32 --times=3600
|
||||||
|
exp-result 0294158664d9ada36bd23fbb652cb823-smtlib-qfbv-aigs-countbits128-tseitin.cnf --share=1 --threads=32 --times=3600
|
||||||
|
exp-result 02c6fe8483e4f4474b7ac9731772535d-ncc_none_7047_6_3_3_0_0_420.cnf --share=1 --threads=32 --times=3600
|
||||||
|
exp-result 02f2343e32f9070f149708d77556b4aa-Kakuro-easy-117-ext.xml.hg_5.cnf --share=1 --threads=32 --times=3600
|
||||||
|
exp-result 0398e6b20de133ba8b49c74b67dad7b7-6s133-sc2014.cnf --share=1 --threads=32 --times=3600
|
||||||
|
exp-result 03ba29d5cb38d345357a74a7b5ccd759-20-100-lambda100-49_sat.cnf --share=1 --threads=32 --times=3600
|
||||||
|
exp-result 03bb7baaa45980753a0e7050ae44755d-atco_enc3_opt1_03_53.cnf --share=1 --threads=32 --times=3600
|
||||||
|
exp-result 03c44a93577c98119dc498053888937a-ctl_4291_567_1_unsat_pre.cnf --share=1 --threads=32 --times=3600
|
||||||
|
exp-result 03fb9af7b390fe9e0739150ca3410cf0-4g_5color_166_100_02.cnf --share=1 --threads=32 --times=3600
|
||||||
|
exp-result 04157f716c1e9606c6a530657bf8f957-Kakuro-easy-125-ext.xml.hg_4.cnf --share=1 --threads=32 --times=3600
|
||||||
|
exp-result 0447371bb8a97e8fe5d3cee6de1db766-UTI-20-10p0-sc2009.cnf --share=1 --threads=32 --times=3600
|
||||||
|
exp-result 047c92e7c0a36a23d8107f4313517719-rubikcube701-sc2017.cnf --share=1 --threads=32 --times=3600
|
||||||
|
exp-result 047fbe00ecc60835f1ee9d458bbd7ee8-SAT_H_instances_childsnack_p06.hddl_2.cnf --share=1 --threads=32 --times=3600
|
5661207
output.txt
Normal file
5661207
output.txt
Normal file
File diff suppressed because it is too large
Load Diff
2
run.sh
2
run.sh
@ -4,4 +4,6 @@
|
|||||||
|
|
||||||
#valgrind
|
#valgrind
|
||||||
|
|
||||||
|
#make -j 16 && mpirun -np 9 --allow-run-as-root ./light -i /pub/data/chenzh/data/sat2022/0205e0724a8a912dde9ad7dfba2aee0b-003-23-80.cnf --share=1 --threads=32 --times=3600
|
||||||
|
|
||||||
make -j 16 && mpirun -np 9 --allow-run-as-root ./light -i /pub/data/chenzh/data/sat2022/0205e0724a8a912dde9ad7dfba2aee0b-003-23-80.cnf --share=1 --threads=32 --times=3600
|
make -j 16 && mpirun -np 9 --allow-run-as-root ./light -i /pub/data/chenzh/data/sat2022/0205e0724a8a912dde9ad7dfba2aee0b-003-23-80.cnf --share=1 --threads=32 --times=3600
|
@ -7,55 +7,42 @@ exec 6<>"$tmp_fifofile" # 定义文件描述符6指向这个fifo管道文件
|
|||||||
rm $tmp_fifofile
|
rm $tmp_fifofile
|
||||||
for i in $(seq 1 $SEND_THREAD_NUM)
|
for i in $(seq 1 $SEND_THREAD_NUM)
|
||||||
do
|
do
|
||||||
echo # for循环 往 fifo管道文件中写入 $SEND_THREAD_NUM 个空行
|
echo # for循环 往 fifo管道文件中写入 $SEND_THREAD_NUM 个空行
|
||||||
done >&6
|
done >&6
|
||||||
|
|
||||||
CUTOFF_TIME=3600
|
|
||||||
|
|
||||||
instance1="/pub/data/chenzh/data/sat2022"
|
|
||||||
|
|
||||||
res_sat1="./exp-result"
|
|
||||||
|
|
||||||
res_no="./unused"
|
|
||||||
#####################################################
|
|
||||||
|
|
||||||
ulimit -t 3600
|
ulimit -t 3600
|
||||||
|
|
||||||
all_datas=($instance1)
|
instance="/pub/data/chenzh/data/sat2022"
|
||||||
res_dir=($res_sat1)
|
|
||||||
|
run_solver(){
|
||||||
|
solver=$1
|
||||||
|
res_solver_ins=$2
|
||||||
|
solver_args=$3
|
||||||
|
if [ ! -d "$res_solver_ins" ]; then
|
||||||
|
mkdir -p $res_solver_ins
|
||||||
|
fi
|
||||||
|
for dir_file in `cat $instance/all.txt`
|
||||||
|
do
|
||||||
|
file=$dir_file
|
||||||
|
echo "$res_solver_ins $file $solver_args"
|
||||||
|
touch $res_solver_ins/$file
|
||||||
|
read -u 6
|
||||||
|
{
|
||||||
|
time $solver $instance/$file $solver_args
|
||||||
|
echo >&6
|
||||||
|
} >$res_solver_ins/$file 2>>$res_solver_ins/$file &
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
all_datas=($instance)
|
||||||
|
|
||||||
for((i=0;i<${#all_datas[*]};i++))
|
for((i=0;i<${#all_datas[*]};i++))
|
||||||
do
|
do
|
||||||
instance=${all_datas[$i]}
|
instance=${all_datas[$i]}
|
||||||
res_solver_ins=${res_dir[$i]}
|
|
||||||
if [ ! -d "$res_solver_ins" ]; then
|
|
||||||
mkdir -p $res_solver_ins
|
|
||||||
fi
|
|
||||||
for dir_file in `cat $instance/all.txt`
|
|
||||||
do
|
|
||||||
file=$dir_file
|
|
||||||
echo $file
|
|
||||||
touch $res_solver_ins/$file
|
|
||||||
read -u 6
|
|
||||||
{
|
|
||||||
cd /home/qianyh/projects/Light
|
|
||||||
mpirun -np 9 --allow-run-as-root ./light -i $instance/$file --share=1 --threads=32 --times=$CUTOFF_TIME
|
|
||||||
echo >&6
|
|
||||||
} >$res_solver_ins/$file &
|
|
||||||
done
|
|
||||||
done
|
|
||||||
|
|
||||||
# res_solver_ins=$res_no
|
run_solver \
|
||||||
# if [ ! -d "$res_solver_ins" ]; then
|
'mpirun -np 9 --allow-run-as-root ./light -i ' \
|
||||||
# mkdir -p $res_solver_ins
|
'exp-result'\
|
||||||
# fi
|
'--share=1 --threads=32 --times=3600'
|
||||||
# for((i=0;i<96;i++))
|
|
||||||
# do
|
|
||||||
# read -u 6
|
|
||||||
# {
|
|
||||||
# cd /home/chenzh/solvers/sota/kissat-MAB/build
|
|
||||||
# ./kissat /home/chenzh/data/hard_cnfs/49.cnf
|
|
||||||
# echo >&6
|
|
||||||
# } >$res_solver_ins/$i &
|
|
||||||
# done
|
|
||||||
|
|
||||||
exit 0
|
done
|
@ -32,6 +32,7 @@ void leader_main(light* S, int num_procs, int rank) {
|
|||||||
// preprocess 证明了UNSAT 则不需要启动云计算
|
// preprocess 证明了UNSAT 则不需要启动云计算
|
||||||
if(!start) {
|
if(!start) {
|
||||||
printf("c [leader] UNSAT!!!!!! by preprocess\n");
|
printf("c [leader] UNSAT!!!!!! by preprocess\n");
|
||||||
|
printf("s UNSATISFIABLE\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
#include <mpi.h>
|
#include <mpi.h>
|
||||||
typedef long long ll;
|
typedef long long ll;
|
||||||
|
|
||||||
|
using std::shared_ptr;
|
||||||
|
|
||||||
class basesolver;
|
class basesolver;
|
||||||
class sharer;
|
class sharer;
|
||||||
|
|
||||||
|
@ -11,7 +11,10 @@
|
|||||||
#include "distributed/leader.hpp"
|
#include "distributed/leader.hpp"
|
||||||
#include "distributed/worker.hpp"
|
#include "distributed/worker.hpp"
|
||||||
|
|
||||||
|
#include "workers/clause.hpp"
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
int num_procs, rank;
|
int num_procs, rank;
|
||||||
MPI_Init(&argc, &argv);
|
MPI_Init(&argc, &argv);
|
||||||
MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
|
MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -31,6 +31,7 @@ class vec {
|
|||||||
void setsize (int v) { sz = v;}
|
void setsize (int v) { sz = v;}
|
||||||
void push (void) { if (sz == cap) capacity(sz + 1); new (&data[sz]) T(); sz++; }
|
void push (void) { if (sz == cap) capacity(sz + 1); new (&data[sz]) T(); sz++; }
|
||||||
void push (const T& elem) { if (sz == cap) capInc(sz + 1); data[sz++] = elem;}
|
void push (const T& elem) { if (sz == cap) capInc(sz + 1); data[sz++] = elem;}
|
||||||
|
void push_with_init (const T& elem) { if (sz == cap) capInc(sz + 1); new (&data[sz]) T(); data[sz++] = elem;}
|
||||||
void push_ (const T& elem) { assert(sz < cap); data[sz++] = elem; }
|
void push_ (const T& elem) { assert(sz < cap); data[sz++] = elem; }
|
||||||
void pop (void) { assert(sz > 0), sz--, data[sz].~T(); }
|
void pop (void) { assert(sz > 0), sz--, data[sz].~T(); }
|
||||||
void copyTo (vec<T>& copy) { copy.clear(); copy.growTo(sz); for (int i = 0; i < sz; i++) copy[i] = data[i]; }
|
void copyTo (vec<T>& copy) { copy.clear(); copy.growTo(sz); for (int i = 0; i < sz; i++) copy[i] = data[i]; }
|
||||||
|
@ -38,7 +38,7 @@ int basekissat::val(int l) {
|
|||||||
|
|
||||||
void basekissat::exp_clause(void* cl, int lbd) {
|
void basekissat::exp_clause(void* cl, int lbd) {
|
||||||
cvec *c = (cvec *) cl;
|
cvec *c = (cvec *) cl;
|
||||||
clause_store* cls = new clause_store(c->sz);
|
shared_ptr<clause_store> cls = std::make_shared<clause_store>(c->sz);
|
||||||
for (int i = 0; i < c->sz; i++) {
|
for (int i = 0; i < c->sz; i++) {
|
||||||
int v = cvec_data(c, i);
|
int v = cvec_data(c, i);
|
||||||
int eidx = PEEK_STACK(solver->exportk, (v >> 1));
|
int eidx = PEEK_STACK(solver->exportk, (v >> 1));
|
||||||
@ -65,7 +65,7 @@ void call_back_out(void *solver, int lbd, cvec *c) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool basekissat::imp_clause(clause_store *cls, void *cl) {
|
bool basekissat::imp_clause(shared_ptr<clause_store>cls, void *cl) {
|
||||||
cvec *c = (cvec *) cl;
|
cvec *c = (cvec *) cl;
|
||||||
for (int i = 0; i < cls->size; i++) {
|
for (int i = 0; i < cls->size; i++) {
|
||||||
// S->outimport << cls->data[i] << std::endl;
|
// S->outimport << cls->data[i] << std::endl;
|
||||||
@ -84,7 +84,7 @@ bool basekissat::imp_clause(clause_store *cls, void *cl) {
|
|||||||
|
|
||||||
int call_back_in(void *solver, int *lbd, cvec *c) {
|
int call_back_in(void *solver, int *lbd, cvec *c) {
|
||||||
basekissat* S = (basekissat *) solver;
|
basekissat* S = (basekissat *) solver;
|
||||||
clause_store* cls = NULL;
|
shared_ptr<clause_store> cls = NULL;
|
||||||
if (S->import_clause.pop(cls) == false) return -1;
|
if (S->import_clause.pop(cls) == false) return -1;
|
||||||
*lbd = cls->lbd;
|
*lbd = cls->lbd;
|
||||||
bool res = S->imp_clause(cls, c);
|
bool res = S->imp_clause(cls, c);
|
||||||
|
@ -17,7 +17,7 @@ public:
|
|||||||
void parse_from_PAR(preprocess *pre);
|
void parse_from_PAR(preprocess *pre);
|
||||||
void parse_from_MEM(char* instance);
|
void parse_from_MEM(char* instance);
|
||||||
void exp_clause(void *cl, int lbd);
|
void exp_clause(void *cl, int lbd);
|
||||||
bool imp_clause(clause_store *cls, void *cl);
|
bool imp_clause(shared_ptr<clause_store>cls, void *cl);
|
||||||
|
|
||||||
basekissat(int id, light *light);
|
basekissat(int id, light *light);
|
||||||
~basekissat();
|
~basekissat();
|
||||||
|
Binary file not shown.
@ -42,15 +42,21 @@ double basesolver::get_waiting_time() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void basesolver::export_clauses_to(vec<clause_store *> &clauses) {
|
void basesolver::export_clauses_to(std::vector<shared_ptr<clause_store>> &clauses) {
|
||||||
clause_store *cls;
|
shared_ptr<clause_store> cls;
|
||||||
|
|
||||||
while (export_clause.pop(cls)) {
|
while (export_clause.pop(cls)) {
|
||||||
clauses.push(cls);
|
|
||||||
|
// printf("size: %d [", cls->size);
|
||||||
|
// for(int i=0; i<cls->size; i++) {
|
||||||
|
// printf("%d ", cls->data[i]);
|
||||||
|
// }
|
||||||
|
// printf("] \n");
|
||||||
|
clauses.push_back(cls);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void basesolver::import_clauses_from(vec<clause_store *> &clauses) {
|
void basesolver::import_clauses_from(std::vector<shared_ptr<clause_store>> &clauses) {
|
||||||
for (int i = 0; i < clauses.size(); i++) {
|
for (int i = 0; i < clauses.size(); i++) {
|
||||||
import_clause.push(clauses[i]);
|
import_clause.push(clauses[i]);
|
||||||
}
|
}
|
||||||
@ -65,7 +71,7 @@ void basesolver::select_clauses() {
|
|||||||
int sz = cls[i]->size;
|
int sz = cls[i]->size;
|
||||||
while (sz > bucket.size()) bucket.push();
|
while (sz > bucket.size()) bucket.push();
|
||||||
if (sz * (bucket[sz - 1].size() + 1) <= share->share_lits)
|
if (sz * (bucket[sz - 1].size() + 1) <= share->share_lits)
|
||||||
bucket[sz - 1].push(cls[i]);
|
bucket[sz - 1].push_back(cls[i]);
|
||||||
}
|
}
|
||||||
period_clauses *pcls = new period_clauses(period);
|
period_clauses *pcls = new period_clauses(period);
|
||||||
int space = share->share_lits;
|
int space = share->share_lits;
|
||||||
@ -81,8 +87,8 @@ void basesolver::select_clauses() {
|
|||||||
else {
|
else {
|
||||||
space -= clause_num * (i + 1);
|
space -= clause_num * (i + 1);
|
||||||
for (int j = 0; j < clause_num; j++) {
|
for (int j = 0; j < clause_num; j++) {
|
||||||
pcls->push(bucket[i].last());
|
pcls->push(bucket[i].back());
|
||||||
bucket[i].pop();
|
bucket[i].pop_back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,10 +24,10 @@ public:
|
|||||||
virtual void parse_from_PAR(preprocess* pre) = 0;
|
virtual void parse_from_PAR(preprocess* pre) = 0;
|
||||||
virtual void parse_from_MEM(char* instance) = 0;
|
virtual void parse_from_MEM(char* instance) = 0;
|
||||||
virtual void exp_clause(void *cl, int lbd) = 0;
|
virtual void exp_clause(void *cl, int lbd) = 0;
|
||||||
virtual bool imp_clause(clause_store *cls, void *cl) = 0;
|
virtual bool imp_clause(shared_ptr<clause_store>cls, void *cl) = 0;
|
||||||
|
|
||||||
void export_clauses_to(vec<clause_store *> &clauses);
|
void export_clauses_to(std::vector<shared_ptr<clause_store>> &clauses);
|
||||||
void import_clauses_from(vec<clause_store *> &clauses);
|
void import_clauses_from(std::vector<shared_ptr<clause_store>> &clauses);
|
||||||
|
|
||||||
void get_model(vec<int> &model);
|
void get_model(vec<int> &model);
|
||||||
void select_clauses();
|
void select_clauses();
|
||||||
@ -51,12 +51,12 @@ public:
|
|||||||
mutable boost::mutex mtx;
|
mutable boost::mutex mtx;
|
||||||
boost::condition_variable cond;
|
boost::condition_variable cond;
|
||||||
period_queue pq;
|
period_queue pq;
|
||||||
vec<clause_store *> cls;
|
std::vector<shared_ptr<clause_store>> cls;
|
||||||
vec<vec<clause_store *>> bucket;
|
vec<std::vector<shared_ptr<clause_store>>> bucket;
|
||||||
vec<int> unfree;
|
vec<int> unfree;
|
||||||
|
|
||||||
boost::lockfree::spsc_queue<clause_store*, boost::lockfree::capacity<10240000>> import_clause;
|
boost::lockfree::spsc_queue<shared_ptr<clause_store>, boost::lockfree::capacity<10240000>> import_clause;
|
||||||
boost::lockfree::spsc_queue<clause_store*, boost::lockfree::capacity<10240000>> export_clause;
|
boost::lockfree::spsc_queue<shared_ptr<clause_store>, boost::lockfree::capacity<10240000>> export_clause;
|
||||||
|
|
||||||
basesolver(int sid, light* light) : id(sid), controller(light) {
|
basesolver(int sid, light* light) : id(sid), controller(light) {
|
||||||
good_clause_lbd = 2;
|
good_clause_lbd = 2;
|
||||||
|
Binary file not shown.
@ -2,12 +2,17 @@
|
|||||||
#define _clause_hpp_INCLUDED
|
#define _clause_hpp_INCLUDED
|
||||||
#include <boost/thread.hpp>
|
#include <boost/thread.hpp>
|
||||||
#include <boost/thread/thread.hpp>
|
#include <boost/thread/thread.hpp>
|
||||||
|
#include "../utils/vec.hpp"
|
||||||
|
|
||||||
|
using std::shared_ptr;
|
||||||
|
|
||||||
struct clause_store {
|
struct clause_store {
|
||||||
int size, lbd;
|
int size, lbd;
|
||||||
int *data;
|
int *data;
|
||||||
std::atomic<int> refs;
|
std::atomic<int> refs;
|
||||||
clause_store(int sz) {
|
clause_store(int sz) {
|
||||||
|
|
||||||
|
//printf("c new clause_store\n");
|
||||||
size = sz;
|
size = sz;
|
||||||
data = (int*) malloc(sizeof(int) * sz);
|
data = (int*) malloc(sizeof(int) * sz);
|
||||||
lbd = 0;
|
lbd = 0;
|
||||||
@ -17,19 +22,16 @@ struct clause_store {
|
|||||||
refs += inc;
|
refs += inc;
|
||||||
}
|
}
|
||||||
bool free_clause() {
|
bool free_clause() {
|
||||||
int ref = refs.fetch_sub(1);
|
// int ref = refs.fetch_sub(1);
|
||||||
if (ref <= 1) {
|
// if (ref <= 1) {
|
||||||
// printf("c free clause: ");
|
// free(data);
|
||||||
// for (int i = 0; i < size; i++)
|
// return true;
|
||||||
// printf("%d ", data[i]);
|
// }
|
||||||
// puts("");
|
|
||||||
free(data);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
~clause_store() {
|
~clause_store() {
|
||||||
puts("free");
|
//printf("c free clause_store\n");
|
||||||
|
free(data);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -37,7 +39,7 @@ struct clause_store {
|
|||||||
struct period_clauses {
|
struct period_clauses {
|
||||||
int period;
|
int period;
|
||||||
std::atomic<int> refs;
|
std::atomic<int> refs;
|
||||||
vec<clause_store *> cls;
|
std::vector<shared_ptr<clause_store>> cls;
|
||||||
period_clauses(int p = 0) {
|
period_clauses(int p = 0) {
|
||||||
refs = 0;
|
refs = 0;
|
||||||
period = p;
|
period = p;
|
||||||
@ -59,8 +61,8 @@ struct period_clauses {
|
|||||||
for (int i = 0; i < cls.size(); i++)
|
for (int i = 0; i < cls.size(); i++)
|
||||||
cls[i]->free_clause();
|
cls[i]->free_clause();
|
||||||
}
|
}
|
||||||
void push(clause_store * c) {
|
void push(shared_ptr<clause_store> c) {
|
||||||
cls.push(c);
|
cls.push_back(c);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include "../distributed/comm_tag.h"
|
#include "../distributed/comm_tag.h"
|
||||||
#include <boost/thread/thread.hpp>
|
#include <boost/thread/thread.hpp>
|
||||||
|
|
||||||
|
|
||||||
int nums = 0;
|
int nums = 0;
|
||||||
double share_time = 0;
|
double share_time = 0;
|
||||||
int num_procs, rank;
|
int num_procs, rank;
|
||||||
@ -16,31 +15,17 @@ std::vector<std::pair<MPI_Request*, int*>> send_data_struct;
|
|||||||
MPI_Request receive_request;
|
MPI_Request receive_request;
|
||||||
int buf[BUF_SIZE];
|
int buf[BUF_SIZE];
|
||||||
|
|
||||||
|
void share_clauses_to_next_node(int from, const std::vector<shared_ptr<clause_store>> &cls) {
|
||||||
|
|
||||||
void share_clauses_to_next_node(const vec<clause_store *> &cls) {
|
int target = rank % (num_procs - 1) + 1;
|
||||||
|
|
||||||
// 清理 send_data_struct,把发送完毕的发送数据结构清理掉
|
// 环形传递,数据来源如果是目的地,说明数据已轮转一圈,停止发送。
|
||||||
for(int i=0; i<send_data_struct.size(); i++) {
|
if(from == target) return;
|
||||||
auto& request = send_data_struct[i].first;
|
|
||||||
auto& send_buf = send_data_struct[i].second;
|
|
||||||
|
|
||||||
// 已完成发送,释放内存空间
|
|
||||||
int flag;
|
|
||||||
if(MPI_Test(request, &flag, MPI_STATUS_IGNORE) == MPI_SUCCESS && flag == 1) {
|
|
||||||
delete request;
|
|
||||||
delete []send_buf;
|
|
||||||
// 与数组最后一个交换,然后 pop_back;
|
|
||||||
std::swap(send_data_struct[i], send_data_struct[send_data_struct.size()-1]);
|
|
||||||
send_data_struct.pop_back();
|
|
||||||
|
|
||||||
//printf("c [worker] free send request, now: %d\n", send_data_struct.size());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 定义发送数据
|
// 定义发送数据
|
||||||
MPI_Request *send_request = new MPI_Request();
|
MPI_Request *send_request = new MPI_Request();
|
||||||
int *send_buf;
|
int *send_buf;
|
||||||
int send_length = 0;
|
int send_length = 1;
|
||||||
|
|
||||||
// 初始化发送数据
|
// 初始化发送数据
|
||||||
for(int i=0; i<cls.size(); i++) {
|
for(int i=0; i<cls.size(); i++) {
|
||||||
@ -48,8 +33,11 @@ void share_clauses_to_next_node(const vec<clause_store *> &cls) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
send_buf = new int[send_length];
|
send_buf = new int[send_length];
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
|
send_buf[index++] = from;
|
||||||
|
|
||||||
for(int i=0; i<cls.size(); i++) {
|
for(int i=0; i<cls.size(); i++) {
|
||||||
auto& c = cls[i];
|
auto& c = cls[i];
|
||||||
send_buf[index++] = c->size;
|
send_buf[index++] = c->size;
|
||||||
@ -63,26 +51,34 @@ void share_clauses_to_next_node(const vec<clause_store *> &cls) {
|
|||||||
|
|
||||||
// 调用 MPI 发送共享子句
|
// 调用 MPI 发送共享子句
|
||||||
|
|
||||||
int num_procs, rank;
|
|
||||||
MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
|
|
||||||
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
|
||||||
|
|
||||||
int target = rank % (num_procs - 1) + 1;
|
|
||||||
|
|
||||||
MPI_Isend(send_buf, send_length, MPI_INT, target, SHARE_CLAUSES_TAG, MPI_COMM_WORLD, send_request);
|
MPI_Isend(send_buf, send_length, MPI_INT, target, SHARE_CLAUSES_TAG, MPI_COMM_WORLD, send_request);
|
||||||
|
|
||||||
send_data_struct.push_back(std::make_pair(send_request, send_buf));
|
send_data_struct.push_back(std::make_pair(send_request, send_buf));
|
||||||
|
|
||||||
//printf("c [worker] send clauses: %d\n", send_length);
|
// printf("c [worker] send clauses: %d\n", send_length);
|
||||||
|
|
||||||
|
// 清理 send_data_struct,把发送完毕的发送数据结构清理掉
|
||||||
|
for(int i=0; i<send_data_struct.size(); i++) {
|
||||||
|
// 已完成发送,释放内存空间
|
||||||
|
int flag;
|
||||||
|
if(MPI_Test(send_data_struct[i].first, &flag, MPI_STATUS_IGNORE) == MPI_SUCCESS && flag == 1) {
|
||||||
|
delete send_data_struct[i].first;
|
||||||
|
delete []send_data_struct[i].second;
|
||||||
|
// 与数组最后一个交换,然后 pop_back;
|
||||||
|
std::swap(send_data_struct[i], send_data_struct[send_data_struct.size()-1]);
|
||||||
|
send_data_struct.pop_back();
|
||||||
|
// printf("c [worker] free send request, now: %d\n", send_data_struct.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool receive_clauses_from_last_node(vec<clause_store*> &clauses) {
|
bool receive_clauses_from_last_node(std::vector<shared_ptr<clause_store>> &clauses) {
|
||||||
clauses.clear();
|
clauses.clear();
|
||||||
|
|
||||||
int flag;
|
int flag;
|
||||||
MPI_Status status;
|
MPI_Status status;
|
||||||
|
|
||||||
bool received = false;
|
int from = -1;
|
||||||
|
|
||||||
// 已接收完数据
|
// 已接收完数据
|
||||||
while(MPI_Test(&receive_request, &flag, &status) == MPI_SUCCESS && flag == 1) {
|
while(MPI_Test(&receive_request, &flag, &status) == MPI_SUCCESS && flag == 1) {
|
||||||
@ -90,33 +86,28 @@ bool receive_clauses_from_last_node(vec<clause_store*> &clauses) {
|
|||||||
int count;
|
int count;
|
||||||
MPI_Get_count(&status, MPI_INT, &count);
|
MPI_Get_count(&status, MPI_INT, &count);
|
||||||
|
|
||||||
|
from = buf[index++];
|
||||||
while(index < count) {
|
while(index < count) {
|
||||||
clause_store* cl = new clause_store(buf[index++]);
|
shared_ptr<clause_store> cl = std::make_shared<clause_store>(buf[index++]);
|
||||||
cl->lbd = buf[index++];
|
cl->lbd = buf[index++];
|
||||||
for(int i=0; i<cl->size; i++) {
|
for(int i=0; i<cl->size; i++) {
|
||||||
cl->data[i] = buf[index++];
|
cl->data[i] = buf[index++];
|
||||||
}
|
}
|
||||||
clauses.push(cl);
|
clauses.push_back(cl);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(index == count);
|
assert(index == count);
|
||||||
|
|
||||||
// 进行下一步接收数据
|
// 进行下一步接收数据
|
||||||
|
|
||||||
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;
|
int from = (rank - 2 + num_procs - 1) % (num_procs - 1) + 1;
|
||||||
|
|
||||||
//LOGGER->info("receive clauses: %v", count);
|
//LOGGER->info("receive clauses: %v", count);
|
||||||
|
|
||||||
MPI_Irecv(buf, BUF_SIZE, MPI_INT, from, SHARE_CLAUSES_TAG, MPI_COMM_WORLD, &receive_request);
|
MPI_Irecv(buf, BUF_SIZE, MPI_INT, from, SHARE_CLAUSES_TAG, MPI_COMM_WORLD, &receive_request);
|
||||||
|
|
||||||
received = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return received;
|
return from;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sharer::clause_sharing_init() {
|
void sharer::clause_sharing_init() {
|
||||||
@ -137,7 +128,9 @@ void sharer::do_clause_sharing() {
|
|||||||
++nums;
|
++nums;
|
||||||
auto clk_now = std::chrono::high_resolution_clock::now();
|
auto clk_now = std::chrono::high_resolution_clock::now();
|
||||||
int solve_time = std::chrono::duration_cast<std::chrono::milliseconds>(clk_now - clk_st).count();
|
int solve_time = std::chrono::duration_cast<std::chrono::milliseconds>(clk_now - clk_st).count();
|
||||||
//printf("c [worker] round %d, time: %d.%d\n", nums, solve_time / 1000, solve_time % 1000);
|
|
||||||
|
printf("c [worker] round %d, time: %d.%d\n", nums, solve_time / 1000, solve_time % 1000);
|
||||||
|
|
||||||
// printf("start sharing %d\n", sq->share_intv);
|
// printf("start sharing %d\n", sq->share_intv);
|
||||||
for (int i = 0; i < producers.size(); i++) {
|
for (int i = 0; i < producers.size(); i++) {
|
||||||
cls.clear();
|
cls.clear();
|
||||||
@ -146,14 +139,15 @@ void sharer::do_clause_sharing() {
|
|||||||
//printf("c size %d\n", sq->cls.size());
|
//printf("c size %d\n", sq->cls.size());
|
||||||
int number = cls.size();
|
int number = cls.size();
|
||||||
|
|
||||||
//printf("c [worker] thread-%d: get %d exported clauses\n", i, number);
|
// printf("c [worker] thread-%d: get %d exported clauses\n", i, number);
|
||||||
|
|
||||||
//分享当前节点产生的子句
|
//分享当前节点产生的子句
|
||||||
if(cls.size() > 0) share_clauses_to_next_node(cls);
|
if(cls.size() > 0) share_clauses_to_next_node(rank, cls);
|
||||||
|
|
||||||
// 导入外部网络传输的子句
|
// 导入外部网络传输的子句
|
||||||
vec<clause_store*> clauses;
|
std::vector<shared_ptr<clause_store>> clauses;
|
||||||
if(receive_clauses_from_last_node(clauses)) {
|
int from = receive_clauses_from_last_node(clauses);
|
||||||
|
if(from != -1) {
|
||||||
for (int j = 0; j < consumers.size(); j++) {
|
for (int j = 0; j < consumers.size(); j++) {
|
||||||
for (int k = 0; k < clauses.size(); k++)
|
for (int k = 0; k < clauses.size(); k++)
|
||||||
clauses[k]->increase_refs(1);
|
clauses[k]->increase_refs(1);
|
||||||
@ -161,7 +155,7 @@ void sharer::do_clause_sharing() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 传递外部网络传输的子句给下个节点
|
// 传递外部网络传输的子句给下个节点
|
||||||
share_clauses_to_next_node(clauses);
|
share_clauses_to_next_node(from, clauses);
|
||||||
|
|
||||||
for (int k = 0; k < clauses.size(); k++) {
|
for (int k = 0; k < clauses.size(); k++) {
|
||||||
clauses[k]->free_clause();
|
clauses[k]->free_clause();
|
||||||
@ -228,7 +222,7 @@ int sharer::sort_clauses(int x) {
|
|||||||
int sz = cls[i]->size;
|
int sz = cls[i]->size;
|
||||||
while (sz > bucket[x].size()) bucket[x].push();
|
while (sz > bucket[x].size()) bucket[x].push();
|
||||||
if (sz * (bucket[x][sz - 1].size() + 1) <= share_lits)
|
if (sz * (bucket[x][sz - 1].size() + 1) <= share_lits)
|
||||||
bucket[x][sz - 1].push(cls[i]);
|
bucket[x][sz - 1].push_back(cls[i]);
|
||||||
// else
|
// else
|
||||||
// cls[i]->free_clause();
|
// cls[i]->free_clause();
|
||||||
}
|
}
|
||||||
@ -241,14 +235,14 @@ int sharer::sort_clauses(int x) {
|
|||||||
if (clause_num >= bucket[x][i].size()) {
|
if (clause_num >= bucket[x][i].size()) {
|
||||||
space -= bucket[x][i].size() * (i + 1);
|
space -= bucket[x][i].size() * (i + 1);
|
||||||
for (int j = 0; j < bucket[x][i].size(); j++)
|
for (int j = 0; j < bucket[x][i].size(); j++)
|
||||||
cls.push(bucket[x][i][j]);
|
cls.push_back(bucket[x][i][j]);
|
||||||
bucket[x][i].clear();
|
bucket[x][i].clear();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
space -= clause_num * (i + 1);
|
space -= clause_num * (i + 1);
|
||||||
for (int j = 0; j < clause_num; j++) {
|
for (int j = 0; j < clause_num; j++) {
|
||||||
cls.push(bucket[x][i].last());
|
cls.push_back(bucket[x][i].back());
|
||||||
bucket[x][i].pop();
|
bucket[x][i].pop_back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,10 +15,10 @@ public:
|
|||||||
boost::condition_variable cond;
|
boost::condition_variable cond;
|
||||||
int terminated;
|
int terminated;
|
||||||
int waitings;
|
int waitings;
|
||||||
vec<vec<clause_store *>> bucket[64]; //need to update
|
vec<std::vector<shared_ptr<clause_store>>> bucket[64]; //need to update
|
||||||
|
|
||||||
vec<basesolver *> producers, consumers;
|
vec<basesolver *> producers, consumers;
|
||||||
vec<clause_store *> cls;
|
std::vector<shared_ptr<clause_store>> cls;
|
||||||
sharer(int idx, int intv, int lits, int share_dps = 0) {
|
sharer(int idx, int intv, int lits, int share_dps = 0) {
|
||||||
share_intv = intv;
|
share_intv = intv;
|
||||||
share_lits = lits;
|
share_lits = lits;
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user