23 garfn << key <<
".ci.gar";
25 ifstream in(garfn.str());
28 auto c = ar.unarchive_ex(
"c");
29 if(c!=19790923)
throw Error(
"Contours: *.ci.gar error!");
30 FT_N_XN = ex_to<lst>(ar.unarchive_ex(
"ftnxn"));
35 if(FT_N_XN.nops()<1)
return;
42 for(
int i=0; i<FT_N_XN.nops(); i++) ftnxn_vec.push_back(FT_N_XN.op(i));
45 string spid = to_string(pid);
46 if(
get_env(
"GiNaC_Parallel_Host").length()>0) spid =
get_env(
"GiNaC_Parallel_Host")+
"_"+spid;
48 cmd <<
"mkdir -p " << spid;
49 if(!
dir_exists(spid))
auto rc = system(cmd.str().c_str());
53 fsofn << key <<
"F.so";
55 fsofn << spid <<
"F.so";
57 void*
module = dlopen(fsofn.str().c_str(), RTLD_NOW);
58 if (module ==
nullptr) {
59 module = dlopen(("./"+fsofn.str()).c_str(), RTLD_NOW);
60 if (module ==
nullptr) {
61 cerr <<
ErrColor <<
"Contours: could not open compiled module!" <<
RESET << endl;
62 cout <<
"dlerror(): " << dlerror() << endl;
70 GiNaC_Parallel(ftnxn_vec.size(), [&ftnxn_vec,
this,module](
int idx)->ex {
74 if(Verbose>5) cout <<
" λ: " << idx <<
" / " << ftnxn_vec.size() << flush;
75 auto ftnxn = ftnxn_vec[idx];
77 for(auto kv : Parameter) if(npara<kv.first) npara = kv.first;
80 for(auto kv : Parameter) {
81 paras[kv.first] = (dREAL)ex2q(kv.second);
82 plRepl.append(PL(kv.first)==kv.second);
85 auto ft = ftnxn.op(0);
90 cout <<
" λ: xSign>0 or CTLaMax<0, back to REAL mode!" << endl;
92 return lst{ ftnxn.op(1), 1979 };
95 int nvars = ex_to<numeric>(ftnxn.op(2)).to_int();
102 fname <<
"minF_"<<ftnxn.op(1);
106 fname <<
"minFM_"<<ftnxn.op(1);
108 if(fp==NULL || fp2==NULL) {
109 cerr <<
ErrColor <<
"Contours: fp==NULL/fp2==NULL" <<
RESET << endl;
110 cout <<
"dlerror(): " << dlerror() << endl;
118 cout <<
" λ: F>0 Found, back to REAL mode!" << endl;
120 return lst{ ftnxn.op(1), 1979 };
127 cout <<
" λ: F<0 Found, back to REAL mode!" << endl;
129 return lst{ ftnxn.op(1), 1979 };
134 dREAL max_df = -1, max_f;
135 for(
int i=0; i<nvars; i++) {
139 fname <<
"dirC_"<<ftnxn.op(1)<<
"_"<<i;
143 cout <<
"dlerror(): " << dlerror() << endl;
150 if(max_df<maxdf) max_df = maxdf;
153 for(
int i=0; i<nvars; i++) {
154 if(nlas[i] < 1) nlas[i] = 1;
155 else nlas[i] = 1/nlas[i];
159 for(
int i=0; i<nvars; i++) {
160 las.append(
q2ex(nlas[i]));
166 fname <<
"imgF_"<<ftnxn.op(1);
170 cout <<
"dlerror(): " << dlerror() << endl;
176 for(
int i=0; i<nvars+1; i++) UB[i] = 1;
182 if(res < -1E-5) laEnd = min;
187 cout <<
" λ: " <<
ErrColor <<
"too small lambda!" <<
RESET << endl;
191 if(laEnd-laBegin <= 0.01*laEnd)
break;
192 min = (laBegin + laEnd) / 2.0;
196 las.append(
q2ex(min));
199 cout <<
" λ: " <<
NN(las,3) << endl;
202 return lst{ ftnxn.op(1), las };
206 if(use_dlclose) dlclose(module);
211 if(pkey !=
"") garfn <<
"-" << pkey;
214 for(
auto &item : res) gar_res.append(item);
216 ar.archive_ex(gar_res,
"res");
217 ar.archive_ex(19790923,
"c");
218 ofstream out(garfn.str());
222 for(
auto &item : res) LambdaMap[item.op(0)] = item.op(1);
227 cmd <<
"rm -rf " << spid;
228 if(!
Debug)
auto rc = system(cmd.str().c_str());
virtual dREAL FindMinimum(int nvars, FunctionType func, dREAL *PL=NULL, dREAL *las=NULL, dREAL *UB=NULL, dREAL *LB=NULL, dREAL *IP=NULL, bool compare0=false, int TryPTS=0, int SavePTS=0)=0