8 #include <itpp/itbase.h>
28 int simulate(
string title_str,
string note,
int mode,
int sub_mode_A,
int sub_mode_B,
29 int n_low,
int n_high,
int k_low,
int k_high,
int debug,
34 int main(
int args,
char ** argv){
36 parser.init(args,argv);
37 parser.set_silentmode(
true);
38 int num_cores; parser.get(num_cores,
"num_cores");
39 int mode = -1; parser.get(mode,
"mode");
40 int sub_mode_A = -1; parser.get(sub_mode_A,
"sub_mode_A");
41 int sub_mode_B = -1; parser.get(sub_mode_B,
"sub_mode_B");
42 std::string title_str=
"no-title"; parser.get(title_str,
"title");
43 std::string note=
"no-note"; parser.get(note,
"note");
45 parser.get(debug,
"debug");
46 int seed; parser.get(seed,
"seed");
48 if (debug) std::cout<<
"input seed: "<<seed<<
" --> ";
50 itpp::RNG_reset(seed);
51 if (debug) std::cout<<
"converted seed:"<<seed;
54 int na_input; parser.get(na_input,
"na_input");
55 int n_low; parser.get(n_low,
"n_low");
56 int n_high; parser.get(n_high,
"n_high");
57 int k_low; parser.get(k_low,
"k_low");
58 int k_high; parser.get(k_high,
"k_high");
59 int max_trial; parser.get(max_trial,
"max_trial");
61 Real_Timer timer; timer.tic();
64 const int id_list_max=100000;
65 int id_list[id_list_max][5];
74 cout<<
"max_trial = "<<max_trial<<endl;
76 #pragma omp parallel for schedule(guided) num_threads(num_cores)
77 for (
int i =0; i< max_trial; i++){
80 string title_str_trial = title_str +
"-" +to_string(i);
81 simulate(title_str_trial, note, mode, sub_mode_A, sub_mode_B, n_low, n_high, k_low, k_high, debug, code_temp);
85 if ( count % 10 == 0 )
86 cout<<
"count="<<count<<endl;
97 simulate(title_str, note, mode, sub_mode_A, sub_mode_B, 0, 0,0,0, debug, code_temp);
103 int total_trials=0, calculated_trials=0;
105 for (
int Gax_row = 1; Gax_row< na-1; Gax_row++){
106 const int id_Gax_MAX = (int) pow(2, Gax_row * (na-Gax_row) ) -1 ;
107 #pragma omp parallel for schedule(guided) num_threads(num_cores)
108 for (
int id_Gax = 1; id_Gax < id_Gax_MAX+1 ; id_Gax++){
109 if ( id_Gax % 1000 == 0 )
110 cout<<
"start: id_Gax="<<id_Gax<<
",\t id_Gax_MAX="<<id_Gax_MAX<<
",\t Gax_row="<<Gax_row<<endl;
111 for (
int Gaz_row = 1; Gaz_row< min(Gax_row +1,na-Gax_row); Gaz_row ++){
112 const int id_Gaz_MAX = (int) pow(2, Gaz_row*(na - Gax_row)) - 1;
113 for (
int id_Gaz = 1; id_Gaz < id_Gaz_MAX+1 ; id_Gaz++){
117 if (debug) cout<<
"Gax_row="<<Gax_row<<
",Gaz_row="<<Gaz_row<<endl;
120 CSSCode codeA(na,Gax_row,id_Gax,Gaz_row,id_Gaz);
128 if (debug) cout<<
"duplicated case, return 2"<<endl;
134 int id[5] = {na,Gax_row,id_Gax,Gaz_row,id_Gaz};
138 for (
int i_id = 0; i_id < 5; i_id ++) id_list[calculated_trials][i_id] =
id[i_id];
148 string title_str_trial=title_str+
"-na"+to_string(na)+
"-Gax_row"+to_string(Gax_row)+
"-id_Gax"+to_string(id_Gax)
149 +
"-Gaz_row"+to_string(Gaz_row)+
"-id_Gaz"+to_string(id_Gaz);
156 cout<<
"start calculating for "<< calculated_trials<<
" cases out of "<<total_trials<<
" trials."<<endl;
157 cout<<
"time used: "<<timer.toc()<<
" sec"<<endl;
160 if ( sub_mode_A != 2)
161 cout<<
"wrong input or no input for sub_mode_A. It should be 2"<<endl;
165 switch ( sub_mode_B ){
170 #pragma omp parallel for schedule(guided) num_threads(num_cores)
171 for (
int iAB = 0; iAB <calculated_trials; iAB++){
175 if ( count % 10 == 0){
176 cout<<count*100/calculated_trials<<
"% finished. total: "<<calculated_trials
177 <<
", remaining time:"<<timer.toc()/count*(calculated_trials-count)/60<<
" min"
185 CSSCode codeA(id_list[iA][0],id_list[iA][1],id_list[iA][2],id_list[iA][3],id_list[iA][4]);
190 string title_str_trial=title_str+
"-na"+to_string(codeA.
n)+
"-Gax_row"+to_string(codeA.
Gx_row)+
"-id_Gax"+to_string(codeA.
id_Gx)
191 +
"-Gaz_row"+to_string(codeA.
Gz_row)+
"-id_Gaz"+to_string(codeA.
id_Gz);
196 simulate(title_str_trial, note, mode, sub_mode_A, sub_mode_B, 0, 0, 0, 0, debug, codeC);
197 simulate(title_str_trial, note, mode, sub_mode_A, 3, 0, 0, 0, 0, debug, codeC);
204 const int total = calculated_trials*calculated_trials;
205 const int chunk_size_max = 10000;
206 const int chunk_size = ( total/100 < chunk_size_max ) ? total/100:chunk_size_max ;
210 #pragma omp parallel for schedule(guided) num_threads(num_cores)
213 for (
int iAB = count; iAB <total; iAB++){
218 if (count % chunk_size == 0){
219 cout<<count<<
", "<<(int) (count*1.0/total*100)<<
"% finished. total: "<<total
220 <<
", remaining time:"<<timer.toc()/count*(total-count)/60<<
" min"
224 int iA = iAB / calculated_trials;
225 int iB = iAB % calculated_trials;
226 if ( iA < iB )
continue;
228 CSSCode codeA(id_list[iA][0],id_list[iA][1],id_list[iA][2],id_list[iA][3],id_list[iA][4]);
229 CSSCode codeB(id_list[iB][0],id_list[iB][1],id_list[iB][2],id_list[iB][3],id_list[iB][4]);
232 string title_str_trial=title_str
233 +
"-A-"+to_string(codeA.
n)+
"-"+to_string(codeA.
Gx_row)+
"-"+to_string(codeA.
id_Gx)
234 +
"-"+to_string(codeA.
Gz_row)+
"-"+to_string(codeA.
id_Gz)
235 +
"-B-"+to_string(codeB.
n)+
"-"+to_string(codeB.
Gx_row)+
"-"+to_string(codeB.
id_Gx)
236 +
"-"+to_string(codeB.
Gz_row)+
"-"+to_string(codeB.
id_Gz);
242 simulate(title_str_trial, note, mode, sub_mode_A, sub_mode_B, 0, 0, 0, 0, debug, codeC);
248 cout<<
"main(): illegal sub_mode_B value"<<sub_mode_B<<endl;
255 cout<<
"main(): illegal mode value"<<endl;
261 int simulate(
string title_str,
string note,
int mode,
int sub_mode_A,
int sub_mode_B,
262 int n_low,
int n_high,
int k_low,
int k_high,
int debug,
267 if ( mode == 3) mode =1;
269 Real_Timer timer; timer.tic();
270 GF2mat Gax,Gaz,Cax,Caz;
271 GF2mat Gbx,Gbz,Cbx,Cbz;
272 int na,ka, Gax_row,Gaz_row;
273 int nb,kb, Gbx_row,Gbz_row;
278 const char * title = title_str.c_str();
279 char filename_Gax[256];
char filename_Gaz[256];
char filename_Gbx[256];
char filename_Gbz[256];
280 sprintf(filename_Gax,
"%sGax.mm",title); sprintf(filename_Gaz,
"%sGaz.mm",title); sprintf(filename_Gbx,
"%sGbx.mm",title); sprintf(filename_Gbz,
"%sGbz.mm",title);
283 if (debug) cout<<mode<<endl<<title<<endl;
286 switch ( sub_mode_A ){
288 na=randi(n_low,n_high); ka = randi(k_low,k_high);Gax_row=randi(1,na-ka-1); Gaz_row=na-ka-Gax_row;
300 cout<<
"code A is not defined,"<<endl;
309 if (debug) cout<<
"duplicated case, return 2"<<endl;
325 cout<<
"simulate(): illegal sub_mode_A value"<<endl;
330 switch ( sub_mode_B ){
334 nb=randi(n_low,n_high); kb = randi(k_low,k_high);Gbx_row=randi(1,nb-kb-1); Gbz_row=nb-kb-Gbx_row;
363 if (debug) cout<<
"duplicated case, return 2"<<endl;
384 cout<<
"simulate(): illegal sub_mode_A value"<<endl;
392 if (debug) cout<<
"check "<<title<<endl;
416 if (debug) {cout<<
"Gax "<<Gax<<endl; cout<<
"Gaz "<<Gaz<<endl; cout<<
"Cax "<<Cax<<endl; cout<<
"Caz "<<Caz<<endl;}
417 if (debug) { cout<<
"Gbx "<<Gbx<<endl; cout<<
"Gbz "<<Gbz<<endl; cout<<
"Cbx "<<Cbx<<endl; cout<<
"Cbz "<<Cbz<<endl;}
457 int flag_chain_complex=0;
459 if (
product(Gax,Gaz,Gbx,Gbz,dax,daz,dbx,dbz,debug,0) == 2) {
460 std::cout<<title<<
","<<note<<
", time:"<<timer.toc()<<std::endl;
461 flag_chain_complex=1;
464 if (
product(Gax,Gaz,Gbx,Gbz,dax,daz,dbx,dbz,debug,1) == 2){
465 std::cout<<title<<
","<<note<<
", time:"<<timer.toc()<<std::endl;
469 flag_chain_complex=1;
474 if ( flag_chain_complex ){
485 if (
product(Gax,Gaz,Gbx,Gbz,dax,daz,dbx,dbz,debug,3) == 2)
486 std::cout<<title<<
","<<note<<
", time:"<<timer.toc()<<std::endl;
492 if (
product(Gax,Gaz,Gbx,Gbz,dax,daz,dbx,dbz,debug,4) == 2)
493 std::cout<<title<<
","<<note<<
", time:"<<timer.toc()<<std::endl;
510 if ( debug ) timer.toc_print();