From 0b1c521bd8e9bba7f7b59f797b53f3d41ddfdf07 Mon Sep 17 00:00:00 2001 From: WeileiZeng <240155787@qq.com> Date: Tue, 31 Mar 2020 00:44:42 -0700 Subject: [PATCH] clean input and multi thread; next collect result --- makefile | 2 +- my_bp1.c | 86 +++++++++++++++++++++++++++++++++++++++----------- my_bp1.out | Bin 175968 -> 222864 bytes run_my_bp1.sh | 4 +-- weilei_lib | 1 - 5 files changed, 70 insertions(+), 23 deletions(-) delete mode 120000 weilei_lib diff --git a/makefile b/makefile index 1f5b581..590c7ff 100644 --- a/makefile +++ b/makefile @@ -16,7 +16,7 @@ INC_DIR=~/working/weilei_lib files=$(INC_DIR)/mm_read.c $(INC_DIR)/mm_read.h $(INC_DIR)/mmio.c $(INC_DIR)/mmio.h $(INC_DIR)/mm_write.c $(INC_DIR)/mm_write.h $(INC_DIR)/lib.cpp $(INC_DIR)/lib.h $(INC_DIR)/dist.c $(INC_DIR)/dist.h $(INC_DIR)/concatenation_lib.c $(INC_DIR)/concatenation_lib.h $(INC_DIR)/my_lib.h makefile #command=$(CXX) -I../../weilei_lib $(START) -o $@ $< $(word 2,$^) $(word 4, $^) $(word 6, $^) $(word 8, $^) $(word 10, $^) $(word 12, $^) $(END) -command=$(CXX) -I $(INC_DIR) $(START) -o $@ $< $(word 2,$^) $(word 4, $^) $(word 6, $^) $(word 8, $^) $(word 10, $^) $(word 12, $^) $(END) ; echo finish making +command=$(CXX) -std=c++11 -pthread -I $(INC_DIR) $(START) -o $@ $< $(word 2,$^) $(word 4, $^) $(word 6, $^) $(word 8, $^) $(word 10, $^) $(word 12, $^) $(END) ; echo finish making diff --git a/my_bp1.c b/my_bp1.c index 9723b0f..b4e9471 100644 --- a/my_bp1.c +++ b/my_bp1.c @@ -1,6 +1,8 @@ //Weilei March 26, 2020. yse c++ async to manage multi threads // copied from bp_decoding4.c - +#include +#include +#include #include #include #include @@ -14,34 +16,81 @@ using namespace itpp; // Read the code from files and do BP decoding //input:source file for stabilzier matrix; error propability p ; +int decode( GF2mat G, GF2mat H, double p, string filename_result_p); + int main(int argc, char **argv){ Parser parser; parser.init(argc,argv); //p.set_silentmode(true); string filename_G, filename_H, filename_result; - parser.get(filename_G,"filename_G"); - parser.get(filename_H,"filename_H"); - parser.get(filename_result,"filename_result"); - GF2mat G =MM_to_GF2mat(filename_G); - GF2mat H =MM_to_GF2mat(filename_H); - + //parser.get(filename_G,"filename_G"); + //parser.get(filename_H,"filename_H"); + //parser.get(filename_result,"filename_result"); + + vector> pool; + int pool_size=10; + std::chrono::milliseconds span (100); + //change parameter p, code size //char * filename_result=argv[3];//prefix for the file double p; - parser.get(p,"p"); - //atof(argv[4]); - p=p/100000.0;//previous use 1000 division. Now use 100,000 division cause the thershold for toric codes seems to be around 0.1%. + //parser.get(p,"p"); + int sizes[]= {13,11,9,7,5}; + string stabilizer_folder="data/toric/stabilizer"; + string error_folder="data/toric/bp_decoding4"; + for ( int size : sizes){ + + filename_G = stabilizer_folder + "/toric_S_x_size_" + to_string(size) + ".mm"; + filename_H = stabilizer_folder + "/toric_S_z_size_" + to_string(size) + ".mm"; + filename_result = error_folder + "/toric_S_size_" + to_string(size) + ".mm_rate"; + for ( int ip=100;ip<5001;ip+=100){ + //atof(argv[4]); + p=ip/100000.0;//previous use 1000 division. Now use 100,000 division cause the thershold for toric codes seems to be around 0.1%. + char filename_result_p[255]; + sprintf( filename_result_p,"%s%.5f",filename_result.c_str(),p);//append p in the file name + string filename_result_p_string(filename_result_p); + //cout<= pool_size ){ + //wait until some of them finish + //break; + for(vector > :: iterator it = pool.begin(); it != pool.end(); ++it){ + //printf("%d", *it); + if ( it->wait_for(span) == future_status::ready){ + cout<<"."< fut = async(launch::async, decode,G, H, p, filename_result_p); + //pool.push_back(move(fut)); + pool.push_back(async(launch::async, decode,G, H, p, filename_result_p)); + + cout<<"add new thread. "<=0){ if ( current_iteration < 0 ){ - cout<