Blockstructured Adaptive Mesh Refinement in object-oriented C++
00001 00006 #include "GridHierarchy.h" 00007 #include "IndexGridData1.h" 00008 #include "IndexGridData2.h" 00009 #include "IndexGridData3.h" 00010 00011 /*************************************************************************/ 00012 /* IO Functions */ 00013 /*************************************************************************/ 00014 DAGHIO_WriteFunc DAGHIO_Write[DAGHMaxIOTypes]; 00015 DAGHIO_ReadFunc DAGHIO_Read[DAGHMaxIOTypes]; 00016 /*************************************************************************/ 00017 00018 /*************************************************************************/ 00019 /* Error messages */ 00020 /*************************************************************************/ 00021 static char const filename[] = "GridHierarchy"; 00022 static void warn(const char msg[]) 00023 { cerr << filename << ":" << msg << "\n"; } 00024 static void abort(const char msg[]) 00025 { warn(msg); exit(-1); } 00026 /*************************************************************************/ 00027 00028 /*************************************************************************/ 00029 /* Utility macros */ 00030 /*************************************************************************/ 00031 #define power2(x) ((unsigned) 1 << (x)) 00032 00033 /*************************************************************************/ 00034 /* Constructor... */ 00035 /*************************************************************************/ 00036 GridHierarchy::GridHierarchy(const int ndim, 00037 const int type, 00038 const int max_level) 00039 : rank(ndim), basebbox(ndim,1), daghtype(type), 00040 bndrytype(DAGHDefaultBoundary), 00041 adaptbndrytype(DAGHDefaultAdaptBoundary), 00042 bndrywidth(0), extghostwidth(0), 00043 levels(max_level), maxlev(0), crslev(0), finelev(0), intbbox(ndim,1), 00044 intbaselist(0), bndrycoords(0), nbndrycoords(0), cutbbox(0), ncutbbox(0), 00045 updatedstep(DAGHCurrentTime), 00046 nestbuffer(0), cfactor(1), guwidth(0), 00047 distribution_type(DAGHDefaultDistribution), 00048 distribution(0), 00049 complist(0), locallist(0), 00050 localbboxarray(0), 00051 gfnum(0), gflist(0), 00052 io_type(0), io_write_server(0), 00053 io_read_server(0), io_end_server(0), 00054 #ifdef DAGH_IOV 00055 ServerPort(0), Server(0), 00056 #endif 00057 chkptflag(DAGHFalse), chkptpnum(0) 00058 { 00059 if (max_level<1) abort ("To few levels!"); 00060 AllocError::Init(); 00061 chkptname[0] = '\0'; 00062 DAGH_InitOverlaps(daghtype,overlap); 00063 localbboxarray = new BBoxList*[max_level]; 00064 localgbl = new GridBoxList*[max_level]; 00065 globalgbl = new GridBoxList*[max_level]; 00066 oldlocalgbl = new GridBoxList*[max_level]; 00067 oldglobalgbl = new GridBoxList*[max_level]; 00068 refby = new short[max_level]; 00069 for (register int i=0;i<max_level;i++) { 00070 localbboxarray[i] = 0; 00071 localgbl[i] = 0; globalgbl[i] = 0; 00072 oldlocalgbl[i] = 0; oldglobalgbl[i] = 0; 00073 refby[i] = DAGHDefaultRefineFactor; 00074 } 00075 if (max_level>1) refby[max_level-1] = 1; 00076 distribution = new DAGHDistribution(DAGHDefaultDistribution); 00077 if (max_level == 1) { 00078 distribution_type = (rank == 1) ? DAGHBlockXDistribution : 00079 (rank == 2) ? DAGHBlockXYDistribution : DAGHBlockAllDistribution; 00080 distribution->set_dist(distribution_type); 00081 } 00082 for (int d=0; d<rank; d++) 00083 bndryperiodic[d] = DAGHFalse; 00084 DAGH_CommInit(); 00085 curtime = (int*) 0; 00086 } 00087 00088 /*************************************************************************/ 00089 /* Destructor... */ 00090 /*************************************************************************/ 00091 GridHierarchy::~GridHierarchy(void) 00092 { 00093 register int i; 00094 00095 /* release memory */ 00096 if (intbaselist) delete intbaselist; 00097 if (bndrycoords) delete [] bndrycoords; 00098 if (cutbbox) delete [] cutbbox; 00099 if (curtime) delete [] curtime; 00100 if (distribution) delete distribution; 00101 if (complist) delete complist; 00102 if (locallist) delete locallist; 00103 00104 if (gflist) { 00105 for (i=0;i<gfnum;i++) 00106 if (gflist[i]) gflist[i] = (GridFunctionVoid *) NULL; 00107 delete [] gflist; 00108 } 00109 if (refby) delete [] refby; 00110 00111 for (i=0;i<levels;i++) { 00112 if (localbboxarray) if (localbboxarray[i]) delete localbboxarray[i]; 00113 } 00114 if(localbboxarray) delete [] localbboxarray; 00115 00116 for (i=0;i<levels;i++) { 00117 if (localgbl) if (localgbl[i]) delete localgbl[i]; 00118 if (globalgbl) if (globalgbl[i]) delete globalgbl[i]; 00119 if (oldlocalgbl) if (oldlocalgbl[i]) delete oldlocalgbl[i]; 00120 if (oldglobalgbl) if (oldglobalgbl[i]) delete oldglobalgbl[i]; 00121 } 00122 if (localgbl) delete [] localgbl; 00123 if (globalgbl) delete [] globalgbl; 00124 if (oldlocalgbl) delete [] oldlocalgbl; 00125 if (oldglobalgbl) delete [] oldglobalgbl; 00126 00127 if (io_write_server) { 00128 delete io_write_server; 00129 io_write_server = 0; 00130 } 00131 if (io_read_server) { 00132 delete io_read_server; 00133 io_read_server = 0; 00134 } 00135 if (io_end_server) { 00136 delete io_end_server; 00137 io_end_server = 0; 00138 } 00139 00140 chkptname[0] = '\0'; 00141 00142 #ifdef DAGH_IOV 00143 if (ServerPort) delete ServerPort; ServerPort = 0; 00144 if (Server) { 00145 char buf[2048]; 00146 sprintf(buf,"Q\n"); 00147 Server->write(buf,sizeof(buf)); 00148 delete Server; Server = 0; 00149 } 00150 #endif 00151 00152 /* Shut down comms */ 00153 DAGH_CommKill(); 00154 } 00155 00156 /*************************************************************************/ 00157 /* Setup the hierarchy... */ 00158 /*************************************************************************/ 00159 /* bbox[0:2*rank-1] = {xmin,xmax,ymin,ymax,zmin,zmax,...} */ 00160 /* shape[0:rank-1] = {nx,ny,nz,...} */ 00161 /* h = (max - min)/(n-1) */ 00162 void GridHierarchy::DAGH_SetBaseGrid(double const *bbox, const int *shape, 00163 const int& ncuts, const int *cuts) { 00164 if (cutbbox) delete [] cutbbox; 00165 cutbbox = (BBox*) 0; 00166 00167 ncutbbox = ncuts; 00168 if (ncutbbox>0) 00169 cutbbox = new BBox[ncutbbox]; 00170 00171 for (register int nc=0; nc<ncutbbox; nc++) 00172 cutbbox[nc] = BBox(rank,1); 00173 00174 for (register int i=0;i<rank;i++) { 00175 dspecs[i].low = bbox[2*i]; 00176 dspecs[i].high = bbox[2*i+1]; 00177 dspecs[i].n = shape[i]; 00178 dspecs[i].h = (dspecs[i].high - dspecs[i].low) / (dspecs[i].n); 00179 basebbox.lower(i) = 0; 00180 basebbox.upper(i) = shape[i]-1; 00181 for (register int nc=0; nc<ncutbbox; nc++) { 00182 cutbbox[nc].lower(i) = cuts[nc*2*rank+2*i]; 00183 cutbbox[nc].upper(i) = cuts[nc*2*rank+2*i+1]; 00184 } 00185 } 00186 } 00187 00188 void GridHierarchy::DAGH_SetTimeSpecs(double const starttime, 00189 double const stoptime, const int numtsteps) { 00190 tspecs.low = starttime; 00191 tspecs.high = stoptime; 00192 tspecs.n = numtsteps; 00193 tspecs.h = (tspecs.high - tspecs.low) / (tspecs.n-1); 00194 } 00195 00196 void GridHierarchy::DAGH_SetRefineFactor(const int rfactor) { 00197 for (register int l=0; l<levels-1; l++) 00198 refby[l] = (rfactor>DAGHDefaultRefineFactor ? rfactor : DAGHDefaultRefineFactor); 00199 } 00200 00201 void GridHierarchy::DAGH_SetRefineFactor(const int l, const int rfactor) { 00202 if (l>=0 && l<levels-1) 00203 refby[l] = (rfactor>DAGHDefaultRefineFactor ? rfactor : DAGHDefaultRefineFactor); 00204 } 00205 00206 /*************************************************************************/ 00207 /* Test for periodic boundaries */ 00208 /*************************************************************************/ 00209 static int ipow(int b, int p) 00210 { 00211 register int tmpr = 1; 00212 while (p--) tmpr *= b; 00213 return tmpr; 00214 } 00215 00216 void GridHierarchy::DAGH_PeriodicAppendTogbl(GridBoxList *gbl, GridBox* gb, const BBox& bbox, 00217 const BBox& bbtest, const int dir, const int base, 00218 const int maxlength) { 00219 BBox wholebb = growupper(refine(wholebbox(),wholebbox().stepsize()/bbtest.stepsize()),1); 00220 Coords wholebblength = wholebb.upper()-wholebb.lower(); 00221 00222 for (int d=dir; d<rank; d++) { 00223 int count = base; 00224 if (periodicboundary(d)) { 00225 count += ipow(3, periodicindex(d)); 00226 if (bbtest.lower(d)<wholebb.lower(d)) { 00227 int length = count*maxlength; 00228 BBox bbwork = bbox; 00229 bbwork.lower(d) += wholebblength(d); bbwork.upper(d) += wholebblength(d); 00230 GridBox* gbnew = gbl->add(); 00231 gbnew->SetGridBox(gb->gbOwner(), gb->gbIndex()+length, bbwork); 00232 DAGH_PeriodicAppendTogbl(gbl, gb, bbwork, bbtest, d+1, count, maxlength); 00233 } 00234 00235 count += ipow(3, periodicindex(d)); 00236 if (bbtest.upper(d)+bbtest.stepsize(d)>wholebb.upper(d)) { 00237 int length = count*maxlength; 00238 BBox bbwork = bbox; 00239 bbwork.lower(d) -= wholebblength(d); bbwork.upper(d) -= wholebblength(d); 00240 GridBox* gbnew = gbl->add(); 00241 gbnew->SetGridBox(gb->gbOwner(), gb->gbIndex()+length, bbwork); 00242 DAGH_PeriodicAppendTogbl(gbl, gb, bbwork, bbtest, d+1, count, maxlength); 00243 } 00244 } 00245 } 00246 } 00247 00248 00249 void GridHierarchy::DAGH_PeriodicBoundaries(GridBoxList *gbl, GridBoxList *agbl) 00250 { 00251 if (!gbl || gbl->isempty()) return; 00252 int d; 00253 for (d=0; d<rank; d++) 00254 periodicidx[d] = d; 00255 for (d=0; d<rank; d++) { 00256 if (!periodicboundary(d)) 00257 for (int dd=d+1; dd<rank; dd++) 00258 periodicidx[dd] -= 1; 00259 } 00260 00261 BBox wbb(coarsen(wholebbox(),gucfactor())); 00262 Coords& ws = wbb.stepsize(); 00263 const int maxlength = gbl->number(); 00264 for(register GridBox* gb = gbl->first(); gb ; gb = gbl->next()) { 00265 BBox gbtest = gb->gbBBox(); 00266 gbtest.coarsen(ws/gb->gbBBox().stepsize()); 00267 gbtest.grow(boundarywidth()); 00268 gbtest.refine(ws/gb->gbBBox().stepsize()); 00269 int count = 0; 00270 DAGH_PeriodicAppendTogbl(agbl, gb, gb->gbBBox(), gbtest, 0, count, maxlength); 00271 } 00272 } 00273 00274 /***************************************************************/ 00275 /* counts the cells in all levels the BBox includes */ 00276 /***************************************************************/ 00277 int GridHierarchy::countcells(BBox& bb, BBoxList** bbla, int count) 00278 { 00279 int factor = 1; 00280 int cells = 0; 00281 BBox tmpbb(bb); 00282 tmpbb.refine(gucfactor()); 00283 for (int l=0; l<levels; l++) { 00284 if (bbla[l]) { 00285 int cellsperlevel = 0; 00286 for (BBox* _b=bbla[l]->first(); _b!=BBoxNULL; _b=bbla[l]->next()) { 00287 BBox bb = tmpbb*(*_b); 00288 if (!bb.empty()) 00289 cellsperlevel += bb.size(); 00290 } 00291 if (count==DAGHFalse) //if count==DAGHFalse, calculate the real wl, else calc the nr. of cells 00292 cells += factor*cellsperlevel; 00293 else 00294 cells += cellsperlevel; 00295 } 00296 00297 factor *= refinefactor(l); 00298 tmpbb.refine(refinefactor(l)); 00299 } 00300 return cells; 00301 } 00302 00303 /***************************************************************/ 00304 /* create from globalbboxlist gridunits with uniform cells */ 00305 /***************************************************************/ 00306 void GridHierarchy::DAGH_CreateGridUnitList(GridUnitList*& gul, 00307 BBoxList** bbla, int count) { 00308 if (gul) gul->empty(); 00309 else gul = new GridUnitList(); 00310 00311 BBox wbb(coarsen(wholebbox(),gucfactor())); 00312 Coords& ws = wbb.stepsize(); 00313 00314 BBoxList gubbl; 00315 BBoxList others; 00316 BBox* bb; 00317 for (int l=0; l<levels; l++) { 00318 if (bbla[l]) { 00319 BBoxList bbl; 00320 for (bb=bbla[l]->first(); bb!=BBoxNULL; bb=bbla[l]->next()) { 00321 BBox bbh(coarsen(*bb,ws/bb->stepsize())); 00322 for (register int d=0; d<bb->rank; d++) { 00323 if (bbh.lower(d) < bb->lower(d)) 00324 bbh.lower(d) += ws(d); 00325 if (bbh.upper(d)+ws(d) > bb->upper(d)+bb->stepsize(d)) 00326 bbh.upper(d) -= ws(d); 00327 } 00328 bbl.add(bbh); 00329 } 00330 if (l==0) others = bbl; 00331 00332 if (l<levels-1 && bbla[l+1]) 00333 for (bb=bbla[l+1]->first(); bb!=BBoxNULL; bb=bbla[l+1]->next()) { 00334 BBox bbh(coarsen(*bb,ws/bb->stepsize())); 00335 bbl -= bbh; 00336 } 00337 00338 for (bb=bbl.first(); bb!=BBoxNULL; bb=bbl.next()) 00339 gubbl.add(*bb); 00340 } 00341 } 00342 others -= gubbl; 00343 00344 for (bb=others.first(); bb!=BBoxNULL; bb=others.next()) 00345 if (rank==1) 00346 for_1(i, *bb, ws) 00347 gubbl.add(BBox(1, i, i, ws(0))); 00348 end_for 00349 else if (rank==2) 00350 for_2(i, j, *bb, ws) 00351 gubbl.add(BBox(2, i, j, i, j, ws(0), ws(1))); 00352 end_for 00353 else if (rank==3) 00354 for_3(i, j, k, *bb, ws) 00355 gubbl.add(BBox(3, i, j, k, i, j, k, ws(0), ws(1), ws(2))); 00356 end_for 00357 00358 int mlev = 0; 00359 for (int i=0; i<rank; i++) 00360 if (mlev<((wbb.upper(i) - wbb.lower(i))/ ws(i) + 1)) 00361 mlev = (wbb.upper(i) - wbb.lower(i))/ ws(i) + 1; 00362 if (mlev>1) mlev = (int)(log((double)(mlev-1))/log((double)2.0)) + 1; 00363 else mlev = 0; 00364 00365 GridUnitList rList; 00366 GridUnit whole_GridUnit(rank, mlev, 0, mlev, mlev, 1, 0); 00367 rList.add(whole_GridUnit); //Gridunit over the whole bbox 00368 00369 for (bb=gubbl.first(); bb!=BBoxNULL; bb=gubbl.next()) { 00370 bb->lower() /= bb->stepsize(); 00371 bb->upper() /= bb->stepsize(); 00372 bb->stepsize() /= bb->stepsize(); 00373 } 00374 00375 register GridUnit *gu; 00376 for (gu=rList.first();gu;gu=rList.next()) { 00377 BBox levbb = gu->guBBox(mlev); 00378 for (bb=gubbl.first();bb;bb=gubbl.next()) { 00379 if (!bb->empty()) { 00380 BBox interestion(*bb * levbb); 00381 if (!interestion.empty() && !((*bb)>levbb) && 00382 gu->guExtent(gu->guCrsLev())>guminwidth()) { 00383 rList.decompose(); 00384 break; 00385 } 00386 } 00387 } 00388 } 00389 00390 for (gu=rList.first(); gu; gu=rList.next()) { 00391 BBox fbb = BBox((gu->guBBox()).lower()*ws,(gu->guBBox()).upper()*ws,ws); 00392 int load = countcells(fbb,bbla,count); 00393 if (load != 0) { 00394 gu->guSetWorkload(load); /*set workload*/ 00395 gul->add(*gu); 00396 } 00397 } 00398 00399 #ifdef DEBUG_PRINT_DIST 00400 ( comm_service::log() << "gubbl:" << gubbl <<"\nrList"<< *gul << endl ).flush(); 00401 #endif 00402 } 00403 00404 void GridHierarchy::DAGH_CreateBBoxList(BBoxList*& bbl, GridUnitList& gul) { 00405 if (bbl) bbl->empty(); 00406 else bbl = new BBoxList(); 00407 for(register GridUnit* gu = gul.first(); gu ; gu = gul.next()) { 00408 BBox bb = gu->guBBox(); 00409 for (register int d=0; d<bb.rank; d++) { 00410 bb.lower(d) *= gucfactor()*stepsize(crslev); 00411 bb.upper(d) *= gucfactor()*stepsize(crslev); 00412 bb.stepsize(d) *= gucfactor()*stepsize(crslev); 00413 } 00414 bbl->add(refine(bb,gucfactor())); 00415 } 00416 short olap[DAGHMaxRank]; 00417 for (int i=0;i<DAGHMaxRank;i++) olap[i]=0; 00418 bbl->mergeboxes(olap); 00419 } 00420 00421 /*************************************************************************/ 00422 /* Compose the hierarchy... */ 00423 /*************************************************************************/ 00424 void GridHierarchy::DAGH_ComposeHierarchy(void) { 00425 AllocError::SetTexts("GridHierarchy","DAGH_ComposeHierarchy()"); 00426 00427 const int me = comm_service::proc_me(); 00428 const int num = comm_service::proc_num(); 00429 const int wnum = comm_service::proc_world(); 00430 const int io_on = comm_service::io_enabled(); 00431 const int pio = comm_service::proc_io(); 00432 register int i; 00433 00434 maxlev = levels-1; 00435 for (i=0;i<rank;i++) { 00436 dspecs[i].nfine = dspecs[i].n*refinedby(maxlev); 00437 dspecs[i].hfine = dspecs[i].high/(1.0*dspecs[i].nfine) - 00438 dspecs[i].low/(1.0*dspecs[i].nfine); 00439 } 00440 00441 if (levels > 1) { 00442 BBox wholebox(rank,basebbox.lower(),basebbox.upper(),stepsize(crslev)); 00443 wholebox.lower() *= stepsize(crslev); 00444 wholebox.upper() *= stepsize(crslev); 00445 intbbox = wholebox; 00446 } 00447 else 00448 intbbox = basebbox; 00449 00450 nbndrycoords = ncutbbox+1; 00451 bndrycoords = new double[nbndrycoords*2*rank]; 00452 DCoords lbc(worldCoords(wholebbox().lower(),wholebbox().stepsize())); 00453 DCoords ubc(worldCoords(wholebbox().upper()+wholebbox().stepsize(), 00454 wholebbox().stepsize())); 00455 for (register int d=0; d<rank; d++) { 00456 bndrycoords[nbndrycoords*(0+2*d)] = lbc(d); 00457 bndrycoords[nbndrycoords*(1+2*d)] = ubc(d); 00458 } 00459 intbbox.growupperbydim(daghoverlap()); 00460 00461 BBoxList** globalbboxlist = new BBoxList*[levels]; 00462 for (i=1;i<levels;i++) 00463 globalbboxlist[i] = (BBoxList*) 0; 00464 intbaselist = new BBoxList(); 00465 intbaselist->add(wholebbox()); 00466 00467 for (register int nc=0; nc<ncutbbox; nc++) { 00468 cutbbox[nc] = BBox(rank,cutbbox[nc].lower()*wholebbox().stepsize(), 00469 cutbbox[nc].upper()*wholebbox().stepsize(), 00470 wholebbox().stepsize()); 00471 DCoords lbc(worldCoords(cutbbox[nc].lower(),cutbbox[nc].stepsize())); 00472 DCoords ubc(worldCoords(cutbbox[nc].upper()+cutbbox[nc].stepsize(), 00473 cutbbox[nc].stepsize())); 00474 for (register int d=0; d<rank; d++) { 00475 bndrycoords[(nc+1)+nbndrycoords*(0+2*d)] = lbc(d); 00476 bndrycoords[(nc+1)+nbndrycoords*(1+2*d)] = ubc(d); 00477 } 00478 cutbbox[nc].growupperbydim(daghoverlap()); 00479 *intbaselist -= cutbbox[nc]; 00480 } 00481 intbaselist->mergeboxes(daghoverlap()); 00482 globalbboxlist[0] = intbaselist; 00483 00484 /* Current Time Array */ 00485 curtime = new int[levels]; 00486 for (i=0;i<levels;i++) 00487 curtime[i] = 0; 00488 00489 /* Create the GridUnitList */ 00490 DAGH_CreateGridUnitList(complist, globalbboxlist); 00491 00492 BBoxList *localbbl = (BBoxList *) 0; 00493 if (num > 1) { 00494 locallist = new GridUnitList; 00495 /* Partition the composite list & get local information */ 00496 distribution->partition(complist,locallist,num,me,guminwidth(),daghoverlap()); 00497 DAGH_CreateBBoxList(localbbl, *locallist); 00498 } 00499 else { 00500 locallist = new GridUnitList(*complist); 00501 localbbl = new BBoxList(); 00502 *localbbl = (*intbaselist); 00503 } 00504 00505 #ifdef DEBUG_PRINT_GH 00506 (comm_service::log() << "Setting up Servers finished" << endl).flush(); 00507 #endif 00508 if (io_on && wnum > 1 && me == pio) { 00509 io_write_server = new DAGHIOServerRcv((DAGHIOTag|DAGHIOWriteReqTag), 00510 *this,DAGHIO_Write[io_type]); 00511 io_read_server = new DAGHIOServerSnd((DAGHIOTag|DAGHIOReadReqTag), 00512 *this,DAGHIO_Read[io_type]); 00513 io_end_server = new DAGHIOServerPing((DAGHIOTag|DAGHIOEndReqTag), 00514 *this,&DAGHIO_EndIOPingFunction); 00515 } 00516 #ifdef DEBUG_PRINT_GH 00517 (comm_service::log() << "Setting up Servers finished" << endl).flush(); 00518 #endif 00519 00520 #ifdef DEBUG_PRINT_GH 00521 (comm_service::log() << "GridHierarchy::DAGH_ComposeHierarchy" << " " 00522 << comm_service::proc_me() << " " 00523 << "BaseBBox: " << basebbox << " " 00524 << endl).flush(); 00525 00526 (comm_service::log() << "\n************* Composite List *************\n" 00527 << *complist 00528 << "\n************* Local List *************\n" 00529 << *locallist 00530 << "\n************* ***************** *************\n" 00531 ).flush(); 00532 #endif 00533 00534 short olap[DAGHMaxRank]; 00535 DAGH_InitOverlaps(daghtype,olap); 00536 #ifdef DEBUG_PRINT_GH 00537 ( comm_service::log() << "\n************* NLists ************\n" ).flush(); 00538 #endif 00539 int rl = 0; 00540 localgbl[rl] = new GridBoxList(); 00541 BBoxList bbl = (*globalbboxlist[rl]); 00542 bbl *= (*localbbl); 00543 if (!bbl.isempty()) { 00544 bbl.mergeboxes(olap); 00545 for (BBox *_b = bbl.first();_b;_b=bbl.next()) 00546 localgbl[rl]->add(GridBox(me,localgbl[rl]->number(),*_b)); 00547 } 00548 delete localbbl; 00549 00550 GridBoxList* sendgbl = new GridBoxList(*localgbl[rl]); 00551 DAGH_PeriodicBoundaries(localgbl[rl], sendgbl); 00552 00553 if (wnum == 1) { 00554 globalgbl[rl] = new GridBoxList(*sendgbl); 00555 } 00556 else { 00557 int sndsize=0, rcvsize=0; 00558 void *sndbuf = (sendgbl) ? sendgbl->pack(sndsize) : 0; 00559 void *rcvbuf = 0; 00560 DAGH_GlbConcat(sndbuf, sndsize, rcvbuf, rcvsize); 00561 globalgbl[rl] = new GridBoxList(rcvbuf, rcvsize, num); 00562 if (rcvbuf) delete [] (char*) rcvbuf; 00563 } 00564 if (sendgbl) { 00565 sendgbl->empty(); 00566 delete sendgbl; 00567 } 00568 delete [] globalbboxlist; 00569 #ifdef DEBUG_PRINT_GH 00570 ( comm_service::log() << "localgbl L" << rl << ": " << *localgbl[rl] << "\n" ).flush(); 00571 ( comm_service::log() << "globalgbl L" << rl << ": " << *globalgbl[rl] << "\n" ).flush(); 00572 ( comm_service::log() << "\n************* **************** ************\n" ).flush(); 00573 #endif 00574 00575 if (io_on && wnum > 1 && me == pio) { 00576 DAGH_IOServe(); 00577 } 00578 } 00579 00580 /*************************************************************************/ 00581 /* Compose the hierarchy using a check point file ...... */ 00582 /*************************************************************************/ 00583 void GridHierarchy::DAGH_ComposeHierarchy(const char* name) 00584 { 00585 // AllocError::SetTexts("GridHierarchy", 00586 // "DAGH_ComposeHierarchy(const char* name)"); 00587 00588 // const int me = comm_service::proc_me(); 00589 // const int num = comm_service::proc_num(); 00590 // const int wnum = comm_service::proc_world(); 00591 // const int io_on = comm_service::io_enabled(); 00592 // const int pio = comm_service::proc_io(); 00593 // GridBoxList* sendgbl = (GridBoxList*) 0; 00594 00595 // int eflag = DAGHFalse; 00596 // int rdflag = DAGHFalse; 00597 00598 // /* Start checkpointing */ 00599 // DAGH_InitChkpt(name); 00600 // streampos* chkptdir = 0; 00601 // char* chkptnamedir = 0; 00602 // ifstream ifs; 00603 // eflag = DAGH_OpenChkptIStream(me, chkptdir, chkptnamedir, ifs); 00604 00605 // /* If my file does not exist open Proc 0 file */ 00606 // if (eflag != DAGHTrue) 00607 // eflag = DAGH_OpenChkptIStream(0, chkptdir, chkptnamedir, ifs); 00608 // else 00609 // rdflag = DAGHTrue; 00610 00611 // assert (eflag == DAGHTrue); 00612 00613 // /* Read information from the checkpoint file */ 00614 // ifs >> *this; 00615 00616 // /* Close chkpt stream and delete associated data */ 00617 // DAGH_CloseChkptIStream(chkptdir, chkptnamedir, ifs); 00618 00619 // /* New Distribution or I am the IO server */ 00620 // if (chkptpnum != num || (io_on && wnum > 1 && me == pio)) { 00621 00622 // if (oldlocalgbl) delete oldlocalgbl; 00623 // oldlocalgbl = 0; 00624 // if (oldglobalgbl) delete oldglobalgbl; 00625 // oldglobalgbl = 0; 00626 00627 // if (me != pio || wnum == 1) { /* Not IO processor */ 00628 00629 // /* if its a new distribution then the GF's will need oldglobalgbl */ 00630 // oldglobalgbl = new GridBoxList(*globalgbl); 00631 00632 // if (num == 1) { 00633 // if (locallist) delete locallist; locallist = 0; 00634 // locallist = complist; 00635 // if (localgbl) delete localgbl; 00636 // if (globalgbl) delete globalgbl; 00637 // localgbl = new GridBoxList; 00638 // globalgbl = new GridBoxList; 00639 // if (levels == 1) DAGH_MergeGridUnits(); 00640 // else if (!locallist->isempty()) { 00641 // DAGH_InitBBoxArray(); 00642 // DAGH_MergeGridUnits(); 00643 // } 00644 // if (localgbl) { 00645 // // sendgbl = new GridBoxList(*localgbl); 00646 // // DAGH_PeriodicBoundaries(localgbl, sendgbl); 00647 // } 00648 // globalgbl = new GridBoxList(*sendgbl); 00649 // globalgbl->setowner(me); 00650 // globalgbl->setindex(); 00651 // } 00652 // } 00653 // else if (me == pio && wnum > 1) { /* IO Processor */ 00654 // if (locallist) delete locallist; locallist = 0; 00655 // if (localgbl) delete localgbl; localgbl = 0; 00656 // } 00657 00658 // /* Partition the composite list & get local information */ 00659 // if (num > 1) { 00660 // if (levels == 1) { 00661 // if (!localbboxarray[0]) 00662 // localbboxarray[0] = new BBoxList; 00663 // else if (!localbboxarray[0]->isempty()) 00664 // localbboxarray[0]->empty(); 00665 // BBox* mybbox = localbboxarray[0]->add(); 00666 // distribution->partition(wholebbox(),*mybbox,num,me); 00667 // } 00668 // else 00669 // distribution->partition(complist,locallist,num,me,guminwidth(),daghoverlap()); 00670 // 00671 // if (me != pio || wnum == 1) { /* Not IO processor */ 00672 // if (levels == 1) DAGH_MergeGridUnits(); 00673 // else if (!locallist->isempty()) { 00674 // DAGH_InitBBoxArray(); 00675 // DAGH_MergeGridUnits(); 00676 // } 00677 // else { 00678 // if (!localgbl->isempty()) localgbl->empty(); 00679 // } 00680 // } 00681 // } 00682 // } 00683 // else if (rdflag == DAGHFalse) { /* Same Distribution */ 00684 // eflag = DAGH_OpenChkptIStream(me, chkptdir, chkptnamedir, ifs); 00685 // assert (eflag == DAGHTrue); 00686 00687 // /* Read information from the checkpoint file */ 00688 // ifs >> *this; 00689 00690 // /* Close chkpt stream and delete associated data */ 00691 // DAGH_CloseChkptIStream(chkptdir, chkptnamedir, ifs); 00692 00693 // if (oldlocalgbl) delete oldlocalgbl; 00694 // oldlocalgbl = 0; 00695 // if (oldglobalgbl) delete oldglobalgbl; 00696 // oldglobalgbl = 0; 00697 // } 00698 00699 // if (io_on && wnum > 1 && me == pio) { 00700 // io_write_server = new DAGHIOServerRcv((DAGHIOTag|DAGHIOWriteReqTag), 00701 // *this,DAGHIO_Write[io_type]); 00702 // io_read_server = new DAGHIOServerSnd((DAGHIOTag|DAGHIOReadReqTag), 00703 // *this,DAGHIO_Read[io_type]); 00704 // io_end_server = new DAGHIOServerPing((DAGHIOTag|DAGHIOEndReqTag), 00705 // *this,&DAGHIO_EndIOPingFunction); 00706 // } 00707 00708 // if (wnum > 1 && (io_on || chkptpnum != num)) { 00709 // // Since IO node is also executing this I don't need a ping 00710 // // if (localgbl) { 00711 // // sendgbl = new GridBoxList(*localgbl); 00712 // // DAGH_PeriodicBoundaries(localgbl, sendgbl); 00713 // // } 00714 00715 // int sndsize=0, rcvsize=0; 00716 // void *sndbuf = (sendgbl) ? sendgbl->pack(sndsize) : 0; 00717 // void *rcvbuf = 0; 00718 // DAGH_GlbConcat(sndbuf, sndsize, rcvbuf, rcvsize); 00719 // if (globalgbl) delete globalgbl; 00720 // globalgbl = new GridBoxList(rcvbuf, rcvsize, num); 00721 // if (rcvbuf) delete [] (char*) rcvbuf; 00722 // } 00723 00724 // #ifdef DEBUG_PRINT_GH 00725 // (comm_service::log() << "GridHierarchy::DAGH_ComposeHierarchy" << " " 00726 // << comm_service::proc_me() << " " 00727 // << "BaseBBox: " << basebbox << " " 00728 // << endl).flush(); 00729 00730 // (comm_service::log() << "\n************* Composite List *************\n" 00731 // << *complist 00732 // << "\n************* Local List *************\n" 00733 // << *locallist 00734 // << "\n************* Global GBL *************\n" 00735 // << *globalgbl 00736 // << "\n************* Local GBL *************\n" 00737 // << *localgbl 00738 // << "\n************* ***************** *************\n" 00739 // ).flush(); 00740 // #endif 00741 00742 // if (io_on && wnum > 1 && me == pio) { 00743 // DAGH_IOServe(); 00744 // } 00745 00746 // if (sendgbl) delete sendgbl; 00747 } 00748 00749 /***************************************************************/ 00750 /* GridFunction Information/Operations */ 00751 /***************************************************************/ 00752 #ifndef GFListIncrement 00753 #define GFListIncrement (64) 00754 #endif 00755 00756 int GridHierarchy::DAGH_AddGridFunction(GridFunctionVoid *gfv) 00757 { 00758 if (comm_service::dce()) 00759 assert (comm_service::num_comm() == gfnum); 00760 00761 if (!gflist) { 00762 gflist = new GridFunctionVoid *[GFListIncrement]; 00763 for (register int i=0;i<GFListIncrement;i++) { 00764 gflist[i] = (GridFunctionVoid *) NULL; 00765 } 00766 if (comm_service::dce()) 00767 comm_service::inc_commarray(GFListIncrement); 00768 } 00769 00770 register int idx = gfnum; 00771 while (gflist[idx] != (GridFunctionVoid *) NULL) idx--; 00772 gflist[idx] = gfv; 00773 if (comm_service::dce()) 00774 comm_service::add_comm(idx); 00775 gfnum++; 00776 00777 if (gfnum%GFListIncrement == 0) { 00778 GridFunctionVoid **ogflist = gflist; 00779 gflist = new GridFunctionVoid *[gfnum+GFListIncrement]; 00780 register int i; 00781 for (i=0;i<gfnum;i++) { 00782 gflist[i] = ogflist[i]; 00783 ogflist[i] = (GridFunctionVoid *) NULL; 00784 } 00785 for (i=gfnum;i<gfnum+GFListIncrement;i++) 00786 gflist[i] = (GridFunctionVoid *) NULL; 00787 00788 delete [] ogflist; 00789 00790 if (comm_service::dce()) 00791 comm_service::inc_commarray(GFListIncrement); 00792 } 00793 return (idx); 00794 } 00795 00796 /***************************************************************/ 00797 /* Recompose the hierarchy */ 00798 /***************************************************************/ 00799 void GridHierarchy::DAGH_RecomposeHierarchy(int Partition) 00800 { 00801 AllocError::SetTexts("GridHierarchy","DAGH_RecomposeHierarchy()"); 00802 00803 #ifdef DEBUG_PROFILE 00804 ( cout << "\nDAGH_RecomposeHierarchy()\n" ).flush(); 00805 #endif 00806 const int me = comm_service::proc_me(); 00807 const int num = comm_service::proc_num(); 00808 const int wnum = comm_service::proc_world(); 00809 00810 if (chkpt_restart()) DAGH_StopChkpt(); 00811 00812 register int rl; 00813 BBoxList* globaltmp = 0; 00814 BBoxList** globalbboxarray = new BBoxList*[levels]; 00815 for (rl=0;rl<levels-1;rl++) { 00816 if (globaltmp) delete globaltmp; 00817 if (wnum == 1) { 00818 globaltmp = new BBoxList(); 00819 if (localbboxarray[rl]) *globaltmp = *localbboxarray[rl]; 00820 } 00821 else { 00822 if (!localbboxarray[rl]) localbboxarray[rl] = new BBoxList(); 00823 int sndsize=0, rcvsize=0; 00824 void *sndbuf = (localbboxarray[rl]) ? localbboxarray[rl]->pack(sndsize) : 0; 00825 void *rcvbuf = 0; 00826 DAGH_GlbConcat(sndbuf, sndsize, rcvbuf, rcvsize, comm_service::comm()); 00827 globaltmp = new BBoxList(rcvbuf, rcvsize, num); 00828 if (rcvbuf) delete [] (char*) rcvbuf; 00829 } 00830 globalbboxarray[rl] = new BBoxList(); 00831 for (BBox *bb=globaltmp->first();bb;bb=globaltmp->next()) 00832 if (!bb->empty()) globalbboxarray[rl]->add(*bb); 00833 } 00834 globalbboxarray[levels-1] = (BBoxList*) 0; 00835 if (globaltmp) delete globaltmp; 00836 00837 /* Ensure proper nesting */ 00838 for (rl=1;rl<levels-1;rl++) 00839 if (globalbboxarray[rl-1] && globalbboxarray[rl]) { 00840 BBoxList bbl; 00841 for (BBox *bbi=intbaselist->first();bbi;bbi=intbaselist->next()) 00842 bbl.add(refine(*bbi,refinedby(rl-1))); 00843 bbl -= (*globalbboxarray[rl-1]); 00844 for (BBox *bb=bbl.first();bb;bb=bbl.next()) { 00845 bb->refine(refinefactor(rl-1)); 00846 bb->grow(buffer()); 00847 } 00848 (*globalbboxarray[rl]) -= bbl; 00849 if (localbboxarray[rl]) 00850 (*localbboxarray[rl]) *= (*globalbboxarray[rl]); 00851 } 00852 00853 for (rl=0;rl<levels;rl++) { 00854 #ifdef DEBUG_PRINT_RG 00855 if (globalbboxarray[rl]) 00856 ( comm_service::log() << "globalbboxarray L" << rl << ": " 00857 << *globalbboxarray[rl] << "\n" ).flush(); 00858 #endif 00859 if (oldglobalgbl[rl]) { 00860 oldglobalgbl[rl]->empty(); delete oldglobalgbl[rl]; 00861 } 00862 oldglobalgbl[rl] = globalgbl[rl]; globalgbl[rl] = 0; 00863 if (oldlocalgbl[rl]) { 00864 oldlocalgbl[rl]->empty(); delete oldlocalgbl[rl]; 00865 } 00866 oldlocalgbl[rl] = localgbl[rl]; localgbl[rl] = 0; 00867 } 00868 00869 short olap[DAGHMaxRank]; 00870 DAGH_InitOverlaps(daghtype,olap); 00871 00872 BBoxList** globalbboxlist = new BBoxList*[levels]; 00873 globalbboxlist[0] = intbaselist; 00874 for (rl = 0; rl<levels-1; rl++) 00875 if (globalbboxarray[rl]) { 00876 if (!globalbboxarray[rl]->isempty()) finelev = rl+1; 00877 globalbboxlist[rl+1] = new BBoxList(); 00878 for (BBox *bb=globalbboxarray[rl]->first();bb; 00879 bb=globalbboxarray[rl]->next()) 00880 globalbboxlist[rl+1]->add(refine(*bb,refinefactor(rl))); 00881 } 00882 else globalbboxlist[rl+1] = 0; 00883 00884 BBoxList *localbbl = (BBoxList *) 0; 00885 if (num > 1) { 00886 if (Partition) { 00887 /* Create the GridUnitList */ 00888 DAGH_CreateGridUnitList(complist, globalbboxlist); 00889 00890 /* Repartition the composite list & get local information */ 00891 distribution->partition(complist,locallist,num,me,guminwidth(),daghoverlap()); 00892 #ifdef DEBUG_PRINT_RG 00893 ( comm_service::log() << "\n*********** New Composite List ***********\n" 00894 << *complist 00895 << "\n*********** ****************** ***********\n" 00896 ).flush(); 00897 ( comm_service::log() << "\n*********** New Local List ***********\n" 00898 << *locallist 00899 << "\n*********** ************** ***********\n" 00900 ).flush(); 00901 #endif 00902 } 00903 DAGH_CreateBBoxList(localbbl, *locallist); 00904 } 00905 else { 00906 localbbl = new BBoxList(); 00907 *localbbl = (*intbaselist); 00908 } 00909 00910 #ifdef DEBUG_PRINT_RG 00911 ( comm_service::log() << "\n************* NLists ************\n" ).flush(); 00912 #endif 00913 for (rl=0;rl<levels;rl++) { 00914 if (rl>0) 00915 for (BBox *bb=localbbl->first();bb;bb=localbbl->next()) 00916 bb->refine(refinefactor(rl-1)); 00917 if (globalbboxlist[rl]) { 00918 if (!localgbl[rl]) localgbl[rl] = new GridBoxList(); 00919 else localgbl[rl]->empty(); 00920 BBoxList bbl = (*globalbboxlist[rl]); 00921 bbl *= (*localbbl); 00922 if (!bbl.isempty()) { 00923 bbl.mergeboxes(olap); 00924 for (BBox *_b = bbl.first();_b;_b=bbl.next()) 00925 localgbl[rl]->add(GridBox(me,localgbl[rl]->number(),*_b)); 00926 } 00927 GridBoxList* sendgbl = new GridBoxList(*localgbl[rl]); 00928 DAGH_PeriodicBoundaries(localgbl[rl], sendgbl); 00929 00930 if (globalgbl[rl]) { 00931 globalgbl[rl]->empty(); 00932 delete globalgbl[rl]; 00933 } 00934 if (wnum == 1) { 00935 globalgbl[rl] = new GridBoxList(*sendgbl); 00936 } 00937 else { 00938 int sndsize=0, rcvsize=0; 00939 void *sndbuf = (sendgbl) ? sendgbl->pack(sndsize) : 0; 00940 void *rcvbuf = 0; 00941 DAGH_GlbConcat(sndbuf, sndsize, rcvbuf, rcvsize, comm_service::comm()); 00942 globalgbl[rl] = new GridBoxList(rcvbuf, rcvsize, num); 00943 if (rcvbuf) delete [] (char*) rcvbuf; 00944 } 00945 if (sendgbl) { 00946 sendgbl->empty(); 00947 delete sendgbl; 00948 } 00949 #ifdef DEBUG_PRINT_RG 00950 ( comm_service::log() << "localgbl L" << rl << ": " << *localgbl[rl] << "\n" ).flush(); 00951 ( comm_service::log() << "globalgbl L" << rl << ": " << *globalgbl[rl] << "\n" ).flush(); 00952 ( comm_service::log() << "globallist L" << rl << ": " << *globalbboxlist[rl] << "\n" ).flush(); 00953 #endif 00954 } 00955 } 00956 delete localbbl; 00957 00958 #ifdef DEBUG_PRINT_RG 00959 ( comm_service::log() << "\n************* **************** ************\n" ).flush(); 00960 ( comm_service::log() << "\n************* NOSLists ************\n" ).flush(); 00961 #endif 00962 GridBoxList** rgbl = new GridBoxList*[levels]; 00963 GridBoxList** sgbl = new GridBoxList*[levels]; 00964 GridBoxList** ogbl = new GridBoxList*[levels]; 00965 for (rl=0;rl<levels;rl++) { 00966 if (globalgbl[rl]) { 00967 rgbl[rl] = new GridBoxList(); 00968 sgbl[rl] = new GridBoxList(); 00969 ogbl[rl] = new GridBoxList(); 00970 if (comm_service::dce() && comm_service::proc_num() > 1) { 00971 register GridBox* gb; 00972 if (globalgbl[rl]) { 00973 for(gb = globalgbl[rl]->first(); gb ; gb = globalgbl[rl]->next()) { 00974 BBox work = growupper(wholebbox(), 1); 00975 work.setstepsize(gb->gbBBox().stepsize()); work.growupper(-1); 00976 work *= gb->gbBBox(); 00977 if (work == gb->gbBBox()) 00978 sgbl[rl]->add(*gb); 00979 } 00980 if (oldlocalgbl[rl]) { 00981 if (localgbl[rl]) 00982 *sgbl[rl] -= *localgbl[rl]; 00983 *sgbl[rl] *= *oldlocalgbl[rl]; 00984 } 00985 else sgbl[rl]->empty(); 00986 } 00987 if (oldglobalgbl[rl]) { 00988 for(gb = oldglobalgbl[rl]->first(); gb ; gb = oldglobalgbl[rl]->next()) { 00989 BBox work = growupper(wholebbox(), 1); 00990 work.setstepsize(gb->gbBBox().stepsize()); work.growupper(-1); 00991 work *= gb->gbBBox(); 00992 if (work == gb->gbBBox()) 00993 rgbl[rl]->add(*gb); 00994 } 00995 if (localgbl[rl]) { 00996 if (oldlocalgbl[rl]) 00997 *rgbl[rl] -= *oldlocalgbl[rl]; 00998 *rgbl[rl] *= *localgbl[rl]; 00999 } 01000 else rgbl[rl]->empty(); 01001 } 01002 } 01003 if (oldlocalgbl[rl] && localgbl[rl]) { 01004 *ogbl[rl] = *oldlocalgbl[rl]; 01005 *ogbl[rl] *= *localgbl[rl]; 01006 } 01007 #ifdef DEBUG_PRINT_RG 01008 ( comm_service::log() << "sgbl L" << rl << ": " << *sgbl[rl] << "\n" ).flush(); 01009 ( comm_service::log() << "rgbl L" << rl << ": " << *rgbl[rl] << "\n" ).flush(); 01010 ( comm_service::log() << "ogbl L" << rl << ": " << *ogbl[rl] << "\n" ).flush(); 01011 #endif 01012 } 01013 else { 01014 rgbl[rl] = 0; sgbl[rl] = 0; ogbl[rl] = 0; 01015 } 01016 } 01017 #ifdef DEBUG_PRINT_RG 01018 ( comm_service::log() << "\n************* **************** ************\n" ).flush(); 01019 #endif 01020 01021 register GridBox *ogb, *gb; 01022 int *unchanged = new int[levels]; 01023 for (rl=0; rl<levels; rl++) { 01024 unchanged[rl] = 0; 01025 if (rgbl[rl]) if (!rgbl[rl]->isempty()) continue; 01026 if (sgbl[rl]) if (!sgbl[rl]->isempty()) continue; 01027 if (localgbl[rl] && oldlocalgbl[rl]) 01028 if (localgbl[rl]->number()==oldlocalgbl[rl]->number()) { 01029 for (gb=localgbl[rl]->first(),ogb=oldlocalgbl[rl]->first(); gb && ogb; 01030 gb=localgbl[rl]->next(),ogb=oldlocalgbl[rl]->next() ) 01031 if ((*gb)!=(*ogb)) break; 01032 if (gb || ogb) continue; 01033 } 01034 if (globalgbl[rl] && oldglobalgbl[rl]) 01035 if (globalgbl[rl]->number()==oldglobalgbl[rl]->number()) { 01036 for (gb=globalgbl[rl]->first(),ogb=oldglobalgbl[rl]->first(); gb && ogb; 01037 gb=globalgbl[rl]->next(),ogb=oldglobalgbl[rl]->next() ) 01038 if ((*gb)!=(*ogb)) break; 01039 if (!(gb && ogb)) unchanged[rl] = 1; 01040 } 01041 } 01042 int *reuse = new int[levels]; 01043 for (rl=0; rl<levels; rl++) { 01044 reuse[rl] = 0; 01045 if (!unchanged[rl]) continue; 01046 if (rl>0) if (!unchanged[rl-1]) continue; 01047 if (rl<levels-1) if (!unchanged[rl+1]) continue; 01048 reuse[rl] = 1; 01049 } 01050 delete [] unchanged; 01051 01052 register int i; 01053 for (i=0; i<gfnum; i++) if (gflist[i]) { 01054 #ifdef DEBUG_PROFILE 01055 ( cout << me << ": --- GridFunction " << i ).flush(); 01056 #endif 01057 gflist[i]->GF_Recompose(reuse, oldlocalgbl, rgbl, sgbl, ogbl); 01058 #ifdef DEBUG_PROFILE 01059 ( cout << " " << me << ": done ---\n" ).flush(); 01060 #endif 01061 } 01062 for (i=0; i<gfnum; i++) if (gflist[i]) { 01063 gflist[i]->GF_FreeTmpStorage(); 01064 } 01065 01066 for (rl = 0; rl<levels; rl++) { 01067 if (globalbboxlist[rl] && rl>0) delete globalbboxlist[rl]; 01068 if (globalbboxarray[rl]) delete globalbboxarray[rl]; 01069 01070 if (rgbl[rl]) delete rgbl[rl]; 01071 if (sgbl[rl]) delete sgbl[rl]; 01072 if (ogbl[rl]) delete ogbl[rl]; 01073 } 01074 delete [] rgbl; delete [] sgbl; delete [] ogbl; 01075 delete [] globalbboxlist; 01076 delete [] globalbboxarray; 01077 delete [] reuse; 01078 01079 #ifdef DEBUG_PROFILE 01080 ( cout << "\nDAGH_RecomposeHierarchy().done\n" ).flush(); 01081 #endif 01082 } 01083 01084 /***************************************************************/ 01085 /* Recompose the hierarchy from a checkpoint file */ 01086 /***************************************************************/ 01087 void GridHierarchy::DAGH_RecomposeHierarchy(const char* name) 01088 { 01089 AllocError::SetTexts("GridHierarchy", 01090 "DAGH_RecomposeHierarchy(const char* name)"); 01091 01092 const int me = comm_service::proc_me(); 01093 const int num = comm_service::proc_num(); 01094 const int wnum = comm_service::proc_world(); 01095 01096 if (chkpt_restart()) DAGH_StopChkpt(); 01097 01098 /* Delete old storage */ 01099 register int rl; 01100 for (rl=0;rl<levels;rl++) { 01101 if (oldglobalgbl[rl]) delete oldglobalgbl[rl]; 01102 oldglobalgbl[rl] = 0; 01103 if (oldlocalgbl[rl]) delete oldlocalgbl[rl]; 01104 oldlocalgbl[rl] = 0; 01105 } 01106 01107 /* Start checkpointing */ 01108 DAGH_InitChkpt(name); 01109 streampos* chkptdir = 0; 01110 char* chkptnamedir = 0; 01111 ifstream ifs; 01112 int eflag = DAGH_OpenChkptIStream(me, chkptdir, chkptnamedir, ifs); 01113 int* lasttime = new int[levels]; 01114 for (rl=0;rl<levels;rl++) 01115 if (rl<=finelevel()) lasttime[rl]=curtime[rl]; 01116 else lasttime[rl]=-1; 01117 01118 if (eflag == DAGHTrue && chkptpnum == num) { 01119 /* Read information from the checkpoint file */ 01120 ifs >> *this; 01121 01122 /* Close chkpt stream and delete associated data */ 01123 DAGH_CloseChkptIStream(ifs); 01124 01125 int reset_comm = DAGHFalse; 01126 for (rl=0;rl<levels;rl++) 01127 if (rl<=finelevel() && lasttime[rl]==curtime[rl]) 01128 reset_comm = DAGHTrue; 01129 01130 register int i; 01131 for (i=0; i<gfnum; i++) if (gflist[i]) { 01132 #ifdef DEBUG_PRINT_RG 01133 ( comm_service::log() << "Recomposing GF: " << i << "\n" ).flush(); 01134 #endif 01135 if (comm_service::dce() && reset_comm) comm_service::reset_comm(gflist[i]->gfid); 01136 gflist[i]->GF_CheckpointRecompose(); 01137 } 01138 } 01139 else { 01140 DAGH_CloseChkptIStream(chkptdir, chkptnamedir, ifs); 01141 eflag = DAGH_OpenChkptIStream(0, chkptdir, chkptnamedir, ifs); 01142 /* Read information from the first checkpoint file */ 01143 if (eflag == DAGHTrue) { 01144 ifs >> *this; 01145 01146 int reset_comm = DAGHFalse; 01147 for (rl=0;rl<levels;rl++) 01148 if (rl<=finelevel() && lasttime[rl]==curtime[rl]) 01149 reset_comm = DAGHTrue; 01150 01151 DAGH_CloseChkptIStream(chkptdir, chkptnamedir, ifs); 01152 01153 BBoxList** globalbboxlist = new BBoxList*[levels]; 01154 for (rl = 0; rl<levels; rl++) 01155 if (globalgbl[rl]) { 01156 globalbboxlist[rl] = new BBoxList(); 01157 for (GridBox *_gb = globalgbl[rl]->first();_gb;_gb=globalgbl[rl]->next()) { 01158 BBox bb(_gb->gbBBox()); 01159 bb *= refine(wholebbox(),wholebbox().stepsize()/bb.stepsize()); 01160 if (!bb.empty()) globalbboxlist[rl]->add(bb); 01161 } 01162 } 01163 else 01164 globalbboxlist[rl] = 0; 01165 01166 BBoxList *localbbl = (BBoxList *) 0; 01167 DAGH_CreateGridUnitList(complist, globalbboxlist); 01168 if (num > 1) { 01169 distribution->partition(complist,locallist,num,me,guminwidth(),daghoverlap()); 01170 DAGH_CreateBBoxList(localbbl, *locallist); 01171 } 01172 else { 01173 if (locallist) locallist->empty(); 01174 else locallist = new GridUnitList(); 01175 *locallist = *complist; 01176 localbbl = new BBoxList(); 01177 *localbbl = (*intbaselist); 01178 } 01179 01180 for (rl=0;rl<levels;rl++) { 01181 if (globalbboxlist[rl]) delete globalbboxlist[rl]; 01182 if (oldglobalgbl[rl]) { 01183 oldglobalgbl[rl]->empty(); delete oldglobalgbl[rl]; 01184 } 01185 oldglobalgbl[rl] = globalgbl[rl]; globalgbl[rl] = 0; 01186 if (oldlocalgbl[rl]) { 01187 oldlocalgbl[rl]->empty(); delete oldlocalgbl[rl]; 01188 } 01189 oldlocalgbl[rl] = localgbl[rl]; localgbl[rl] = 0; 01190 } 01191 delete globalbboxlist; 01192 01193 short olap[DAGHMaxRank]; 01194 DAGH_InitOverlaps(daghtype,olap); 01195 01196 for (rl=0;rl<levels;rl++) { 01197 if (rl>0) 01198 for (BBox *bb=localbbl->first();bb;bb=localbbl->next()) 01199 bb->refine(refinefactor(rl-1)); 01200 if (oldglobalgbl[rl]) { 01201 if (!localgbl[rl]) localgbl[rl] = new GridBoxList(); 01202 else localgbl[rl]->empty(); 01203 BBoxList bbl; 01204 for (GridBox *_gb = oldglobalgbl[rl]->first();_gb;_gb=oldglobalgbl[rl]->next()) 01205 bbl.add(_gb->gbBBox()); 01206 bbl *= (*localbbl); 01207 if (!bbl.isempty()) { 01208 bbl.mergeboxes(olap); 01209 for (BBox *_b = bbl.first();_b;_b=bbl.next()) 01210 localgbl[rl]->add(GridBox(me,localgbl[rl]->number(),*_b)); 01211 } 01212 GridBoxList* sendgbl = new GridBoxList(*localgbl[rl]); 01213 DAGH_PeriodicBoundaries(localgbl[rl], sendgbl); 01214 01215 if (globalgbl[rl]) { 01216 globalgbl[rl]->empty(); 01217 delete globalgbl[rl]; 01218 } 01219 if (wnum == 1) { 01220 globalgbl[rl] = new GridBoxList(*sendgbl); 01221 } 01222 else { 01223 int sndsize=0, rcvsize=0; 01224 void *sndbuf = (sendgbl) ? sendgbl->pack(sndsize) : 0; 01225 void *rcvbuf = 0; 01226 DAGH_GlbConcat(sndbuf, sndsize, rcvbuf, rcvsize, comm_service::comm()); 01227 globalgbl[rl] = new GridBoxList(rcvbuf, rcvsize, num); 01228 if (rcvbuf) delete [] (char*) rcvbuf; 01229 } 01230 if (sendgbl) { 01231 sendgbl->empty(); 01232 delete sendgbl; 01233 } 01234 } 01235 } 01236 delete localbbl; 01237 01238 register int i; 01239 for (i=0; i<gfnum; i++) if (gflist[i]) { 01240 if (comm_service::dce() && reset_comm) comm_service::reset_comm(gflist[i]->gfid); 01241 int chkpt_str = gflist[i]->checkpoint() ? DAGHTrue : DAGHFalse; 01242 gflist[i]->GF_SetCheckpointFlag(DAGHFalse); 01243 gflist[i]->GF_CheckpointRecompose(); 01244 gflist[i]->GF_SetCheckpointFlag(chkpt_str); 01245 } 01246 01247 for (register int npc=0; npc<chkptpnum; npc++) { 01248 eflag = DAGH_OpenChkptIStream(npc, chkptdir, chkptnamedir, ifs); 01249 if (eflag == DAGHTrue) { 01250 char* dc = new char[sizeof(GridHierarchy)]; 01251 int* di = new int[levels]; 01252 double* dd = new double[nbndrycoords*2*rank]; 01253 GridUnitList dul; 01254 GridBoxList dgl; 01255 BBoxList dbl; 01256 BBox dbb; 01257 ifs.read((char*)dc,sizeof(GridHierarchy)); 01258 ifs >> dbl; 01259 ifs.read((char*)dd,sizeof(double)*nbndrycoords*2*rank); 01260 for (i=0; i<ncutbbox; i++) 01261 ifs >> dbb; 01262 ifs.read((char*)di,sizeof(int)*levels); 01263 delete [] dc; delete [] di; delete [] dd; dbl.empty(); 01264 ifs >> dul; dul.empty(); ifs >> dul; 01265 register int i; 01266 for (i=0; i<levels; i++) { 01267 ifs >> dgl; dgl.empty(); 01268 } 01269 for (i=0; i<levels; i++) { 01270 ifs >> dgl; dgl.empty(); 01271 } 01272 for (i=0; i<levels; i++) { 01273 ifs >> dbl; dbl.empty(); 01274 } 01275 DAGH_CloseChkptIStream(chkptdir, chkptnamedir, ifs); 01276 for (i=0; i<gfnum; i++) if (gflist[i]) 01277 if (gflist[i]->checkpoint()) gflist[i]->GF_CheckpointRestart(npc); 01278 } 01279 } 01280 } 01281 } 01282 delete [] lasttime; 01283 01284 #ifdef DEBUG_PRINT_RG 01285 ( comm_service::log() << "\n*********** New Composite List ***********\n" 01286 << *complist 01287 << "\n*********** ****************** ***********\n" 01288 ).flush(); 01289 #endif 01290 #ifdef DEBUG_PRINT_RG 01291 ( comm_service::log() << "\n*********** New Local List ***********\n" 01292 << *locallist 01293 << "\n*********** ************** ***********\n" 01294 ).flush(); 01295 #endif 01296 #ifdef DEBUG_PRINT_RG 01297 ( comm_service::log() << "\n************* Checkpointed NLists ************\n" ).flush(); 01298 for (rl=0;rl<levels;rl++) { 01299 if (localgbl) if (localgbl[rl]) 01300 ( comm_service::log() << "localgbl L" << rl << ": " 01301 << *localgbl[rl] << "\n" ).flush(); 01302 if (globalgbl) if (globalgbl[rl]) 01303 ( comm_service::log() << "globalgbl L" << rl << ": " 01304 << *globalgbl[rl] << "\n" ).flush(); 01305 ( comm_service::log() << "\n************* **************** ************\n" ).flush(); 01306 } 01307 #endif 01308 DAGH_StopChkpt(); 01309 } 01310 01311 01312 /***************************************************************/ 01313 /* Recompose the hierarchy from memory */ 01314 /***************************************************************/ 01315 void GridHierarchy::DAGH_RecomposeHierarchy(strstream& ifs) 01316 { 01317 AllocError::SetTexts("GridHierarchy", 01318 "DAGH_RecomposeHierarchy(strstream& ifs)"); 01319 01320 if (chkpt_restart()) DAGH_StopChkpt(); 01321 01322 /* Delete old storage */ 01323 register int rl; 01324 for (rl=0;rl<levels;rl++) { 01325 if (oldglobalgbl[rl]) delete oldglobalgbl[rl]; 01326 oldglobalgbl[rl] = 0; 01327 if (oldlocalgbl[rl]) delete oldlocalgbl[rl]; 01328 oldlocalgbl[rl] = 0; 01329 } 01330 01331 DAGH_InitChkpt(); 01332 streampos* chkptdir = 0; 01333 char* chkptnamedir = 0; 01334 /* Start checkpointing */ 01335 DAGH_OpenChkptStrStream(chkptdir, chkptnamedir, ifs); 01336 01337 int* lasttime = new int[levels]; 01338 for (rl=0;rl<levels;rl++) 01339 if (rl<=finelevel()) lasttime[rl]=curtime[rl]; 01340 else lasttime[rl]=-1; 01341 01342 /* Read information from the checkpoint file */ 01343 ifs >> *this; 01344 01345 int reset_comm = DAGHFalse; 01346 for (rl=0;rl<levels;rl++) 01347 if (rl<=finelevel() && lasttime[rl]==curtime[rl]) 01348 reset_comm = DAGHTrue; 01349 01350 /* Close chkpt stream and delete associated data */ 01351 DAGH_CloseChkptStrStream(chkptdir, chkptnamedir, ifs); 01352 01353 #ifdef DEBUG_PRINT_RG 01354 ( comm_service::log() << "\n*********** New Composite List ***********\n" 01355 << *complist 01356 << "\n*********** ****************** ***********\n" 01357 ).flush(); 01358 #endif 01359 #ifdef DEBUG_PRINT_RG 01360 ( comm_service::log() << "\n*********** New Local List ***********\n" 01361 << *locallist 01362 << "\n*********** ************** ***********\n" 01363 ).flush(); 01364 #endif 01365 01366 register int i; 01367 for (i=0; i<gfnum; i++) if (gflist[i]) { 01368 if (comm_service::dce() && reset_comm) comm_service::reset_comm(gflist[i]->gfid); 01369 gflist[i]->GF_CheckpointRecompose(ifs); 01370 } 01371 01372 delete [] lasttime; 01373 01374 #ifdef DEBUG_PRINT_RG 01375 ( comm_service::log() << "\n************* Checkpointed NLists ************\n" ).flush(); 01376 for (rl=0;rl<levels;rl++) { 01377 if (localgbl) if (localgbl[rl]) 01378 ( comm_service::log() << "localgbl L" << rl << ": " 01379 << *localgbl[rl] << "\n" ).flush(); 01380 if (globalgbl) if (globalgbl[rl]) 01381 ( comm_service::log() << "globalgbl L" << rl << ": " 01382 << *globalgbl[rl] << "\n" ).flush(); 01383 ( comm_service::log() << "\n************* **************** ************\n" ).flush(); 01384 } 01385 #endif 01386 01387 DAGH_StopChkpt(); 01388 } 01389 01390 /***************************************************************/ 01391 /* Refine the hierarchy */ 01392 /***************************************************************/ 01393 void GridHierarchy::DAGH_Refine(const int lev) 01394 { 01395 if (lev<0 || lev>=levels-1) return; 01396 01397 if (!localbboxarray[lev]) 01398 localbboxarray[lev] = new BBoxList(); 01399 else 01400 localbboxarray[lev]->empty(); 01401 01402 for (register GridBox* gb = localgbl[lev]->first(); gb ; 01403 gb = localgbl[lev]->next()) 01404 localbboxarray[lev]->add(gb->gbBBox()); 01405 curtime[lev+1] = curtime[lev]; 01406 01407 #ifdef DEBUG_PRINT_RG 01408 ( comm_service::log() 01409 << "\n************* Local List at Level " << lev << " *************\n" 01410 << *localbboxarray[lev] 01411 << "\n************* ***************** *************\n" 01412 ).flush(); 01413 #endif 01414 } 01415 01416 void GridHierarchy::DAGH_Refine(BBoxList &bblist, const int lev) 01417 { 01418 if (lev<0 || lev>=levels-1) return; 01419 01420 if (!localbboxarray[lev]) 01421 localbboxarray[lev] = new BBoxList(); 01422 else 01423 localbboxarray[lev]->empty(); 01424 01425 BBoxList testbbl; 01426 for (register GridBox* gb = localgbl[lev]->first(); gb ; 01427 gb = localgbl[lev]->next()) 01428 testbbl.add(gb->gbBBox()); 01429 01430 const int ls = stepsize(lev); 01431 for (BBox *bb=bblist.first(); bb; bb=bblist.next()) { 01432 Coords& bs = bb->stepsize(); 01433 for (register int d=0; d<bb->rank; d++) 01434 if (bs(d)<ls) bb->coarsen(d,ls/bs(d)); 01435 else if (bs(d)>ls) bb->refine(d,bs(d)/ls,0); 01436 localbboxarray[lev]->add(*bb); 01437 } 01438 *localbboxarray[lev] *= testbbl; 01439 curtime[lev+1] = curtime[lev]; 01440 01441 #ifdef DEBUG_PRINT_RG 01442 ( comm_service::log() 01443 << "\n************* Local List at Level" << lev << " *************\n" 01444 << *localbboxarray[lev] 01445 << "\n************* ***************** *************\n" 01446 ).flush(); 01447 #endif 01448 } 01449 01450 /***************************************************************/ 01451 /* Checkpoint file open/close/seek */ 01452 /***************************************************************/ 01453 int GridHierarchy::DAGH_OpenChkptIStream(const int p, 01454 ifstream& ifs) 01455 { 01456 assert (chkptflag == DAGHTrue); 01457 01458 char buf[128]; 01459 ostrstream obuf(buf,sizeof(buf),ios::out); 01460 chkpt_filename(obuf,chkptname,p); 01461 ifs.open(buf); 01462 if (!ifs) return DAGHFalse; 01463 ifs.read((char*)&chkptpnum,sizeof(int)); 01464 return DAGHTrue; 01465 01466 } 01467 01468 int GridHierarchy::DAGH_OpenChkptIStream(const int p, 01469 streampos*& chkptdir, 01470 char*& chkptnamedir, 01471 ifstream& ifs) 01472 { 01473 assert (chkptflag == DAGHTrue); 01474 01475 char buf[128]; 01476 ostrstream obuf(buf,sizeof(buf),ios::out); 01477 chkpt_filename(obuf,chkptname,p); 01478 ifs.open(buf); 01479 if (!ifs) return DAGHFalse; 01480 ifs.read((char*)&chkptpnum,sizeof(int)); 01481 01482 int dirnum = 0; 01483 ifs.read((char*)&dirnum,sizeof(int)); 01484 01485 const int namedirnum = (dirnum-1)*DAGHBktGFNameWidth; 01486 01487 chkptdir = new streampos[dirnum]; 01488 ifs.read((char*)chkptdir,sizeof(streampos)*dirnum); 01489 chkptnamedir = new char[namedirnum]; 01490 ifs.read((char*)chkptnamedir,sizeof(char)*namedirnum); 01491 01492 ifs.seekg(chkptdir[dirnum-1]); 01493 return DAGHTrue; 01494 } 01495 01496 int GridHierarchy::DAGH_GetGFChkptIStream(const int p, 01497 const char* gfname, 01498 const int gfid, 01499 ifstream& ifs) 01500 { 01501 assert (chkptflag == DAGHTrue); 01502 01503 char buf[128]; 01504 ostrstream obuf(buf,sizeof(buf),ios::out); 01505 chkpt_filename(obuf,chkptname,p); 01506 ifs.open(buf); 01507 if (!ifs) return DAGHFalse; 01508 ifs.read((char*)&chkptpnum,sizeof(int)); 01509 01510 int dirnum = 0; 01511 ifs.read((char*)&dirnum,sizeof(int)); 01512 01513 const int namedirnum = (dirnum-1)*DAGHBktGFNameWidth; 01514 01515 streampos* chkptdir = new streampos[dirnum]; 01516 ifs.read((char*)chkptdir,sizeof(streampos)*dirnum); 01517 char* chkptnamedir = new char[namedirnum]; 01518 ifs.read((char*)chkptnamedir,sizeof(char)*namedirnum); 01519 01520 if (!strncmp(gfname,(chkptnamedir+gfid*DAGHBktGFNameWidth), 01521 DAGHBktGFNameWidth)) { 01522 ifs.seekg(chkptdir[gfid]); 01523 return DAGHTrue; 01524 } 01525 else { 01526 for (register int i=0; i<dirnum-1; i++) 01527 if (!strncmp(gfname,(chkptnamedir+i*DAGHBktGFNameWidth), 01528 DAGHBktGFNameWidth)) { 01529 ifs.seekg(chkptdir[i]); 01530 return DAGHTrue; 01531 } 01532 } 01533 ifs.close(); 01534 return DAGHFalse; 01535 } 01536 01537 int GridHierarchy::DAGH_OpenChkptOStream(const int p, 01538 ofstream& ofs) 01539 { 01540 assert (chkptflag == DAGHTrue); 01541 01542 char buf[128]; 01543 ostrstream obuf(buf,sizeof(buf),ios::out); 01544 chkpt_filename(obuf,chkptname,p); 01545 ofs.open(buf); 01546 if (!ofs) return DAGHFalse; 01547 const int pnum = comm_service::proc_num(); 01548 ofs.write((char*)&pnum,sizeof(int)); 01549 return DAGHTrue; 01550 } 01551 01552 int GridHierarchy::DAGH_OpenChkptStrStream(streampos*& chkptdir, 01553 char*& chkptnamedir, 01554 strstream& ifs) 01555 { 01556 ifs.seekg((streampos)0, ios::beg); 01557 01558 int dirnum = 0; 01559 ifs.read((char*)&dirnum,sizeof(int)); 01560 01561 const int namedirnum = (dirnum-1)*DAGHBktGFNameWidth; 01562 01563 chkptdir = new streampos[dirnum]; 01564 ifs.read((char*)chkptdir,sizeof(streampos)*dirnum); 01565 chkptnamedir = new char[namedirnum]; 01566 ifs.read((char*)chkptnamedir,sizeof(char)*namedirnum); 01567 01568 ifs.seekg(chkptdir[dirnum-1]); 01569 return DAGHTrue; 01570 } 01571 01572 int GridHierarchy::DAGH_GetGFChkptStrStream(const char* gfname, 01573 const int gfid, 01574 strstream& ifs) 01575 { 01576 ifs.seekg((streampos)0, ios::beg); 01577 01578 int dirnum = 0; 01579 ifs.read((char*)&dirnum,sizeof(int)); 01580 01581 const int namedirnum = (dirnum-1)*DAGHBktGFNameWidth; 01582 01583 streampos* chkptdir = new streampos[dirnum]; 01584 ifs.read((char*)chkptdir,sizeof(streampos)*dirnum); 01585 char* chkptnamedir = new char[namedirnum]; 01586 ifs.read((char*)chkptnamedir,sizeof(char)*namedirnum); 01587 01588 if (!strncmp(gfname,(chkptnamedir+gfid*DAGHBktGFNameWidth), 01589 DAGHBktGFNameWidth)) { 01590 ifs.seekg(chkptdir[gfid]); 01591 return DAGHTrue; 01592 } 01593 else { 01594 for (register int i=0; i<dirnum-1; i++) 01595 if (!strncmp(gfname,(chkptnamedir+i*DAGHBktGFNameWidth), 01596 DAGHBktGFNameWidth)) { 01597 ifs.seekg(chkptdir[i]); 01598 return DAGHTrue; 01599 } 01600 } 01601 return DAGHFalse; 01602 } 01603 01604 /***************************************************************/ 01605 /* Write Checkpoint file! */ 01606 /***************************************************************/ 01607 void GridHierarchy::DAGH_Checkpoint(const char* name) 01608 { 01609 const int me = comm_service::proc_me(); 01610 01611 /* Start checkpointing */ 01612 DAGH_InitChkpt(name); 01613 ofstream ofs; 01614 int eflag = DAGH_OpenChkptOStream(me,ofs); 01615 assert (eflag == DAGHTrue); 01616 01617 const int dirnum = gfnum+1; 01618 const int namedirnum = gfnum*DAGHBktGFNameWidth; 01619 streampos* chkptdir = new streampos[dirnum]; 01620 char* chkptnamedir = new char[namedirnum]; 01621 01622 ofs.write((char*)&dirnum,sizeof(int)); 01623 01624 const streampos chkptdirpos = ofs.tellp(); 01625 ofs.write((char*)chkptdir,sizeof(streampos)*dirnum); 01626 ofs.write((char*)chkptnamedir,sizeof(char)*namedirnum); 01627 chkptdir[dirnum-1] = ofs.tellp(); 01628 ofs << *this; 01629 01630 for (register int i=0; i<gfnum; i++) 01631 if (gflist[i] && gflist[i]->checkpoint()) { 01632 chkptdir[i] = ofs.tellp(); 01633 strncpy(chkptnamedir+(i*DAGHBktGFNameWidth), 01634 gflist[i]->gfname,DAGHBktGFNameWidth); 01635 gflist[i]->GF_Checkpoint(ofs); 01636 } 01637 else chkptdir[i] = 0; 01638 01639 ofs.seekp(chkptdirpos); 01640 ofs.write((char*)chkptdir,sizeof(streampos)*dirnum); 01641 ofs.write((char*)chkptnamedir,sizeof(char)*namedirnum); 01642 01643 if (chkptdir) delete [] chkptdir; 01644 if (chkptnamedir) delete [] chkptnamedir; 01645 01646 DAGH_CloseChkptOStream(ofs); 01647 DAGH_StopChkpt(); 01648 } 01649 01650 /***************************************************************/ 01651 /* Write Checkpoint to memory! */ 01652 /***************************************************************/ 01653 int GridHierarchy::DAGH_Checkpoint_StrStream_Memory() 01654 { 01655 int mem=0; 01656 mem += sizeof(int); 01657 mem += sizeof(streampos)*(gfnum+1); 01658 mem += sizeof(char)*gfnum*DAGHBktGFNameWidth; 01659 01660 mem += sizeof(GridHierarchy); 01661 mem += intbaselist->number()*sizeof(BBox)+sizeof(int); 01662 mem += sizeof(double)*nbndrycoords*2*rank; 01663 mem += ncutbbox*sizeof(BBox); 01664 mem += sizeof(int)*levels; 01665 mem += complist->number()*sizeof(GridUnit)+sizeof(int); 01666 mem += locallist->number()*sizeof(GridUnit)+sizeof(int); 01667 register int i; 01668 for (i=0; i<levels; i++) { 01669 if (globalgbl[i]) mem += globalgbl[i]->number()*sizeof(GridBox); 01670 if (localgbl[i]) mem += localgbl[i]->number()*sizeof(GridBox); 01671 if (localbboxarray[i]) mem += localbboxarray[i]->number()*sizeof(BBox); 01672 mem += 3*sizeof(int); 01673 } 01674 01675 for (i=0; i<gfnum; i++) 01676 if (gflist[i] && gflist[i]->checkpoint()) 01677 mem += gflist[i]->GF_Checkpoint_StrStream_Memory(); 01678 return mem; 01679 } 01680 01681 void GridHierarchy::DAGH_Checkpoint(strstream& ofs) 01682 { 01683 DAGH_InitChkpt(); 01684 const int dirnum = gfnum+1; 01685 const int namedirnum = gfnum*DAGHBktGFNameWidth; 01686 streampos* chkptdir = new streampos[dirnum]; 01687 char* chkptnamedir = new char[namedirnum]; 01688 01689 ofs.write((char*)&dirnum,sizeof(int)); 01690 01691 const streampos chkptdirpos = ofs.tellp(); 01692 ofs.write((char*)chkptdir,sizeof(streampos)*dirnum); 01693 ofs.write((char*)chkptnamedir,sizeof(char)*namedirnum); 01694 chkptdir[dirnum-1] = ofs.tellp(); 01695 ofs << *this; 01696 for (register int i=0; i<gfnum; i++) 01697 if (gflist[i] && gflist[i]->checkpoint()) { 01698 chkptdir[i] = ofs.tellp(); 01699 strncpy(chkptnamedir+(i*DAGHBktGFNameWidth), 01700 gflist[i]->gfname,DAGHBktGFNameWidth); 01701 gflist[i]->GF_Checkpoint(ofs); 01702 } 01703 else chkptdir[i] = 0; 01704 01705 ofs.seekp(chkptdirpos); 01706 ofs.write((char*)chkptdir,sizeof(streampos)*dirnum); 01707 ofs.write((char*)chkptnamedir,sizeof(char)*namedirnum); 01708 01709 if (chkptdir) delete [] chkptdir; 01710 if (chkptnamedir) delete [] chkptnamedir; 01711 01712 DAGH_StopChkpt(); 01713 } 01714 01715 /***************************************************************/ 01716 /* Utitlity routines.... */ 01717 /* Changed --- RD */ 01718 /***************************************************************/ 01719 void GridHierarchy::wlb(double *wc) const 01720 { 01721 assert (wc != 0); 01722 for (register int i=0;i<rank;i++) 01723 wc[i] = toWorld(dspecs[i],0,basebbox.stepsize(i)); 01724 } 01725 01726 void GridHierarchy::wub(double *wc) const 01727 { 01728 assert (wc != 0); 01729 for (register int i=0;i<rank;i++) 01730 wc[i] = toWorld(dspecs[i],intbbox.upper(i)-intbbox.lower(i),intbbox.stepsize(i)); 01731 } 01732 01733 void GridHierarchy::llb(int *lc) const 01734 { 01735 assert (lc != 0); 01736 for (register int i=0;i<rank;i++) lc[i] = basebbox.lower(i); 01737 } 01738 01739 void GridHierarchy::lub(int *lc) const 01740 { 01741 assert (lc != 0); 01742 for (register int i=0;i<rank;i++) lc[i] = basebbox.upper(i); 01743 } 01744 01745 void GridHierarchy::worldCoords(const int *lc, const int *ls, double *wc) const 01746 { 01747 assert (wc != 0); 01748 for (register int i=0;i<rank;i++) 01749 wc[i] = toWorld(dspecs[i],lc[i]-intbbox.lower(i),ls[i]); 01750 } 01751 void GridHierarchy::worldStep(const int *ls, double *ws) const 01752 { 01753 assert (ws != 0); 01754 for (register int i=0;i<rank;i++) 01755 ws[i] = ls[i] * dspecs[i].hfine; 01756 } 01757 01758 DCoords GridHierarchy::worldCoords(const int *lc, const int *ls) const 01759 { 01760 DCoords wc(rank); 01761 for (register int i=0;i<rank;i++) 01762 wc(i) = toWorld(dspecs[i],lc[i]-intbbox.lower(i),ls[i]); 01763 01764 return wc; 01765 } 01766 DCoords GridHierarchy::worldCoordsUpper(const int *lc, const int *ls) const 01767 { 01768 DCoords wc(rank); 01769 for (register int i=0;i<rank;i++) 01770 wc(i) = toWorldUpper(dspecs[i],lc[i]-intbbox.lower(i),ls[i],daghoverlap(i)); 01771 01772 return wc; 01773 } 01774 DCoords GridHierarchy::worldCoordsLower(const int *lc, const int *ls) const 01775 { 01776 DCoords wc(rank); 01777 for (register int i=0;i<rank;i++) 01778 wc(i) = toWorldLower(dspecs[i],lc[i]-intbbox.lower(i),ls[i],daghoverlap(i)); 01779 01780 return wc; 01781 } 01782 DCoords GridHierarchy::worldStep(const int *ls) const 01783 { 01784 DCoords ws(rank); 01785 for (register int i=0;i<rank;i++) 01786 ws(i) = ls[i] * dspecs[i].hfine; 01787 01788 return ws; 01789 } 01790 01791 Coords GridHierarchy::localCoords(double const *wc) const 01792 { 01793 Coords lc(rank,0); 01794 for (register int i=0;i<rank;i++) 01795 lc(i) = toLocal(dspecs[i],wc[i]); 01796 01797 return lc; 01798 } 01799 Coords GridHierarchy::localStep(double const *ws) const 01800 { 01801 Coords ls(rank,0); 01802 for (register int i=0;i<rank;i++) 01803 ls(i) = (int) (ws[i] / dspecs[i].hfine); 01804 return ls; 01805 } 01806 void GridHierarchy::localCoords(double const *wc, int *lc) const 01807 { 01808 assert (lc != 0); 01809 for (register int i=0;i<rank;i++) 01810 lc[i] = toLocal(dspecs[i],wc[i]); 01811 } 01812 void GridHierarchy::localStep(double const *ws, int *ls) const 01813 { 01814 assert (ls != 0); 01815 for (register int i=0;i<rank;i++) 01816 ls[i] = (int) (ws[i] / dspecs[i].hfine); 01817 } 01818 01819 /***************************************************************/ 01820 /* Global BoundingBox Queries */ 01821 /***************************************************************/ 01822 void GridHierarchy::glb_bboxlist(BBoxList& bbl, 01823 const int l, 01824 const int type) const { 01825 01826 short olap[DAGHMaxRank]; 01827 DAGH_InitOverlaps(type,olap); 01828 01829 if (!bbl.isempty()) bbl.empty(); 01830 01831 if (globalgbl[l]) 01832 for (register GridBox* gb=globalgbl[l]->first();gb; 01833 gb=globalgbl[l]->next()) 01834 bbl.add(gb->gbBBox(olap)); 01835 } 01836 01837 /***************************************************************/ 01838 /* IO Routines */ 01839 /***************************************************************/ 01840 01841 void GridHierarchy::DAGH_IOServe(void) 01842 { 01843 if (comm_service::comminit() && io_end_server) { 01844 #ifdef DEBUG_PRINT_COMM_IO 01845 (comm_service::log() << "GridHierarchy::DAGH_IOServe " 01846 << comm_service::proc_me() << " " 01847 << "Serving ! " 01848 << endl ).flush(); 01849 #endif 01850 comm_service::serve(*io_end_server->req()); 01851 } 01852 } 01853 01854 /***************************************************************/ 01855 /* Print it..... */ 01856 /***************************************************************/ 01857 ostream& operator << (ostream& os, const struct dimspec& ds) 01858 { 01859 if (&ds == (struct dimspec *) NULL) return os; 01860 os << "[" << ds.low << "," << ds.high << "," << ds.h << "," << ds.n << "]"; 01861 return os; 01862 } 01863 01864 ostream& operator << (ostream& os, const struct MergedGridUnit& mgul) 01865 { 01866 os << "*************** Bounding Box ***************" << endl; 01867 os << mgul.bb << endl; 01868 os << "*************** GridUnitList ***************" << endl; 01869 os << mgul.gul; 01870 os << "*************** ***************" << endl; 01871 return os; 01872 } 01873 01874 ostream& operator << (ostream& os, const GridHierarchy& gh) 01875 { 01876 if (&gh == (GridHierarchy *) NULL) return os; 01877 01878 os << "DAGH(" << gh.rank << ") "; 01879 os << gh.tspecs; 01880 register int i; 01881 for (i=0;i<gh.rank;i++) os << gh.dspecs[i]; 01882 os << endl; 01883 01884 os << "BBBox: " << gh.basebbox << " "; 01885 os << "IBBox: " << gh.intbbox << " "; 01886 os << endl; 01887 01888 os << "Clev: " << gh.crslev << " "; 01889 os << "Flev: " << gh.finelev << " "; 01890 os << "Levels: " << gh.levels << " "; 01891 os << endl; 01892 for(i=0;i<gh.levels;i++) os << "Rby[" << i << "]: " << gh.refby[i] << " "; 01893 os << endl; 01894 01895 os << "BoundaryType: " << gh.bndrytype << " "; 01896 os << "AdaptBoundaryType: " << gh.adaptbndrytype << " "; 01897 os << "BoundaryWidth: " << gh.bndrywidth << " "; 01898 os << "ExternalGhostWidth: " << gh.extghostwidth << " "; 01899 os << endl; 01900 01901 os << "NumGF: " << gh.gfnum << endl; 01902 for (i=0;i<gh.gfnum;i++) 01903 if (gh.gflist[i]) 01904 os << "\t[" << gh.gflist[i]->GF_Name() << "] " << endl; 01905 01906 os << endl; 01907 return os; 01908 } 01909 01910 /***************************************************************/ 01911 /* Binary IO. */ 01912 /***************************************************************/ 01913 ofstream& operator << (ofstream& ofs, const GridHierarchy& gh) 01914 { 01915 01916 if (&gh == (GridHierarchy *) NULL) return ofs; 01917 01918 ofs.write((char*)&gh,sizeof(GridHierarchy)); 01919 01920 register int i; 01921 ofs << *gh.intbaselist; 01922 ofs.write((char*)gh.bndrycoords,sizeof(double)*gh.nbndrycoords*2*gh.rank); 01923 for (i=0; i<gh.ncutbbox; i++) 01924 ofs << gh.cutbbox[i]; 01925 01926 ofs.write((char*)gh.curtime,sizeof(int)*gh.levels); 01927 01928 ofs << *gh.complist; 01929 ofs << *gh.locallist; 01930 01931 GridBoxList dummy; 01932 for (i=0; i<gh.levels; i++) 01933 if (gh.globalgbl[i]) ofs << *gh.globalgbl[i]; 01934 else ofs << dummy; 01935 for (i=0; i<gh.levels; i++) 01936 if (gh.localgbl[i]) ofs << *gh.localgbl[i]; 01937 else ofs << dummy; 01938 01939 BBoxList bbldummy; 01940 for (i=0; i<gh.levels; i++) 01941 if (gh.localbboxarray[i]) ofs << *gh.localbboxarray[i]; 01942 else ofs << bbldummy; 01943 01944 return ofs; 01945 } 01946 01947 ifstream& operator >> (ifstream& ifs, GridHierarchy& gh) 01948 { 01949 if (&gh == (GridHierarchy *) NULL) return ifs; 01950 01951 /* Save pointers & Checkpoint info */ 01952 short* tmp_refby = gh.refby; 01953 BBoxList* tmp_intbaselist = gh.intbaselist; 01954 double* tmp_bndrycoords = gh.bndrycoords; 01955 BBox* tmp_cutbbox = gh.cutbbox; 01956 01957 int* tmp_curtime = gh.curtime; 01958 01959 DAGHDistribution* tmp_distribution = gh.distribution; 01960 GridUnitList* tmp_complist = gh.complist; 01961 GridUnitList* tmp_locallist = gh.locallist; 01962 01963 GridBoxList** tmp_globalgbl = gh.globalgbl; 01964 GridBoxList** tmp_localgbl = gh.localgbl; 01965 GridBoxList** tmp_oldglobalgbl = gh.oldglobalgbl; 01966 GridBoxList** tmp_oldlocalgbl = gh.oldlocalgbl; 01967 01968 BBoxList** tmp_localbboxarray = gh.localbboxarray; 01969 01970 const int tmp_gfnum = gh.gfnum; 01971 GridFunctionVoid** tmp_gflist = gh.gflist; 01972 01973 DAGHIOServerRcv * tmp_io_write_server = gh.io_write_server; 01974 DAGHIOServerSnd* tmp_io_read_server = gh.io_read_server; 01975 DAGHIOServerPing* tmp_io_end_server = gh.io_end_server; 01976 01977 #ifdef DAGH_IOV 01978 RawTCPserver tmp_ServerPort = gh.ServerPort; 01979 RawTCPport tmp_Server = gh.Server; 01980 #endif 01981 01982 int old_chkptflag = gh.chkptflag; 01983 int old_chkptpnum = gh.chkptpnum; 01984 char old_chkptname[DAGHChkPtTagNameSize]; 01985 strncpy(old_chkptname,gh.chkptname,DAGHChkPtTagNameSize); 01986 01987 ifs.read((char*)&gh,sizeof(GridHierarchy)); 01988 01989 /* Reset pointers */ 01990 gh.refby = tmp_refby; 01991 gh.intbaselist = tmp_intbaselist; 01992 gh.bndrycoords = tmp_bndrycoords; 01993 gh.cutbbox = tmp_cutbbox; 01994 01995 gh.curtime = tmp_curtime; 01996 01997 gh.distribution = tmp_distribution; 01998 gh.complist = tmp_complist; 01999 gh.locallist = tmp_locallist; 02000 02001 gh.globalgbl = tmp_globalgbl; 02002 gh.localgbl = tmp_localgbl; 02003 gh.oldglobalgbl = tmp_oldglobalgbl; 02004 gh.oldlocalgbl = tmp_oldlocalgbl; 02005 02006 gh.localbboxarray = tmp_localbboxarray; 02007 02008 gh.gfnum = tmp_gfnum; 02009 gh.gflist = tmp_gflist; 02010 02011 gh.io_write_server = tmp_io_write_server; 02012 gh.io_read_server = tmp_io_read_server; 02013 gh.io_end_server = tmp_io_end_server; 02014 02015 #ifdef DAGH_IOV 02016 gh.ServerPort = tmp_ServerPort; 02017 gh.Server = tmp_Server; 02018 #endif 02019 02020 gh.chkptflag = old_chkptflag; 02021 gh.chkptpnum = old_chkptpnum; 02022 strncpy(gh.chkptname,old_chkptname,DAGHChkPtTagNameSize); 02023 02024 register int i; 02025 /* Allocate and read Bndry info lists */ 02026 if (gh.intbaselist) gh.intbaselist->empty(); 02027 else gh.intbaselist = new BBoxList; 02028 ifs >> *gh.intbaselist; 02029 02030 if (gh.bndrycoords) delete [] gh.bndrycoords; 02031 gh.bndrycoords = new double[gh.nbndrycoords*2*gh.rank]; 02032 ifs.read((char*)gh.bndrycoords,sizeof(double)*gh.nbndrycoords*2*gh.rank); 02033 02034 if (gh.ncutbbox) delete [] gh.cutbbox; 02035 gh.cutbbox = new BBox[gh.ncutbbox]; 02036 for (i=0; i<gh.ncutbbox; i++) 02037 ifs >> gh.cutbbox[i]; 02038 02039 /* Allocate Current Time Array */ 02040 if (gh.curtime) delete [] gh.curtime; 02041 gh.curtime = new int[gh.levels]; 02042 for (i=0;i<gh.levels;i++) 02043 gh.curtime[i] = 0; 02044 02045 /* Read Current Time Array */ 02046 ifs.read((char*)gh.curtime,sizeof(int)*gh.levels); 02047 02048 /* Allocate and read Composite List */ 02049 if (gh.complist) gh.complist->empty(); 02050 else gh.complist = new GridUnitList; 02051 ifs >> *gh.complist; 02052 02053 /* Allocate and read Local List */ 02054 if (gh.locallist) gh.locallist->empty(); 02055 else gh.locallist = new GridUnitList; 02056 ifs >> *gh.locallist; 02057 02058 /* Allocate and read Global GBL's */ 02059 for (i=0; i<gh.levels; i++) { 02060 if (gh.globalgbl[i]) gh.globalgbl[i]->empty(); 02061 else gh.globalgbl[i] = new GridBoxList; 02062 ifs >> *gh.globalgbl[i]; 02063 if (gh.globalgbl[i]->isempty()) { 02064 delete gh.globalgbl[i]; 02065 gh.globalgbl[i] = 0 ; 02066 } 02067 } 02068 02069 /* Allocate and read Local GBL's */ 02070 for (i=0; i<gh.levels; i++) { 02071 if (gh.localgbl[i]) gh.localgbl[i]->empty(); 02072 else gh.localgbl[i] = new GridBoxList; 02073 ifs >> *gh.localgbl[i]; 02074 if (gh.localgbl[i]->isempty() && !gh.globalgbl[i]) { 02075 delete gh.localgbl[i]; 02076 gh.localgbl[i] = 0 ; 02077 } 02078 } 02079 02080 /* Allocate and read localbboxarray */ 02081 for (i=0; i<gh.levels; i++) { 02082 if (gh.localbboxarray[i]) gh.localbboxarray[i]->empty(); 02083 else gh.localbboxarray[i] = new BBoxList; 02084 ifs >> *gh.localbboxarray[i]; 02085 if (gh.localbboxarray[i]->isempty()) { 02086 delete gh.localbboxarray[i]; 02087 gh.localbboxarray[i] = 0 ; 02088 } 02089 } 02090 02091 return ifs; 02092 } 02093 02094 /***************************************************************/ 02095 /* Binary Memory IO --- RD */ 02096 /***************************************************************/ 02097 strstream& operator << (strstream& ofs, const GridHierarchy& gh) 02098 { 02099 if (&gh == (GridHierarchy *) NULL) return ofs; 02100 02101 ofs.write((char*)&gh,sizeof(GridHierarchy)); 02102 02103 register int i; 02104 ofs << *gh.intbaselist; 02105 ofs.write((char*)gh.bndrycoords,sizeof(double)*gh.nbndrycoords*2*gh.rank); 02106 for (i=0; i<gh.ncutbbox; i++) 02107 ofs << gh.cutbbox[i]; 02108 02109 ofs.write((char*)gh.curtime,sizeof(int)*gh.levels); 02110 02111 ofs << *gh.complist; 02112 ofs << *gh.locallist; 02113 02114 GridBoxList gbldummy; 02115 for (i=0; i<gh.levels; i++) 02116 if (gh.globalgbl[i]) ofs << *gh.globalgbl[i]; 02117 else ofs << gbldummy; 02118 for (i=0; i<gh.levels; i++) 02119 if (gh.localgbl[i]) ofs << *gh.localgbl[i]; 02120 else ofs << gbldummy; 02121 02122 BBoxList bbldummy; 02123 for (i=0; i<gh.levels; i++) 02124 if (gh.localbboxarray[i]) ofs << *gh.localbboxarray[i]; 02125 else ofs << bbldummy; 02126 02127 return ofs; 02128 } 02129 02130 strstream& operator >> (strstream& ifs, GridHierarchy& gh) 02131 { 02132 if (&gh == (GridHierarchy *) NULL) return ifs; 02133 02134 /* Save pointers & Checkpoint info */ 02135 short* tmp_refby = gh.refby; 02136 BBoxList* tmp_intbaselist = gh.intbaselist; 02137 double* tmp_bndrycoords = gh.bndrycoords; 02138 BBox* tmp_cutbbox = gh.cutbbox; 02139 02140 int* tmp_curtime = gh.curtime; 02141 02142 DAGHDistribution* tmp_distribution = gh.distribution; 02143 GridUnitList* tmp_complist = gh.complist; 02144 GridUnitList* tmp_locallist = gh.locallist; 02145 02146 GridBoxList** tmp_globalgbl = gh.globalgbl; 02147 GridBoxList** tmp_localgbl = gh.localgbl; 02148 GridBoxList** tmp_oldglobalgbl = gh.oldglobalgbl; 02149 GridBoxList** tmp_oldlocalgbl = gh.oldlocalgbl; 02150 02151 BBoxList** tmp_localbboxarray = gh.localbboxarray; 02152 02153 const int tmp_gfnum = gh.gfnum; 02154 GridFunctionVoid** tmp_gflist = gh.gflist; 02155 02156 DAGHIOServerRcv * tmp_io_write_server = gh.io_write_server; 02157 DAGHIOServerSnd* tmp_io_read_server = gh.io_read_server; 02158 DAGHIOServerPing* tmp_io_end_server = gh.io_end_server; 02159 02160 #ifdef DAGH_IOV 02161 RawTCPserver tmp_ServerPort = gh.ServerPort; 02162 RawTCPport tmp_Server = gh.Server; 02163 #endif 02164 02165 int old_chkptflag = gh.chkptflag; 02166 int old_chkptpnum = gh.chkptpnum; 02167 char old_chkptname[DAGHChkPtTagNameSize]; 02168 strncpy(old_chkptname,gh.chkptname,DAGHChkPtTagNameSize); 02169 02170 ifs.read((char*)&gh,sizeof(GridHierarchy)); 02171 02172 /* Reset pointers */ 02173 gh.refby = tmp_refby; 02174 gh.intbaselist = tmp_intbaselist; 02175 gh.bndrycoords = tmp_bndrycoords; 02176 gh.cutbbox = tmp_cutbbox; 02177 02178 gh.curtime = tmp_curtime; 02179 02180 gh.distribution = tmp_distribution; 02181 gh.complist = tmp_complist; 02182 gh.locallist = tmp_locallist; 02183 02184 gh.globalgbl = tmp_globalgbl; 02185 gh.localgbl = tmp_localgbl; 02186 gh.oldglobalgbl = tmp_oldglobalgbl; 02187 gh.oldlocalgbl = tmp_oldlocalgbl; 02188 02189 gh.localbboxarray = tmp_localbboxarray; 02190 02191 gh.gfnum = tmp_gfnum; 02192 gh.gflist = tmp_gflist; 02193 02194 gh.io_write_server = tmp_io_write_server; 02195 gh.io_read_server = tmp_io_read_server; 02196 gh.io_end_server = tmp_io_end_server; 02197 02198 #ifdef DAGH_IOV 02199 gh.ServerPort = tmp_ServerPort; 02200 gh.Server = tmp_Server; 02201 #endif 02202 02203 gh.chkptflag = old_chkptflag; 02204 gh.chkptpnum = old_chkptpnum; 02205 strncpy(gh.chkptname,old_chkptname,DAGHChkPtTagNameSize); 02206 02207 register int i; 02208 /* Allocate and read Bndry info lists */ 02209 if (gh.intbaselist) gh.intbaselist->empty(); 02210 else gh.intbaselist = new BBoxList; 02211 ifs >> *gh.intbaselist; 02212 02213 if (gh.bndrycoords) delete [] gh.bndrycoords; 02214 gh.bndrycoords = new double[gh.nbndrycoords*2*gh.rank]; 02215 ifs.read((char*)gh.bndrycoords,sizeof(double)*gh.nbndrycoords*2*gh.rank); 02216 02217 if (gh.ncutbbox) delete [] gh.cutbbox; 02218 gh.cutbbox = new BBox[gh.ncutbbox]; 02219 for (i=0; i<gh.ncutbbox; i++) 02220 ifs >> gh.cutbbox[i]; 02221 02222 /* Allocate Current Time Array */ 02223 if (gh.curtime) delete [] gh.curtime; 02224 gh.curtime = new int[gh.levels]; 02225 for (i=0;i<gh.levels;i++) 02226 gh.curtime[i] = 0; 02227 02228 /* Read Current Time Array */ 02229 ifs.read((char*)gh.curtime,sizeof(int)*gh.levels); 02230 02231 /* Allocate and read Composite List */ 02232 if (gh.complist) gh.complist->empty(); 02233 else gh.complist = new GridUnitList; 02234 ifs >> *gh.complist; 02235 02236 /* Allocate and read Local List */ 02237 if (gh.locallist) gh.locallist->empty(); 02238 else gh.locallist = new GridUnitList; 02239 ifs >> *gh.locallist; 02240 02241 /* Allocate and read Global GBL's */ 02242 for (i=0; i<gh.levels; i++) { 02243 if (gh.globalgbl[i]) gh.globalgbl[i]->empty(); 02244 else gh.globalgbl[i] = new GridBoxList; 02245 ifs >> *gh.globalgbl[i]; 02246 if (gh.globalgbl[i]->isempty()) { 02247 delete gh.globalgbl[i]; 02248 gh.globalgbl[i] = 0 ; 02249 } 02250 } 02251 02252 /* Allocate and read Local GBL's */ 02253 for (i=0; i<gh.levels; i++) { 02254 if (gh.localgbl[i]) gh.localgbl[i]->empty(); 02255 else gh.localgbl[i] = new GridBoxList; 02256 ifs >> *gh.localgbl[i]; 02257 if (gh.localgbl[i]->isempty() && !gh.globalgbl[i]) { 02258 delete gh.localgbl[i]; 02259 gh.localgbl[i] = 0 ; 02260 } 02261 } 02262 02263 /* Allocate and read localbboxarray */ 02264 for (i=0; i<gh.levels; i++) { 02265 if (gh.localbboxarray[i]) gh.localbboxarray[i]->empty(); 02266 else gh.localbboxarray[i] = new BBoxList; 02267 ifs >> *gh.localbboxarray[i]; 02268 if (gh.localbboxarray[i]->isempty()) { 02269 delete gh.localbboxarray[i]; 02270 gh.localbboxarray[i] = 0 ; 02271 } 02272 } 02273 02274 return ifs; 02275 } 02276 02277 #ifdef DAGH_IOV 02278 void WriteStream(GridHierarchy& GH, RawTCPport* Server, 02279 const GridBoxList& cgbl) 02280 { 02281 if (&cgbl == GridBoxListNULL) return; 02282 02283 GridBoxList &gbl = (GridBoxList &) cgbl; 02284 union record *tmpcur == gbl.currec(); 02285 02286 char buf[2048]; 02287 ostrstream os(buf,sizeof(buf),ios::out); 02288 02289 const int time = GH.getCurrentTime(GH.coarselevel()); 02290 const int model = 2; 02291 GridBox* gb = 0; 02292 for (gb = gbl.first();gb;gb=gbl.next()){ 02293 int owner = gb->gbOwner(); 02294 // for(int i=gb->gbFineLev();i<=gb->gbFineLev();i+=gb->gbLevStep()) { 02295 // os << time << " "; 02296 // os << GH.levelindex(i) << " "; 02297 // os << model << " "; 02298 // BBox bb = gb->gbBBox(i); 02299 // os << bb.lower(0) << " " 02300 // << bb.lower(1) << " "; 02301 // os << bb.upper(0) + bb.stepsize(0) << " " 02302 // << bb.upper(1) + bb.stepsize(1) << " "; 02303 // os << bb.stepsize(0) << " " << bb.stepsize(1) << " "; 02304 // unsigned color = 0; 02305 // color = (((GH.levelindex(i)+1) << 16) | ((owner+1) << 8) | 0); 02306 // os << color; 02307 // os << "\n"; 02308 // } 02309 } 02310 02311 #include <unistd.h> 02312 sleep(10); 02313 char ibuf[10]; 02314 Server->read(ibuf,sizeof(ibuf)); 02315 Server->write(buf,sizeof(buf)); 02316 #ifdef DEBUG_PRINT 02317 comm_service::log() << "Writing on socket...." << endl << flush; 02318 comm_service::log() << buf << flush; 02319 #endif 02320 gbl.setcurrec(tmpcur); 02321 } 02322 #endif
Quickstart Users Guide Programmers Reference Installation Examples Download
AMROC Main Home Contactlast update: 06/01/04