使用 share_ptr 解决了共享子句内存泄漏

This commit is contained in:
YuhangQ 2023-04-10 15:58:33 +08:00
parent f130694965
commit 918ae6817d
27 changed files with 5661386 additions and 135 deletions

View File

@ -88,6 +88,7 @@
"concepts": "cpp",
"numbers": "cpp",
"semaphore": "cpp",
"stop_token": "cpp"
"stop_token": "cpp",
"*.ipp": "cpp"
}
}

View File

@ -1,3 +1,10 @@
preprocess 占了特别大内存
/pub/data/chenzh/data/sat2022/04157f716c1e9606c6a530657bf8f957-Kakuro-easy-125-ext.xml.hg_4.cnf
==2320428==
==2320428== Process terminating with default action of signal 15 (SIGTERM)
==2320428== at 0x4DF912F: poll (poll.c:29)

32
cal.py
View File

@ -12,7 +12,7 @@ from time import monotonic, sleep
from tokenize import Number
# global limit
CUTOFF = 5000
CUTOFF = 3600
PUNISH = 2 #PAR2
MEMS_MAX = 61440 # 60G
@ -106,19 +106,19 @@ class solver_SAT_standard_gnomon(solver):
self.datas[ins_name].res = "sat"
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):
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)
def to_string(self, state):
return super().to_string(state)
SOLVER_LEN = 20
SAMPLE_LEN = 20
NUMBER_LEN = 8
@ -143,6 +143,8 @@ class calculater(object):
title += " | PAR2_t".ljust(NUMBER_LEN+3)
title += " | best".ljust(NUMBER_LEN+3)
title += " | mono".ljust(NUMBER_LEN+3)
title += " | s".ljust(NUMBER_LEN+3)
title += " | TIME".ljust(NUMBER_LEN+3)
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 += " |"
self.split_line = 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:
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 += " | " + slv.print_name.ljust(SOLVER_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(slv.best_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 += " |"
print(line)
@ -224,12 +238,12 @@ class calculater(object):
if(not all_can_solve and not no_answer):
have_diff_res = True
# if(True):
if(True):
# if(False):
# if(no_answer):
# if(all_can_solve):
# 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):
print_line_ct += 1
print(line)

24
nohup.log Normal file
View 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

File diff suppressed because it is too large Load Diff

2
run.sh
View File

@ -4,4 +4,6 @@
#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

View File

@ -10,52 +10,39 @@ do
echo # for循环 往 fifo管道文件中写入 $SEND_THREAD_NUM 个空行
done >&6
CUTOFF_TIME=3600
instance1="/pub/data/chenzh/data/sat2022"
res_sat1="./exp-result"
res_no="./unused"
#####################################################
ulimit -t 3600
all_datas=($instance1)
res_dir=($res_sat1)
for((i=0;i<${#all_datas[*]};i++))
do
instance=${all_datas[$i]}
res_solver_ins=${res_dir[$i]}
instance="/pub/data/chenzh/data/sat2022"
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 $file
echo "$res_solver_ins $file $solver_args"
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
time $solver $instance/$file $solver_args
echo >&6
} >$res_solver_ins/$file &
} >$res_solver_ins/$file 2>>$res_solver_ins/$file &
done
}
all_datas=($instance)
for((i=0;i<${#all_datas[*]};i++))
do
instance=${all_datas[$i]}
run_solver \
'mpirun -np 9 --allow-run-as-root ./light -i ' \
'exp-result'\
'--share=1 --threads=32 --times=3600'
done
# res_solver_ins=$res_no
# if [ ! -d "$res_solver_ins" ]; then
# mkdir -p $res_solver_ins
# fi
# 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

View File

@ -32,6 +32,7 @@ void leader_main(light* S, int num_procs, int rank) {
// preprocess 证明了UNSAT 则不需要启动云计算
if(!start) {
printf("c [leader] UNSAT!!!!!! by preprocess\n");
printf("s UNSATISFIABLE\n");
return;
}

View File

@ -13,6 +13,8 @@
#include <mpi.h>
typedef long long ll;
using std::shared_ptr;
class basesolver;
class sharer;

View File

@ -11,7 +11,10 @@
#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);

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -31,6 +31,7 @@ class vec {
void setsize (int v) { sz = v;}
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_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 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]; }

View File

@ -38,7 +38,7 @@ int basekissat::val(int l) {
void basekissat::exp_clause(void* cl, int lbd) {
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++) {
int v = cvec_data(c, i);
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;
for (int i = 0; i < cls->size; i++) {
// 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) {
basekissat* S = (basekissat *) solver;
clause_store* cls = NULL;
shared_ptr<clause_store> cls = NULL;
if (S->import_clause.pop(cls) == false) return -1;
*lbd = cls->lbd;
bool res = S->imp_clause(cls, c);

View File

@ -17,7 +17,7 @@ public:
void parse_from_PAR(preprocess *pre);
void parse_from_MEM(char* instance);
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();

Binary file not shown.

View File

@ -42,15 +42,21 @@ double basesolver::get_waiting_time() {
}
void basesolver::export_clauses_to(vec<clause_store *> &clauses) {
clause_store *cls;
void basesolver::export_clauses_to(std::vector<shared_ptr<clause_store>> &clauses) {
shared_ptr<clause_store> 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++) {
import_clause.push(clauses[i]);
}
@ -65,7 +71,7 @@ void basesolver::select_clauses() {
int sz = cls[i]->size;
while (sz > bucket.size()) bucket.push();
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);
int space = share->share_lits;
@ -81,8 +87,8 @@ void basesolver::select_clauses() {
else {
space -= clause_num * (i + 1);
for (int j = 0; j < clause_num; j++) {
pcls->push(bucket[i].last());
bucket[i].pop();
pcls->push(bucket[i].back());
bucket[i].pop_back();
}
}
}

View File

@ -24,10 +24,10 @@ public:
virtual void parse_from_PAR(preprocess* pre) = 0;
virtual void parse_from_MEM(char* instance) = 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 import_clauses_from(vec<clause_store *> &clauses);
void export_clauses_to(std::vector<shared_ptr<clause_store>> &clauses);
void import_clauses_from(std::vector<shared_ptr<clause_store>> &clauses);
void get_model(vec<int> &model);
void select_clauses();
@ -51,12 +51,12 @@ public:
mutable boost::mutex mtx;
boost::condition_variable cond;
period_queue pq;
vec<clause_store *> cls;
vec<vec<clause_store *>> bucket;
std::vector<shared_ptr<clause_store>> cls;
vec<std::vector<shared_ptr<clause_store>>> bucket;
vec<int> unfree;
boost::lockfree::spsc_queue<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>> import_clause;
boost::lockfree::spsc_queue<shared_ptr<clause_store>, boost::lockfree::capacity<10240000>> export_clause;
basesolver(int sid, light* light) : id(sid), controller(light) {
good_clause_lbd = 2;

Binary file not shown.

View File

@ -2,12 +2,17 @@
#define _clause_hpp_INCLUDED
#include <boost/thread.hpp>
#include <boost/thread/thread.hpp>
#include "../utils/vec.hpp"
using std::shared_ptr;
struct clause_store {
int size, lbd;
int *data;
std::atomic<int> refs;
clause_store(int sz) {
//printf("c new clause_store\n");
size = sz;
data = (int*) malloc(sizeof(int) * sz);
lbd = 0;
@ -17,19 +22,16 @@ struct clause_store {
refs += inc;
}
bool free_clause() {
int ref = refs.fetch_sub(1);
if (ref <= 1) {
// printf("c free clause: ");
// for (int i = 0; i < size; i++)
// printf("%d ", data[i]);
// puts("");
free(data);
return true;
}
// int ref = refs.fetch_sub(1);
// if (ref <= 1) {
// free(data);
// return true;
// }
return false;
}
~clause_store() {
puts("free");
//printf("c free clause_store\n");
free(data);
}
};
@ -37,7 +39,7 @@ struct clause_store {
struct period_clauses {
int period;
std::atomic<int> refs;
vec<clause_store *> cls;
std::vector<shared_ptr<clause_store>> cls;
period_clauses(int p = 0) {
refs = 0;
period = p;
@ -59,8 +61,8 @@ struct period_clauses {
for (int i = 0; i < cls.size(); i++)
cls[i]->free_clause();
}
void push(clause_store * c) {
cls.push(c);
void push(shared_ptr<clause_store> c) {
cls.push_back(c);
}
};

View File

@ -6,7 +6,6 @@
#include "../distributed/comm_tag.h"
#include <boost/thread/thread.hpp>
int nums = 0;
double share_time = 0;
int num_procs, rank;
@ -16,31 +15,17 @@ std::vector<std::pair<MPI_Request*, int*>> send_data_struct;
MPI_Request receive_request;
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++) {
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());
}
}
// 环形传递,数据来源如果是目的地,说明数据已轮转一圈,停止发送。
if(from == target) return;
// 定义发送数据
MPI_Request *send_request = new MPI_Request();
int *send_buf;
int send_length = 0;
int send_length = 1;
// 初始化发送数据
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];
int index = 0;
send_buf[index++] = from;
for(int i=0; i<cls.size(); i++) {
auto& c = cls[i];
send_buf[index++] = c->size;
@ -63,26 +51,34 @@ void share_clauses_to_next_node(const vec<clause_store *> &cls) {
// 调用 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);
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();
int flag;
MPI_Status status;
bool received = false;
int from = -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;
MPI_Get_count(&status, MPI_INT, &count);
from = buf[index++];
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++];
for(int i=0; i<cl->size; i++) {
cl->data[i] = buf[index++];
}
clauses.push(cl);
clauses.push_back(cl);
}
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;
//LOGGER->info("receive clauses: %v", count);
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() {
@ -137,7 +128,9 @@ void sharer::do_clause_sharing() {
++nums;
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 [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);
for (int i = 0; i < producers.size(); i++) {
cls.clear();
@ -146,14 +139,15 @@ void sharer::do_clause_sharing() {
//printf("c size %d\n", sq->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;
if(receive_clauses_from_last_node(clauses)) {
std::vector<shared_ptr<clause_store>> clauses;
int from = receive_clauses_from_last_node(clauses);
if(from != -1) {
for (int j = 0; j < consumers.size(); j++) {
for (int k = 0; k < clauses.size(); k++)
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++) {
clauses[k]->free_clause();
@ -228,7 +222,7 @@ int sharer::sort_clauses(int x) {
int sz = cls[i]->size;
while (sz > bucket[x].size()) bucket[x].push();
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
// cls[i]->free_clause();
}
@ -241,14 +235,14 @@ int sharer::sort_clauses(int x) {
if (clause_num >= bucket[x][i].size()) {
space -= bucket[x][i].size() * (i + 1);
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();
}
else {
space -= clause_num * (i + 1);
for (int j = 0; j < clause_num; j++) {
cls.push(bucket[x][i].last());
bucket[x][i].pop();
cls.push_back(bucket[x][i].back());
bucket[x][i].pop_back();
}
}
}

View File

@ -15,10 +15,10 @@ public:
boost::condition_variable cond;
int terminated;
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<clause_store *> cls;
std::vector<shared_ptr<clause_store>> cls;
sharer(int idx, int intv, int lits, int share_dps = 0) {
share_intv = intv;
share_lits = lits;

Binary file not shown.