00001
00002
00003
00004
00005 #include "cddefines.h"
00006 #include "version.h"
00007 #include "optimize.h"
00008 #if defined(__unix) || defined(__APPLE__)
00009 #include <cstddef>
00010 #include <sys/types.h>
00011 #include <sys/wait.h>
00012 #include <unistd.h>
00013 #else
00014 #define pid_t int
00015 #define fork() TotalInsanityAsStub<pid_t>()
00016 #define wait(X) TotalInsanityAsStub<pid_t>()
00017 #endif
00018 #include "mpi_utilities.h"
00019
00020
00023 const char* STATEFILE = "continue.pmr";
00024 const char* STATEFILE_BACKUP = "continue.bak";
00025
00026
00027
00028
00029 inline void wr_block(const void*,size_t,const char*);
00030 inline void rd_block(void*,size_t,const char*);
00031
00032
00033 template<class X, class Y, int NP, int NSTR>
00034 void phymir_state<X,Y,NP,NSTR>::p_clear1()
00035 {
00036 DEBUG_ENTRY( "p_clear1()" );
00037
00038
00039
00040 memset( this, 0, sizeof(*this) );
00041
00042 p_xmax = numeric_limits<X>::max();
00043 p_ymax = numeric_limits<Y>::max() / Y(2.);
00044 for( int i=0; i < 2*NP+1; ++i )
00045 {
00046 for( int j=0; j < NP; ++j )
00047 p_xp[i][j] = -p_xmax;
00048 p_yp[i] = -p_ymax;
00049 }
00050 for( int i=0; i < NP; ++i )
00051 {
00052 p_absmin[i] = -p_xmax;
00053 p_absmax[i] = p_xmax;
00054 p_varmin[i] = p_xmax;
00055 p_varmax[i] = -p_xmax;
00056 for( int j=0; j < NP; ++j )
00057 p_a2[i][j] = -p_xmax;
00058 p_c1[i] = -p_xmax;
00059 p_c2[i] = -p_xmax;
00060 p_xc[i] = -p_xmax;
00061 p_xcold[i] = -p_xmax;
00062 }
00063 p_vers = VRSNEW;
00064 p_toler = -p_xmax;
00065 p_dmax = X(0.);
00066 p_dold = X(0.);
00067 p_ymin = p_ymax;
00068 p_dim = int32(NP);
00069 p_sdim = int32(NSTR);
00070 p_nvar = int32(0);
00071 p_noptim = int32(0);
00072 p_maxiter = int32(0);
00073 p_jmin = int32(-1);
00074 p_maxcpu = int32(1);
00075 p_curcpu = int32(0);
00076 p_mode = PHYMIR_ILL;
00077
00078
00079
00080
00081
00082
00083 p_size = static_cast<uint32>(reinterpret_cast<size_t>(&p_size) - reinterpret_cast<size_t>(this));
00084 p_func = NULL;
00085 }
00086
00087 template<class X, class Y, int NP, int NSTR>
00088 void phymir_state<X,Y,NP,NSTR>::p_wr_state(const char *fnam) const
00089 {
00090 DEBUG_ENTRY( "p_wr_state()" );
00091
00092 if( cpu.i().lgMaster() && strlen(fnam) > 0 )
00093 {
00094 FILE *fdes = open_data( fnam, "wb", AS_LOCAL_ONLY_TRY );
00095 bool lgErr = ( fdes == NULL );
00096 lgErr = lgErr || ( fwrite( &p_size, sizeof(uint32), 1, fdes ) != 1 );
00097 lgErr = lgErr || ( fwrite( this, static_cast<size_t>(p_size), 1, fdes ) != 1 );
00098 lgErr = lgErr || ( fclose(fdes) != 0 );
00099 if( lgErr )
00100 {
00101 printf( "p_wr_state: error writing file: %s\n", fnam );
00102 remove(fnam);
00103 }
00104 }
00105 return;
00106 }
00107
00108 template<class X, class Y, int NP, int NSTR>
00109 void phymir_state<X,Y,NP,NSTR>::p_rd_state(const char *fnam)
00110 {
00111 DEBUG_ENTRY( "p_rd_state()" );
00112
00113 FILE *fdes = open_data( fnam, "rb", AS_LOCAL_ONLY );
00114 uint32 wrsize;
00115 bool lgErr = ( fread( &wrsize, sizeof(uint32), 1, fdes ) != 1 );
00116 lgErr = lgErr || ( p_size != wrsize );
00117 lgErr = lgErr || ( fread( this, static_cast<size_t>(p_size), 1, fdes ) != 1 );
00118 lgErr = lgErr || ( fclose(fdes) != 0 );
00119 if( lgErr )
00120 {
00121 printf( "p_rd_state: error reading file: %s\n", fnam );
00122 cdEXIT(EXIT_FAILURE);
00123 }
00124 return;
00125 }
00126
00127 template<class X, class Y, int NP, int NSTR>
00128 Y phymir_state<X,Y,NP,NSTR>::p_execute_job(const X x[],
00129 int jj,
00130 int runNr)
00131 {
00132 DEBUG_ENTRY( "p_execute_job()" );
00133
00134 pid_t pid;
00135 switch( p_mode )
00136 {
00137 case PHYMIR_SEQ:
00138 return p_lgLimitExceeded(x) ? p_ymax : p_func(x,runNr);
00139 case PHYMIR_FORK:
00140 p_curcpu++;
00141 if( p_curcpu > p_maxcpu )
00142 {
00143
00144 (void)wait(NULL);
00145 p_curcpu--;
00146 }
00147
00148 fflush(NULL);
00149 pid = fork();
00150 if( pid < 0 )
00151 {
00152 fprintf( ioQQQ, "creating the child process failed\n" );
00153 cdEXIT(EXIT_FAILURE);
00154 }
00155 else if( pid == 0 )
00156 {
00157
00158 p_execute_job_parallel( x, jj, runNr );
00159
00160
00161 ioQQQ = NULL;
00162 cdEXIT(EXIT_SUCCESS);
00163 }
00164
00165 return p_ymax;
00166 case PHYMIR_MPI:
00167 if( (jj%cpu.i().nCPU()) == cpu.i().nRANK() )
00168 p_execute_job_parallel( x, jj, runNr );
00169
00170 return p_ymax;
00171 default:
00172 TotalInsanity();
00173 }
00174 }
00175
00176
00177 template<class X, class Y, int NP, int NSTR>
00178 void phymir_state<X,Y,NP,NSTR>::p_execute_job_parallel(const X x[],
00179 int jj,
00180 int runNr) const
00181 {
00182 DEBUG_ENTRY( "p_execute_job_parallel()" );
00183
00184 char fnam1[20], fnam2[20];
00185 sprintf(fnam1,"yval_%d",jj);
00186 sprintf(fnam2,"output_%d",jj);
00187
00188 FILE *ioQQQ_old = ioQQQ;
00189 ioQQQ = open_data( fnam2, "w", AS_LOCAL_ONLY );
00190
00191 Y yval = p_ymax;
00192 wr_block(&yval,sizeof(yval),fnam1);
00193 if( !p_lgLimitExceeded(x) )
00194 {
00195 try
00196 {
00197 yval = p_func(x,runNr);
00198 }
00199 catch( ... )
00200 {
00201
00202 fflush(NULL);
00203 yval = p_ymax;
00204 }
00205 wr_block(&yval,sizeof(yval),fnam1);
00206 }
00207 fclose( ioQQQ );
00208 ioQQQ = ioQQQ_old;
00209 }
00210
00211 template<class X, class Y, int NP, int NSTR>
00212 void phymir_state<X,Y,NP,NSTR>::p_barrier(int jlo,
00213 int jhi)
00214 {
00215 DEBUG_ENTRY( "p_barrier()" );
00216
00217 switch( p_mode )
00218 {
00219 case PHYMIR_SEQ:
00220
00221 break;
00222 case PHYMIR_FORK:
00223
00224 while( p_curcpu > 0 )
00225 {
00226 (void)wait(NULL);
00227 p_curcpu--;
00228 }
00229 p_process_output( jlo, jhi );
00230 break;
00231 case PHYMIR_MPI:
00232
00233 MPI::COMM_WORLD.Barrier();
00234 p_process_output( jlo, jhi );
00235
00236 MPI::COMM_WORLD.Bcast( &p_yp[jlo], jhi-jlo+1, MPI::type(p_yp), 0 );
00237 break;
00238 default:
00239 TotalInsanity();
00240 }
00241 }
00242
00243 template<class X, class Y, int NP, int NSTR>
00244 void phymir_state<X,Y,NP,NSTR>::p_process_output(int jlo,
00245 int jhi)
00246 {
00247 DEBUG_ENTRY( "p_process_output()" );
00248
00249 if( cpu.i().lgMaster() )
00250 {
00251 char fnam[20];
00252 for( int jj=jlo; jj <= jhi; jj++ )
00253 {
00254 sprintf(fnam,"yval_%d",jj);
00255 rd_block(&p_yp[jj],sizeof(p_yp[jj]),fnam);
00256 remove(fnam);
00257 sprintf(fnam,"output_%d",jj);
00258 append_file(ioQQQ,fnam);
00259 remove(fnam);
00260 }
00261 }
00262 }
00263
00264 template<class X, class Y, int NP, int NSTR>
00265 void phymir_state<X,Y,NP,NSTR>::p_evaluate_hyperblock()
00266 {
00267 DEBUG_ENTRY( "p_evaluate_hyperblock()" );
00268
00269 int jlo = 1, jhi = 0;
00270 for( int j=0; j < p_nvar; j++ )
00271 {
00272 X sgn = X(1.);
00273 for( int jj=2*j+1; jj <= 2*j+2; jj++ )
00274 {
00275 sgn = -sgn;
00276 for( int i=0; i < p_nvar; i++ )
00277 {
00278 p_xp[jj][i] = p_xc[i] + sgn*p_dmax*p_c2[j]*p_a2[j][i];
00279 p_varmax[i] = max(p_varmax[i],p_xp[jj][i]);
00280 p_varmin[i] = min(p_varmin[i],p_xp[jj][i]);
00281 }
00282 if( !lgMaxIterExceeded() )
00283 {
00284
00285
00286 p_yp[jj] = p_execute_job( p_xp[jj], jj, p_noptim++ );
00287 jhi = jj;
00288 }
00289 }
00290 }
00291
00292 p_barrier( jlo, jhi );
00293 }
00294
00295 template<class X, class Y, int NP, int NSTR>
00296 void phymir_state<X,Y,NP,NSTR>::p_setup_next_hyperblock()
00297 {
00298 DEBUG_ENTRY( "p_setup_next_hyperblock()" );
00299
00300 const Y F0 = Y(1.4142136);
00301 const X F1 = X(0.7071068);
00302 const X F2 = X(0.1);
00303
00304
00305 for( int jj=1; jj <= 2*p_nvar; jj++ )
00306 {
00307 if( p_yp[jj] < p_ymin )
00308 {
00309 p_ymin = p_yp[jj];
00310 p_jmin = jj;
00311 }
00312 }
00313 bool lgNewCnt = p_jmin > 0;
00314
00315
00316 bool lgNegd2 = false;
00317 X xnrm = X(0.);
00318 X xhlp[NP];
00319 for( int i=0; i < p_nvar; i++ )
00320 {
00321 Y d1 = p_yp[2*i+2] - p_yp[2*i+1];
00322 Y d2 = Y(0.5)*p_yp[2*i+2] - p_yp[0] + Y(0.5)*p_yp[2*i+1];
00323 if( d2 <= Y(0.) )
00324 lgNegd2 = true;
00325 xhlp[i] = -p_dmax*p_c2[i]*(static_cast<X>(max(min((Y(0.25)*d1)/max(d2,Y(1.e-10)),F0),-F0)) -
00326 p_delta(2*i+1,p_jmin) + p_delta(2*i+2,p_jmin));
00327 xnrm += pow2(xhlp[i]);
00328 }
00329 xnrm = static_cast<X>(sqrt(xnrm));
00330
00331 int imax = 0;
00332 X amax = X(0.);
00333 for( int j=0; j < p_nvar; j++ )
00334 {
00335 for( int i=0; i < p_nvar; i++ )
00336 {
00337 if( xnrm > X(0.) )
00338 {
00339 if( j == 0 )
00340 {
00341 p_a2[0][i] *= xhlp[0];
00342 }
00343 else
00344 {
00345 p_a2[0][i] += xhlp[j]*p_a2[j][i];
00346 p_a2[j][i] = p_delta(i,j);
00347 if( j == p_nvar-1 && abs(p_a2[0][i]) > amax )
00348 {
00349 imax = i;
00350 amax = abs(p_a2[0][i]);
00351 }
00352 }
00353 }
00354 else
00355 {
00356 p_a2[j][i] = p_delta(i,j);
00357 }
00358 }
00359 }
00360
00361 if( imax > 0 )
00362 {
00363 p_a2[imax][0] = X(1.);
00364 p_a2[imax][imax] = X(0.);
00365 }
00366
00367 p_phygrm( p_a2, p_nvar );
00368
00369
00370 for( int i=0; i < p_nvar; i++ )
00371 {
00372 p_c2[i] = X(0.);
00373 for( int j=0; j < p_nvar; j++ )
00374 {
00375 p_c2[i] += pow2(p_a2[i][j]/p_c1[j]);
00376 }
00377 p_c2[i] = static_cast<X>(1./sqrt(p_c2[i]));
00378 p_xc[i] = p_xp[p_jmin][i];
00379 p_xp[0][i] = p_xc[i];
00380 }
00381 p_yp[0] = p_yp[p_jmin];
00382 p_jmin = 0;
00383
00384 X r1, r2;
00385 if( lgNegd2 )
00386 {
00387
00388
00389
00390 r1 = F1;
00391 r2 = F1;
00392 }
00393 else
00394 {
00395 r1 = F2;
00396 if( lgNewCnt )
00397 {
00398
00399 r2 = sqrt(1.f/F1);
00400 }
00401 else
00402 {
00403
00404
00405 r2 = sqrt(F1);
00406 }
00407 }
00408 p_dmax = min(max(xnrm/p_c2[0],p_dmax*r1),p_dmax*r2);
00409
00410 p_dmax = MIN2(p_dmax,p_dold);
00411 }
00412
00413 template<class X, class Y, int NP, int NSTR>
00414 void phymir_state<X,Y,NP,NSTR>::p_reset_hyperblock()
00415 {
00416 DEBUG_ENTRY( "p_reset_hyperblock()" );
00417
00418 if( !lgConvergedRestart() )
00419 {
00420
00421 for( int i=0; i < p_nvar; i++ )
00422 {
00423 p_xcold[i] = p_xc[i];
00424 p_c2[i] = p_c1[i];
00425 }
00426 p_dmax = p_dold;
00427 p_reset_transformation_matrix();
00428 }
00429 }
00430
00431 template<class X, class Y, int NP, int NSTR>
00432 void phymir_state<X,Y,NP,NSTR>::p_phygrm(X a[][NP],
00433 int n)
00434 {
00435 DEBUG_ENTRY( "p_phygrm()" );
00436
00437
00438 for( int i=0; i < n; i++ )
00439 {
00440 X ip = X(0.);
00441 for( int k=0; k < n; k++ )
00442 ip += pow2(a[i][k]);
00443 ip = sqrt(ip);
00444 for( int k=0; k < n; k++ )
00445 a[i][k] /= ip;
00446 for( int j=i+1; j < n; j++ )
00447 {
00448 X ip = X(0.);
00449 for( int k=0; k < n; k++ )
00450 ip += a[i][k]*a[j][k];
00451 for( int k=0; k < n; k++ )
00452 a[j][k] -= ip*a[i][k];
00453 }
00454 }
00455 return;
00456 }
00457
00458 template<class X, class Y, int NP, int NSTR>
00459 bool phymir_state<X,Y,NP,NSTR>::p_lgLimitExceeded(const X x[]) const
00460 {
00461 DEBUG_ENTRY( "p_lgLimitExceeded()" );
00462
00463 for( int i=0; i < p_nvar; i++ )
00464 {
00465 if( x[i] < p_absmin[i] )
00466 return true;
00467 if( x[i] > p_absmax[i] )
00468 return true;
00469 }
00470 return false;
00471 }
00472
00473 template<class X, class Y, int NP, int NSTR>
00474 void phymir_state<X,Y,NP,NSTR>::p_reset_transformation_matrix()
00475 {
00476 DEBUG_ENTRY( "p_reset_transformation_matrix()" );
00477
00478
00479 for( int i=0; i < p_nvar; i++ )
00480 for( int j=0; j < p_nvar; j++ )
00481 p_a2[j][i] = p_delta(i,j);
00482 }
00483
00484 template<class X, class Y, int NP, int NSTR>
00485 void phymir_state<X,Y,NP,NSTR>::init_minmax(const X pmin[],
00486 const X pmax[],
00487 int nvar)
00488 {
00489 DEBUG_ENTRY( "init_minmax()" );
00490
00491 ASSERT( !lgInitialized() );
00492
00493 for( int i=0; i < nvar; i++ )
00494 {
00495 p_absmin[i] = pmin[i];
00496 p_absmax[i] = pmax[i];
00497 }
00498 }
00499
00500 template<class X, class Y, int NP, int NSTR>
00501 void phymir_state<X,Y,NP,NSTR>::init_strings(const char* date,
00502 const char* version,
00503 const char* host_name)
00504 {
00505 DEBUG_ENTRY( "init_strings()" );
00506
00507
00508 if( date != NULL )
00509 strncpy( p_chStr1, date, NSTR-1 );
00510 if( version != NULL )
00511 strncpy( p_chStr2, version, NSTR-1 );
00512 if( host_name != NULL )
00513 strncpy( p_chStr3, host_name, NSTR-1 );
00514 }
00515
00516 template<class X, class Y, int NP, int NSTR>
00517 void phymir_state<X,Y,NP,NSTR>::init_state_file_name(const char* fnam)
00518 {
00519 DEBUG_ENTRY( "init_state_file_name()" );
00520
00521
00522 strncpy( p_chState, fnam, NSTR-1 );
00523 }
00524
00525 template<class X, class Y, int NP, int NSTR>
00526 void phymir_state<X,Y,NP,NSTR>::initial_run(Y (*func)(const X[],int),
00527 int nvar,
00528 const X start[],
00529 const X del[],
00530 X toler,
00531 int maxiter,
00532 phymir_mode mode,
00533 int maxcpu)
00534 {
00535 DEBUG_ENTRY( "initial_run()" );
00536
00537 ASSERT( nvar > 0 && nvar <= NP );
00538
00539 p_func = func;
00540 p_nvar = nvar;
00541 p_toler = toler;
00542 p_maxiter = maxiter;
00543 p_mode = mode;
00544 p_maxcpu = maxcpu;
00545 p_noptim = 0;
00546
00547
00548 p_dmax = X(0.);
00549 for( int i=0; i < p_nvar; i++ )
00550 p_dmax = max(p_dmax,abs(del[i]));
00551
00552 p_dold = p_dmax;
00553 for( int i=0; i < p_nvar; i++ )
00554 {
00555 p_xc[i] = start[i];
00556 p_xcold[i] = p_xc[i] + X(10.)*p_toler;
00557 p_c1[i] = abs(del[i])/p_dmax;
00558 p_c2[i] = p_c1[i];
00559 p_xp[0][i] = p_xc[i];
00560 p_varmax[i] = max(p_varmax[i],p_xc[i]);
00561 p_varmin[i] = min(p_varmin[i],p_xc[i]);
00562 }
00563
00564
00565
00566 p_yp[0] = p_execute_job( p_xc, 0, p_noptim++ );
00567 p_barrier( 0, 0 );
00568
00569 p_ymin = p_yp[0];
00570 p_jmin = 0;
00571
00572 p_reset_transformation_matrix();
00573
00574 p_wr_state( p_chState );
00575 }
00576
00577 template<class X, class Y, int NP, int NSTR>
00578 void phymir_state<X,Y,NP,NSTR>::continue_from_state(Y (*func)(const X[],int),
00579 int nvar,
00580 const char* fnam,
00581 X toler,
00582 int maxiter,
00583 phymir_mode mode,
00584 int maxcpu)
00585 {
00586 DEBUG_ENTRY( "continue_from_state()" );
00587
00588 p_rd_state( fnam );
00589
00590 if( !fp_equal( p_vers, VRSNEW ) )
00591 {
00592 printf( "optimize continue - file has incompatible version, sorry\n" );
00593 cdEXIT(EXIT_FAILURE);
00594 }
00595 if( p_dim != NP )
00596 {
00597 printf( "optimize continue - arrays have wrong dimension, sorry\n" );
00598 cdEXIT(EXIT_FAILURE);
00599 }
00600 if( p_sdim != NSTR )
00601 {
00602 printf( "optimize continue - strings have wrong length, sorry\n" );
00603 cdEXIT(EXIT_FAILURE);
00604 }
00605 if( p_nvar != nvar )
00606 {
00607 printf( "optimize continue - wrong number of free parameters, sorry\n" );
00608 cdEXIT(EXIT_FAILURE);
00609 }
00610
00611 p_func = func;
00612
00613
00614 p_toler = toler;
00615
00616 p_maxiter = maxiter;
00617
00618 p_mode = mode;
00619 p_maxcpu = maxcpu;
00620 }
00621
00622 template<class X, class Y, int NP, int NSTR>
00623 void phymir_state<X,Y,NP,NSTR>::optimize()
00624 {
00625 DEBUG_ENTRY( "optimize()" );
00626
00627 ASSERT( lgInitialized() );
00628
00629 while( !lgConverged() )
00630 {
00631 p_evaluate_hyperblock();
00632 if( lgMaxIterExceeded() )
00633 break;
00634 p_setup_next_hyperblock();
00635 p_wr_state( p_chState );
00636 }
00637 }
00638
00639 template<class X, class Y, int NP, int NSTR>
00640 void phymir_state<X,Y,NP,NSTR>::optimize_with_restart()
00641 {
00642 DEBUG_ENTRY( "optimize_with_restart()" );
00643
00644 ASSERT( lgInitialized() );
00645
00646 while( !lgConvergedRestart() )
00647 {
00648 optimize();
00649 if( lgMaxIterExceeded() )
00650 break;
00651 p_reset_hyperblock();
00652 }
00653 }
00654
00655 template<class X, class Y, int NP, int NSTR>
00656 bool phymir_state<X,Y,NP,NSTR>::lgConvergedRestart() const
00657 {
00658 DEBUG_ENTRY( "lgConvergedRestart()" );
00659
00660 if( lgConverged() )
00661 {
00662 X dist = X(0.);
00663 for( int i=0; i < p_nvar; i++ )
00664 dist += pow2(p_xc[i] - p_xcold[i]);
00665 dist = static_cast<X>(sqrt(dist));
00666 return ( dist <= p_toler );
00667 }
00668 return false;
00669 }
00670
00671 void optimize_phymir(realnum xc[],
00672 const realnum del[],
00673 long int nvarPhymir,
00674 chi2_type *ymin,
00675 realnum toler)
00676 {
00677 DEBUG_ENTRY( "optimize_phymir()" );
00678
00679 if( nvarPhymir > LIMPAR )
00680 {
00681 fprintf( ioQQQ, "optimize_phymir: too many parameters are varied, increase LIMPAR\n" );
00682 cdEXIT(EXIT_FAILURE);
00683 }
00684
00685 phymir_state<realnum,chi2_type,LIMPAR,STDLEN> phymir;
00686
00687
00688 (void)remove(STATEFILE_BACKUP);
00689 FILE *tmp = open_data( STATEFILE, "r", AS_LOCAL_ONLY_TRY );
00690 if( tmp != NULL )
00691 {
00692 fclose( tmp );
00693
00694 FILE *dest = open_data( STATEFILE_BACKUP, "wb", AS_LOCAL_ONLY_TRY );
00695 if( dest != NULL )
00696 {
00697 append_file( dest, STATEFILE );
00698 fclose( dest );
00699 }
00700 }
00701
00702 phymir_mode mode = optimize.lgParallel ? ( cpu.i().lgMPI() ? PHYMIR_MPI : PHYMIR_FORK ) : PHYMIR_SEQ;
00703 long nCPU = optimize.lgParallel ? ( cpu.i().lgMPI() ? cpu.i().nCPU() : optimize.useCPU ) : 1;
00704 if( optimize.lgOptCont )
00705 {
00706 phymir.continue_from_state( optimize_func, nvarPhymir, STATEFILE, toler,
00707 optimize.nIterOptim, mode, nCPU );
00708 }
00709 else
00710 {
00711 phymir.init_state_file_name( STATEFILE );
00712 phymir.init_strings( t_version::Inst().chDate, t_version::Inst().chVersion,
00713 cpu.i().host_name() );
00714 phymir.initial_run( optimize_func, nvarPhymir, xc, del, toler,
00715 optimize.nIterOptim, mode, nCPU );
00716 }
00717
00718 phymir.optimize_with_restart();
00719
00720 if( phymir.lgMaxIterExceeded() )
00721 {
00722 fprintf( ioQQQ, " Optimizer exceeding maximum iterations.\n" );
00723 fprintf( ioQQQ, " This can be reset with the OPTIMIZE ITERATIONS command.\n" );
00724 }
00725
00726
00727 optimize.nOptimiz = phymir.noptim();
00728 for( int i=0; i < nvarPhymir; i++ )
00729 {
00730 xc[i] = phymir.xval(i);
00731 optimize.varmax[i] = min(phymir.xmax(i),optimize.varang[i][1]);
00732 optimize.varmin[i] = max(phymir.xmin(i),optimize.varang[i][0]);
00733 }
00734 *ymin = phymir.yval();
00735 return;
00736 }
00737
00739 inline void wr_block(const void *ptr,
00740 size_t len,
00741 const char *fnam)
00742 {
00743 DEBUG_ENTRY( "wr_block()" );
00744
00745 FILE *fdes = open_data( fnam, "wb", AS_LOCAL_ONLY );
00746 if( fwrite(ptr,len,size_t(1),fdes) != 1 ) {
00747 printf( "error writing on file: %s\n",fnam );
00748 fclose(fdes);
00749 cdEXIT(EXIT_FAILURE);
00750 }
00751 fclose(fdes);
00752 return;
00753 }
00754
00756 inline void rd_block(void *ptr,
00757 size_t len,
00758 const char *fnam)
00759 {
00760 DEBUG_ENTRY( "rd_block()" );
00761
00762 FILE *fdes = open_data( fnam, "rb", AS_LOCAL_ONLY );
00763 if( fread(ptr,len,size_t(1),fdes) != 1 ) {
00764 printf( "error reading on file: %s\n",fnam );
00765 fclose(fdes);
00766 cdEXIT(EXIT_FAILURE);
00767 }
00768 fclose(fdes);
00769 return;
00770 }