Blockstructured Adaptive Mesh Refinement in object-oriented C++
00001 #ifndef _included_GridDataBlock3_c 00002 #define _included_GridDataBlock3_c 00003 00009 template <class Type> 00010 GridDataBlock(3)<Type>::GridDataBlock(3)(GridFunctionVoid& gf, 00011 GridHierarchy& gh, 00012 GridTable& gt, 00013 const GhostInteraction& gi, 00014 const int midx, 00015 const GridBox& gb, 00016 const int time, 00017 const int level, 00018 const int bwidth, 00019 BBoxList* bndrybbl, 00020 BBoxList* prolongbbl, 00021 const int extghwidth, 00022 const short* olap, 00023 const short *sten, 00024 const int align, 00025 const int mindex, 00026 const int cflag, 00027 const GridDataBlock(3)<Type>* gdbtmpl) 00028 : gfid(gf.GF_Id()), timenum(time), levelnum(level), myindex(midx), 00029 gdb_parent_info(0), gdb_parent_index(0), gdb_child_info(0), gdb_child_index(0), 00030 comm_flag(cflag), maxindex(mindex), 00031 gdb_write_info(0), gdb_read_info(0), gdb_data_rcv(0), 00032 gtable(gt), dagh(gh) 00033 { 00034 00035 const int myrank = 3; 00036 reuse = (gdbtmpl == (GridDataBlock(3)<Type>*) 0) ? 00037 DAGHFalse : DAGHTrue; 00038 00039 const int daghrank = dagh.rank; 00040 sten_rad = new short[2*daghrank]; 00041 00042 register int i; 00043 for ( i = 0 ; i < myrank ; i++ ) 00044 ranks[i] = i; 00045 for ( i = 0 ; i < 2*daghrank ; i++ ) { 00046 if (i<2*myrank) { 00047 sten_rad[i] = sten[i]; 00048 bndryindex[i] = 0; 00049 bndrybboxlist[i] = (BBoxList*) 0; 00050 prolongflag[i] = DAGHFalse; 00051 } 00052 else 00053 sten_rad[i] = 0; 00054 } 00055 00056 if (reuse == DAGHFalse) { 00057 00058 short *dagh_rad = (short *)0; 00059 short *aligned_olap = (short *)0; 00060 if (align != DAGH_All) { 00061 gdbSetRanks(myrank, align, ranks); 00062 dagh_rad = new short[2*daghrank]; 00063 aligned_olap = new short[2*daghrank]; 00064 for (i = 0 ; i < 2*daghrank ; i++) { 00065 dagh_rad[i] = 0; 00066 aligned_olap[i] = 0; 00067 } 00068 for (i = 0 ; i < myrank ; i++) { 00069 dagh_rad[2*ranks[i]] = sten[2*i]; 00070 dagh_rad[2*ranks[i]+1] = sten[2*i+1]; 00071 aligned_olap[i] = olap[ranks[i]]; 00072 } 00073 } 00074 else { 00075 dagh_rad = sten_rad; 00076 aligned_olap = (short *) olap; 00077 } 00078 00079 BBox dagh_interior_bbox = gf.usedbbox(gb, level, DAGH_All); 00080 BBox dagh_merged_bbox = dagh_interior_bbox; 00081 dagh_merged_bbox.growbydim(dagh_rad); 00082 00083 interior_bbox = gf.usedbbox(gb, level, align); 00084 merged_bbox = interior_bbox; 00085 merged_bbox.growbydim(sten_rad); 00086 00087 gdbSetUpBoundaries(bwidth,bndrybbl,prolongbbl,aligned_olap); 00088 gdbSetUpMain(extghwidth); 00089 gdbSetUpLevelInteractionInfo(gf,aligned_olap, align); 00090 00091 if (comm_flag == DAGHTrue) { 00092 const int pnum = comm_service::proc_num(); 00093 00094 /* Allocate memory for the communication stuff */ 00095 gdb_write_info = new GDB_Interaction** [pnum]; 00096 gdb_read_info = new GDB_Interaction** [pnum]; 00097 gdb_write_index = new int* [pnum]; 00098 gdb_read_index = new int* [pnum]; 00099 00100 for (register int p=0; p<pnum; p++) { 00101 gdb_write_info[p] = (GDB_Interaction**)0; 00102 gdb_read_info[p] = (GDB_Interaction**)0; 00103 gdb_write_index[p] = (int*)0; 00104 gdb_read_index[p] = (int*)0; 00105 } 00106 00107 gdbSetUpGhostInteractionInfo(gf,dagh_interior_bbox,dagh_merged_bbox, 00108 gi,olap,dagh_rad,align); 00109 } 00110 if (align != DAGH_All) { 00111 delete [] dagh_rad; 00112 delete [] aligned_olap; 00113 } 00114 } 00115 00116 else { /* reuse == DAGHTrue */ 00117 00118 merged_bbox = gdbtmpl->merged_bbox; 00119 interior_bbox = gdbtmpl->interior_bbox; 00120 00121 for (i = 0 ; i < 2*myrank ; i++) { 00122 bndryindex[i] = gdbtmpl->bndryindex[i]; 00123 bndrybboxlist[i] = gdbtmpl->bndrybboxlist[i]; 00124 prolongflag[i] = gdbtmpl->prolongflag[i]; 00125 prolongbbox[i] = gdbtmpl->prolongbbox[i]; 00126 } 00127 gdbSetUpMain(extghwidth); 00128 00129 gdb_parent_index = gdbtmpl->gdb_parent_index; 00130 gdb_parent_info = gdbtmpl->gdb_parent_info; 00131 gdb_child_index = gdbtmpl->gdb_child_index; 00132 gdb_child_info = gdbtmpl->gdb_child_info; 00133 00134 if (comm_flag == DAGHTrue) { 00135 gdb_write_info = gdbtmpl->gdb_write_info; 00136 gdb_read_info = gdbtmpl->gdb_read_info; 00137 gdb_write_index = gdbtmpl->gdb_write_index; 00138 gdb_read_index = gdbtmpl->gdb_read_index; 00139 } 00140 } 00141 } 00142 00143 /* 00144 ************************************************************************* 00145 * * 00146 * GridDataBlock(3)::~GridDataBlock(3) (void) * 00147 * * 00148 ************************************************************************* 00149 */ 00150 template <class Type> 00151 GridDataBlock(3)<Type>::~GridDataBlock(3) (void) 00152 { 00153 if (reuse == DAGHFalse) { 00154 for (register int i = 0 ; i < 2*3 ; i++) 00155 if (bndrybboxlist[i]) delete bndrybboxlist[i]; 00156 00157 if (comm_flag == DAGHTrue) { 00158 const int pnum = comm_service::proc_num(); 00159 for (register int p=0;p<pnum;p++) { 00160 if (gdb_write_info[p] && gdb_write_index[p]) { 00161 for (register int ad=0; ad<DAGHMaxAxis*DAGHMaxDirs; ad++) 00162 if (gdb_write_info[p][ad]) delete [] gdb_write_info[p][ad]; 00163 delete [] gdb_write_info[p]; 00164 delete [] gdb_write_index[p]; 00165 } 00166 if (gdb_read_info[p] && gdb_read_index[p]) { 00167 for (register int ad=0; ad<DAGHMaxAxis*DAGHMaxDirs; ad++) 00168 if (gdb_read_info[p][ad]) delete [] gdb_read_info[p][ad]; 00169 delete [] gdb_read_info[p]; 00170 delete [] gdb_read_index[p]; 00171 } 00172 } 00173 00174 if (gdb_write_info) delete [] gdb_write_info; 00175 if (gdb_read_info) delete [] gdb_read_info; 00176 if (gdb_write_index) delete [] gdb_write_index; 00177 if (gdb_read_index) delete [] gdb_read_index; 00178 00179 if (gdb_data_rcv) delete gdb_data_rcv; 00180 } 00181 if (gdb_parent_info) delete [] gdb_parent_info; 00182 if (gdb_child_info) delete [] gdb_child_info; 00183 } 00184 delete [] sten_rad; 00185 data.deallocate(); 00186 } 00187 00188 /* 00189 ************************************************************************* 00190 * * 00191 * Set up GDB internals * 00192 * * 00193 ************************************************************************* 00194 */ 00195 template <class Type> 00196 void GridDataBlock(3)<Type>::intersectgbl(GridFunctionVoid& gf, 00197 GridBoxList& gbl, 00198 const BBox& bbtest, 00199 const int& level, 00200 GridBoxList& resgbl, 00201 const short* olap, 00202 const short* sten, 00203 const int& align) { 00204 00205 const int me = comm_service::proc_me(); 00206 00207 const Coords& s = bbtest.stepsize(); 00208 GridBoxList workgbl; 00209 for ( register GridBox* gb = gbl.first(); gb; gb = gbl.next()) { 00210 if (gb->gbIndex()==myindex && gb->gbOwner()==me && level==levelnum) continue; 00211 BBox bb = gf.usedbbox(*gb, level, align); 00212 if (sten) bb.growbydim(sten); 00213 00214 Coords& bs = bb.stepsize(); 00215 for (register int d=0; d<bb.rank; d++) 00216 if (bs(d)>s(d)) bb.refine(d,bs(d)/s(d),olap[d]); 00217 else if (bs(d)<s(d)) bb.coarsen(d,s(d)/bs(d)); 00218 00219 workgbl.add(GridBox(gb->gbOwner(),gb->gbIndex(),bb)); 00220 } 00221 00222 workgbl.intersect(bbtest,resgbl); 00223 } 00224 00225 /*************************************************************************/ 00226 /* Set up arrays for interaction with grids of a different level on same processor */ 00227 /*************************************************************************/ 00228 template <class Type> 00229 void GridDataBlock(3)<Type>::gdbSetUpLevelInteractionInfo(GridFunctionVoid& gf, 00230 const short* olap, 00231 const int& align) { 00232 short *psten_rad = new short[2*dagh.rank]; 00233 for (register int i=0; i<2*dagh.rank; i++) 00234 psten_rad[i] = Max(sten_rad[i]-1,0); 00235 GridBoxList** lgbl = dagh.lgbl(); 00236 00237 /* Create list of parents - overlaps with local grids of levelnum-1 */ 00238 if (levelnum>0 && lgbl[levelnum-1] && !lgbl[levelnum-1]->isempty()) { 00239 GridBoxList lpgbl; 00240 intersectgbl(gf,*lgbl[levelnum-1],merged_bbox,levelnum-1,lpgbl, 00241 olap,psten_rad,align); 00242 gdb_parent_index = lpgbl.number(); 00243 if (gdb_parent_index > 0) { 00244 gdb_parent_info = new GDB_Interaction[gdb_parent_index]; 00245 int cnt=0; 00246 for (register GridBox* gb = lpgbl.first(); gb; gb = lpgbl.next(), cnt++) { 00247 gdb_parent_info[cnt].idx = gb->gbIndex(); 00248 gdb_parent_info[cnt].bbox = merged_bbox*gb->gbBBox(); 00249 #ifdef DEBUG_PRINT 00250 assert (!gdb_parent_info[cnt].bbox.empty()); 00251 #endif 00252 } 00253 } 00254 } 00255 00256 /* Create list of children - overlaps with local grids of levelnum+1 */ 00257 if (levelnum<dagh.totallevels()-1 && lgbl[levelnum+1] && !lgbl[levelnum+1]->isempty()) { 00258 BBox pmerged_bbox = growbydim(interior_bbox,psten_rad); 00259 GridBoxList lpgbl; 00260 intersectgbl(gf,*lgbl[levelnum+1],pmerged_bbox,levelnum+1,lpgbl, 00261 olap,sten_rad,align); 00262 gdb_child_index = lpgbl.number(); 00263 if (gdb_child_index > 0) { 00264 gdb_child_info = new GDB_Interaction[gdb_child_index]; 00265 int cnt=0; 00266 for (register GridBox* gb = lpgbl.first(); gb; gb = lpgbl.next(), cnt++) { 00267 gdb_child_info[cnt].idx = gb->gbIndex(); 00268 gdb_child_info[cnt].bbox = pmerged_bbox*gb->gbBBox(); 00269 #ifdef DEBUG_PRINT 00270 assert (!gdb_child_info[cnt].bbox.empty()); 00271 #endif 00272 } 00273 } 00274 } 00275 delete [] psten_rad; 00276 } 00277 00278 /*************************************************************************/ 00279 /* Set flags defining external and adaptive boundaries */ 00280 /*************************************************************************/ 00281 template <class Type> 00282 void GridDataBlock(3)<Type>::gdbSetUpBoundaries(const int& bwidth, 00283 BBoxList* bndrybbl, 00284 BBoxList* prolongbbl, 00285 const short* olap) { 00286 const int myrank = 3; 00287 const int crslevel = dagh.coarselevel(); 00288 if (bwidth<=0) return; 00289 00290 for (register int r=0; r<2*myrank; r++) { 00291 const int d = r/2; 00292 00293 BBox bb(merged_bbox); 00294 if (r%2) 00295 bb.lower(d) = interior_bbox.upper(d) + interior_bbox.stepsize(d); 00296 else 00297 bb.upper(d) = interior_bbox.lower(d) - interior_bbox.stepsize(d); 00298 00299 if (bndrybbl) { 00300 bndrybboxlist[r] = new BBoxList; 00301 bndrybboxlist[r]->add(bb); 00302 (*bndrybboxlist[r]) *= (*bndrybbl); 00303 if (bndrybboxlist[r]->isempty()) { 00304 delete bndrybboxlist[r]; 00305 bndrybboxlist[r] = (BBoxList*) 0; 00306 bndryindex[r] = 0; 00307 } 00308 else { 00309 bndrybboxlist[r]->mergeboxes(olap); 00310 bndryindex[r] = bndrybboxlist[r]->number(); 00311 } 00312 } 00313 00314 if (levelnum > crslevel && prolongbbl) { 00315 BBox* pbb = (BBox*) 0; 00316 for (pbb=prolongbbl->first(); pbb; pbb=prolongbbl->next()) { 00317 BBox pbbtest(bb); 00318 pbbtest *= *pbb; 00319 if (!pbbtest.empty()) { 00320 prolongflag[r] = DAGHTrue; 00321 prolongbbox[r] += pbbtest; 00322 if (prolongbbox[r] == bb) break; 00323 } 00324 } 00325 } 00326 } 00327 } 00328 00329 /*************************************************************************/ 00330 00331 /*************************************************************************/ 00332 /* Add communication information is a particular axis & direction */ 00333 /* Allocate memory if required */ 00334 /*************************************************************************/ 00335 template <class Type> 00336 void GridDataBlock(3)<Type>::gdbAddGhostInteractionInfo( 00337 const int axis, 00338 const int dir, 00339 const BBox& therb, 00340 const BBox& thewb, 00341 const BBox& hisbb, 00342 const int owner, 00343 const int idx, 00344 BBox*** setup_write_info, 00345 BBox*** setup_read_info) { 00346 00347 const int inter_cnt = DAGHMaxAxis * DAGHMaxDirs * maxindex; 00348 const int index = ( DAGHMaxDirs * maxindex * axis ) + ( maxindex * dir ) + idx; 00349 const int hisindex = ( DAGHMaxDirs * maxindex * axis ) + 00350 ( maxindex * DAGHHisDir(dir) ) + idx; 00351 00352 if (!thewb.empty()) { /* Write Info */ 00353 if (!setup_write_info[owner]) { 00354 setup_write_info[owner] = new BBox* [inter_cnt]; 00355 for ( register int j = 0 ; j < inter_cnt ; j++ ) 00356 setup_write_info[owner][j] = (BBox*)0; 00357 } 00358 if (!gdb_write_index[owner]) { 00359 gdb_write_index[owner] = new int[DAGHMaxAxis*DAGHMaxDirs]; 00360 for (register int ad=0; ad<DAGHMaxAxis*DAGHMaxDirs; ad++) 00361 gdb_write_index[owner][ad] = 0; 00362 } 00363 if (!setup_write_info[owner][index]) { 00364 setup_write_info[owner][index] = new BBox; 00365 gdb_write_index[owner][DAGHMaxDirs*axis+dir]++; 00366 } 00367 00368 *setup_write_info[owner][index] += thewb; 00369 #ifdef DEBUG_PRINT 00370 assert (!setup_write_info[owner][index]->empty()); 00371 #endif 00372 } 00373 00374 if (!therb.empty()) { /* Read Info */ 00375 if (!setup_read_info[owner]) { 00376 setup_read_info[owner] = new BBox* [inter_cnt]; 00377 for ( register int j = 0 ; j < inter_cnt ; j++ ) 00378 setup_read_info[owner][j] = (BBox*)0; 00379 } 00380 if (!gdb_read_index[owner]) { 00381 gdb_read_index[owner] = new int[DAGHMaxAxis*DAGHMaxDirs]; 00382 for (register int ad=0; ad<DAGHMaxAxis*DAGHMaxDirs; ad++) 00383 gdb_read_index[owner][ad] = 0; 00384 } 00385 if (!setup_read_info[owner][hisindex]) { 00386 setup_read_info[owner][hisindex] = new BBox; 00387 gdb_read_index[owner][DAGHMaxDirs*axis+DAGHHisDir(dir)]++; 00388 } 00389 00390 *setup_read_info[owner][hisindex] += therb; 00391 #ifdef DEBUG_PRINT 00392 assert (!setup_read_info[owner][hisindex]->empty()); 00393 #endif 00394 } 00395 } 00396 00397 00398 /*************************************************************************/ 00399 /* Setup ghost interactions info */ 00400 /*************************************************************************/ 00401 template <class Type> 00402 void GridDataBlock(3)<Type>::gdbSetUpGhostInteractionInfo(GridFunctionVoid& gf, 00403 const BBox& di_bbox, 00404 const BBox& dm_bbox, 00405 const GhostInteraction& gi, 00406 const short* olap, 00407 const short* dsten_rad, 00408 const int align) { 00409 GridBoxList** ggbl = dagh.ggbl(); 00410 GridBoxList mcgbl; 00411 intersectgbl(gf,*ggbl[levelnum],dm_bbox,levelnum,mcgbl,olap,0,DAGH_All); 00412 if (mcgbl.isempty()) return; 00413 00414 register int p; 00415 const int pnum = comm_service::proc_num(); 00416 BBox*** setup_write_info = new BBox** [pnum]; 00417 BBox*** setup_read_info = new BBox** [pnum]; 00418 for (p=0; p<pnum; p++) { 00419 setup_write_info[p] = (BBox**)0; 00420 setup_read_info[p] = (BBox**)0; 00421 } 00422 00423 const int myrank = 3 ; 00424 const int ti = gi.total_interactions(); 00425 const int simple = gi.simple(); 00426 00427 register int r = 0, dr = 0; 00428 00429 register GridBox* gb = 0; 00430 register int i = 0; 00431 00432 for ( r = 0, dr = 0; r < DAGHMaxAxis ; ++r ) { 00433 if ( r >= myrank && r != DAGH_All ) continue; 00434 dr = ( r < myrank ) ? ranks[r] : r ; 00435 00436 short const *bi = gi.interactions(dr,DAGH_Backward); 00437 short const *fi = gi.interactions(dr,DAGH_Forward); 00438 short const *bothi = gi.interactions(dr,DAGH_Both); 00439 00440 for ( i = 0 ; i < ti ; i++ ) { 00441 if( bi[i] != DAGHTrue && fi[i] != DAGHTrue ) continue; 00442 00443 BBox rb = gi.Ibbox(di_bbox, i, dsten_rad); 00444 if (align != DAGH_All) 00445 gdbAlignBBox(myrank, rb, align); 00446 00447 if ( !simple || r >= myrank ) { 00448 for ( gb = mcgbl.first(); gb ; gb = mcgbl.next() ) { 00449 const int idx = gb->gbIndex(); 00450 const int owner = gb->gbOwner(); 00451 BBox mbb = gb->gbBBox(); 00452 BBox wb(di_bbox * gi.Ibbox(mbb,gi.complement(i),dsten_rad)); 00453 00454 if (align != DAGH_All) { 00455 gdbAlignBBox(myrank, wb, align); 00456 gdbAlignBBox(myrank, mbb, align); 00457 } 00458 00459 const BBox thewb(growbydim(mbb,sten_rad) * wb); 00460 const BBox therb(mbb * rb); 00461 00462 if ( !simple && bi[i] == DAGHTrue ) { /* Backward... */ 00463 gdbAddGhostInteractionInfo(r,DAGH_Backward,therb,thewb,mbb,owner,idx, 00464 setup_write_info, setup_read_info); 00465 } 00466 if ( !simple && fi[i] == DAGHTrue ) { /* Forward... */ 00467 gdbAddGhostInteractionInfo(r,DAGH_Forward,therb,thewb,mbb,owner,idx, 00468 setup_write_info, setup_read_info); 00469 } 00470 if ( r >= myrank && bothi[i] == DAGHTrue ) { /* Both... */ 00471 gdbAddGhostInteractionInfo(r,DAGH_Both,therb,thewb,mbb,owner,idx, 00472 setup_write_info, setup_read_info); 00473 } 00474 } 00475 } 00476 } 00477 } 00478 00479 /* Setup new info-fields with arbitrary length. That saves execution time */ 00480 /* and memory. */ 00481 for ( p = 0 ; p < pnum ; p++ ) { 00482 00483 /* Setup gdb_write_info from setup_write_info */ 00484 if (setup_write_info[p]) { 00485 if (gdb_write_index[p]) { 00486 gdb_write_info[p] = new GDB_Interaction* [DAGHMaxAxis*DAGHMaxDirs]; 00487 for (int axis=0; axis<DAGHMaxAxis; axis++) 00488 for (int dir=0; dir<DAGHMaxDirs; dir++) { 00489 register int ad = DAGHMaxDirs*axis+dir; 00490 if (gdb_write_index[p][ad]>0) { 00491 gdb_write_info[p][ad] = new GDB_Interaction[gdb_write_index[p][ad]]; 00492 register int cnt = 0; 00493 for (int idx=0; idx<maxindex; idx++) { 00494 register int j = ( DAGHMaxDirs * maxindex * axis ) + ( maxindex * dir ) + idx; 00495 if (setup_write_info[p][j]) { 00496 gdb_write_info[p][ad][cnt] = GDB_Interaction(idx,*setup_write_info[p][j]); 00497 delete setup_write_info[p][j]; 00498 cnt++; 00499 } 00500 } 00501 } 00502 else 00503 gdb_write_info[p][ad] = (GDB_Interaction*)0; 00504 } 00505 } 00506 delete [] setup_write_info[p]; 00507 } 00508 00509 /* Setup gdb_read_info from setup_read_info */ 00510 if (setup_read_info[p]) { 00511 if (gdb_read_index[p]) { 00512 gdb_read_info[p] = new GDB_Interaction* [DAGHMaxAxis*DAGHMaxDirs]; 00513 for (int axis=0; axis<DAGHMaxAxis; axis++) 00514 for (int dir=0; dir<DAGHMaxDirs; dir++) { 00515 register int ad = DAGHMaxDirs*axis+dir; 00516 if (gdb_read_index[p][ad]>0) { 00517 gdb_read_info[p][ad] = new GDB_Interaction[gdb_read_index[p][ad]]; 00518 register int cnt = 0; 00519 for (int idx=0; idx<maxindex; idx++) { 00520 register int j = ( DAGHMaxDirs * maxindex * axis ) + ( maxindex * dir ) + idx; 00521 if (setup_read_info[p][j]) { 00522 gdb_read_info[p][ad][cnt] = GDB_Interaction(idx,*setup_read_info[p][j]); 00523 delete setup_read_info[p][j]; 00524 cnt++; 00525 } 00526 } 00527 } 00528 else 00529 gdb_read_info[p][ad] = (GDB_Interaction*)0; 00530 } 00531 } 00532 delete [] setup_read_info[p]; 00533 } 00534 } 00535 00536 delete [] setup_write_info; 00537 delete [] setup_read_info; 00538 } 00539 00540 /*************************************************************************/ 00541 00542 /* 00543 ************************************************************************* 00544 * * 00545 * Set up storage for the Main Hierarchy * 00546 * * 00547 ************************************************************************* 00548 */ 00549 template <class Type> 00550 void GridDataBlock(3)<Type>::gdbSetUpMain(const int extghwidth) { 00551 const int myrank = 3; 00552 00553 BBox bb(merged_bbox); 00554 if (extghwidth > 0) 00555 for (register int r=0; r<myrank; r++) { 00556 bb.lower(r) -= bb.stepsize(r)*extghwidth; 00557 bb.upper(r) += bb.stepsize(r)*extghwidth; 00558 } 00559 data.allocate(bb); 00560 #ifdef DEBUG_PRINT_GDB 00561 ( comm_service::log() << "gdbSetUpMain" << "[" << gfid << "] " << bb << " " << endl ).flush(); 00562 #endif 00563 } 00564 00565 /******************************************************************/ 00566 /* Ghost Communications */ 00567 /******************************************************************/ 00568 template <class Type> 00569 int GridDataBlock(3)<Type>::gdbWriteGhosts(const int proc, 00570 const int time_value, 00571 const int axis, 00572 const int dir, 00573 GridDataBucket<Type>& gdb, 00574 const int at) { 00575 #ifdef DEBUG_PRINT 00576 assert (dir==DAGH_Backward || dir==DAGH_Forward || axis==DAGH_All); 00577 #endif 00578 00579 const int me = comm_service::proc_me(); 00580 00581 #ifdef DEBUG_PRINT_GDB_COMM 00582 ( comm_service::log() << "gdbWriteGhosts:" << "[" << proc << "]" 00583 << "[" << me << "]" 00584 << "[" << timenum << "]" << "[" << levelnum << "]" 00585 << "[" << axis << "]" << "[" << dir << "]" 00586 << endl ).flush(); 00587 #endif 00588 00589 GDB_Interaction* gdbi; 00590 int ngdbi; 00591 00592 int cnt = 0; 00593 if (gdb_write_info[proc] && gdb_write_index[proc]) { 00594 register int ad = DAGHMaxDirs*axis+dir; 00595 if ((ngdbi=gdb_write_index[proc][ad])>0 && 00596 (gdbi=gdb_write_info[proc][ad])) { 00597 for ( register int i = 0, idx = at ; i<ngdbi; i++ ) { 00598 #ifdef DEBUG_PRINT_GDB_COMM 00599 ( comm_service::log() << "Writing { " << gdbi[i] << " }" << endl ).flush(); 00600 #endif 00601 gdb.add(gdbi[i].bbox, gfid, timenum, time_value, levelnum, gdbi[i].idx, me, idx); 00602 griddata().PackRegion(gdb.data(idx), gdbi[i].bbox); 00603 cnt++; idx++; 00604 } 00605 } 00606 } 00607 return cnt; 00608 } 00609 00610 /******************************************************************/ 00611 /* Data Communications */ 00612 /******************************************************************/ 00613 template <class Type> 00614 void GridDataBlock(3)<Type>::gdbWriteData(const int time_value, 00615 GridDataBucket<Type>& gdb, 00616 const int at) { 00617 00618 const int me = comm_service::proc_me(); 00619 const BBox bb = interiorbox(); 00620 00621 #ifdef DEBUG_PRINT_GDB_COMM 00622 ( comm_service::log() << "gdbWriteData:" << "[" << me << "]" 00623 << "[" << time_value << "]" << "[" << timenum << "]" << "[" 00624 << levelnum << "]" << bb << endl ).flush(); 00625 #endif 00626 00627 gdb.add(bb, gfid, timenum, time_value, levelnum, myindex, me, at); 00628 griddata().PackRegion(gdb.data(at), bb); 00629 } 00630 00631 template <class Type> 00632 void GridDataBlock(3)<Type>::gdbWriteData(const int time_value, 00633 const BBox& where, 00634 GridDataBucket<Type>& gdb, 00635 const int at) { 00636 00637 const int me = comm_service::proc_me(); 00638 const BBox bb = interiorbox() * where; 00639 00640 #ifdef DEBUG_PRINT_GDB_COMM 00641 ( comm_service::log() << "gdbWriteData:" << "[" << me << "]" 00642 << "[" << time_value << "]" << "[" << timenum << "]" << "[" 00643 << levelnum << "]" << bb << endl ).flush(); 00644 #endif 00645 00646 gdb.add(bb, gfid, timenum, time_value, levelnum, myindex, me, at); 00647 griddata().PackRegion(gdb.data(at), bb); 00648 } 00649 00650 /******************************************************************/ 00651 /* Debugging */ 00652 /******************************************************************/ 00653 template <class Type> 00654 int GridDataBlock(3)<Type>::MemoryUsage() { 00655 int mem = 0; 00656 mem += sizeof(GridDataBlock(3)<Type>); 00657 mem += data.bbox().size()*sizeof(Type); 00658 if (reuse == DAGHFalse) { 00659 for (register int i = 0 ; i < 2*3 ; i++) 00660 if (bndrybboxlist[i] && bndryindex[i]>0) 00661 mem += bndryindex[i]*sizeof(BBox); 00662 00663 if (gdb_parent_info && gdb_parent_index>0) 00664 mem += gdb_parent_index*sizeof(GDB_Interaction); 00665 if (gdb_child_info && gdb_child_index>0) 00666 mem += gdb_child_index*sizeof(GDB_Interaction); 00667 00668 if (comm_flag == DAGHTrue) { 00669 for (int i=0; i<comm_service::proc_num(); i++) { 00670 if (gdb_write_info[i] && gdb_write_index[i]) 00671 for (register int ad=0; ad<DAGHMaxAxis*DAGHMaxDirs; ad++) { 00672 mem += (sizeof(GDB_Interaction*)+sizeof(int)) * gdb_write_index[i][ad]; 00673 if (gdb_write_info[i][ad] && gdb_write_index[i][ad]>0) 00674 mem += gdb_write_index[i][ad]*sizeof(GDB_Interaction); 00675 } 00676 if (gdb_read_info[i] && gdb_read_index[i]) 00677 for (register int ad=0; ad<DAGHMaxAxis*DAGHMaxDirs; ad++) { 00678 mem += (sizeof(GDB_Interaction*)+sizeof(int)) * gdb_read_index[i][ad]; 00679 if (gdb_read_info[i][ad] && gdb_read_index[i][ad]>0) 00680 mem += gdb_read_index[i][ad]*sizeof(GDB_Interaction); 00681 } 00682 } 00683 } 00684 } 00685 return mem; 00686 } 00687 00688 /******************************************************************/ 00689 /* Overloaded output */ 00690 /******************************************************************/ 00691 template <class Type> 00692 void GridDataBlock(3)<Type>::gdbPrintData(ostream& os) const { 00693 const int myrank = 3; 00694 00695 os << "GridDataBlock(3)<Type>: "; 00696 os << "[GFid:" << gfid << "]" ; 00697 os << "[Time:" << timenum << "]"; 00698 os << "[Level:" << levelnum << "]"; 00699 os << "[MyIndex:" << myindex << "]"; 00700 os << endl; 00701 os << "[merged_bbox:" << merged_bbox << "]"; 00702 os << "[interior_bbox:" << interior_bbox << "]"; 00703 os << endl; 00704 00705 os << "[Boundary Indices: "; 00706 register int b; 00707 for (b = 0 ; b < 2*myrank ; b++) 00708 os << bndryindex[b] << " "; 00709 os << "]" << endl; 00710 00711 os << "[Boundary BBoxes:" << endl; 00712 for (b = 0 ; b < 2*myrank ; b++) 00713 if (has_externalboundary(b)) 00714 os << " [" << b << ":" << *bndrybboxlist[b] << "]" << endl; 00715 os << "]" << endl; 00716 00717 os << "[Prolong Flags: "; 00718 for (b = 0 ; b < 2*myrank ; b++) 00719 os << prolongflag[b] << " "; 00720 os << "]" << endl; 00721 00722 os << "[Prolong BBoxes:" << endl; 00723 for (b = 0 ; b < 2*myrank ; b++) 00724 if (has_adaptiveboundary(b)) 00725 os << " [" << b << ":" << prolongbbox[b] << "]" << endl; 00726 os << "]" << endl; 00727 00728 os << "Storage:" << endl; 00729 os << " " << data.bbox() << endl; 00730 00731 if (gdb_parent_info && gdb_parent_index) { 00732 os << "Parent Interactions: " << endl; 00733 for (register int m=0; m<gdb_parent_index; m++) 00734 os << " gdb_parent_info[" << m << "]" 00735 << gdb_parent_info[m] << endl; 00736 } 00737 00738 if (gdb_child_info && gdb_child_index) { 00739 os << "Child Interactions: " << endl; 00740 for (register int m=0; m<gdb_child_index; m++) 00741 os << " gdb_child_info[" << m << "]" 00742 << gdb_child_info[m] << endl; 00743 } 00744 00745 const int np = comm_service::proc_num(); 00746 if (gdb_write_info) { 00747 os << "Write Interactions: " << endl; 00748 for (register int n=0; n<np; n++) { 00749 if (gdb_write_info[n] && gdb_write_index[n]) 00750 for (register int ad=0; ad<DAGHMaxAxis*DAGHMaxDirs; ad++) 00751 if (gdb_write_info[n][ad] && gdb_write_index[n][ad]>0) 00752 for (register int m=0; m<gdb_write_index[n][ad]; m++) 00753 os << " gdb_write_info[" << n << "][" << ad << "][" << m << "]" 00754 << gdb_write_info[n][ad][m] << endl; 00755 } 00756 } 00757 if (gdb_read_info) { 00758 os << "Read Interactions: " << endl; 00759 for (register int n=0; n<np; n++) { 00760 if (gdb_read_info[n] && gdb_read_index[n]) 00761 for (register int ad=0; ad<DAGHMaxAxis*DAGHMaxDirs; ad++) 00762 if (gdb_read_info[n][ad] && gdb_read_index[n][ad]>0) 00763 for (register int m=0; m<gdb_read_index[n][ad]; m++) 00764 os << " gdb_read_info[" << n << "][" << ad << "][" << m << "]" 00765 << gdb_read_info[n][ad][m] << endl; 00766 } 00767 } 00768 } 00769 00770 template <class Type> 00771 ostream& operator << (ostream& os, const GridDataBlock(3)<Type>& gdb) { 00772 00773 if (&gdb == (GridDataBlock(3)<Type> *) NULL) return os; 00774 gdb.gdbPrintData(os); 00775 return os; 00776 } 00777 00778 /******************************************************************/ 00779 /* binary output for checkpointing */ 00780 /******************************************************************/ 00781 template <class Type> 00782 ofstream& operator << (ofstream& ofs, const GridDataBlock(3)<Type>& gdb) { 00783 00784 if (&gdb == (GridDataBlock(3)<Type> *) NULL) return ofs; 00785 00786 ofs.write((char*)&gdb.timenum,sizeof(short)); 00787 ofs.write((char*)&gdb.levelnum,sizeof(short)); 00788 00789 ofs << gdb.griddata(); 00790 00791 return ofs; 00792 } 00793 00794 template <class Type> 00795 ifstream& operator >> (ifstream& ifs, GridDataBlock(3)<Type>& gdb) { 00796 00797 if (&gdb == (GridDataBlock(3)<Type> *) NULL) return ifs; 00798 00799 short tmptimenum, tmplevelnum; 00800 ifs.read((char*)&tmptimenum,sizeof(short)); 00801 ifs.read((char*)&tmplevelnum,sizeof(short)); 00802 00803 #ifdef DEBUG_PRINT 00804 assert (tmptimenum == gdb.timenum && tmplevelnum == gdb.levelnum); 00805 #endif 00806 ifs >> gdb.griddata(); 00807 00808 return ifs; 00809 } 00810 00811 template <class Type> 00812 strstream& operator << (strstream& ofs, const GridDataBlock(3)<Type>& gdb) { 00813 00814 if (&gdb == (GridDataBlock(3)<Type> *) NULL) return ofs; 00815 00816 ofs.write((char*)&gdb.timenum,sizeof(short)); 00817 ofs.write((char*)&gdb.levelnum,sizeof(short)); 00818 00819 ofs << gdb.griddata(); 00820 00821 return ofs; 00822 } 00823 00824 template <class Type> 00825 strstream& operator >> (strstream& ifs, GridDataBlock(3)<Type>& gdb) { 00826 00827 if (&gdb == (GridDataBlock(3)<Type> *) NULL) return ifs; 00828 00829 short tmptimenum, tmplevelnum; 00830 ifs.read((char*)&tmptimenum,sizeof(short)); 00831 ifs.read((char*)&tmplevelnum,sizeof(short)); 00832 00833 #ifdef DEBUG_PRINT 00834 assert (tmptimenum == gdb.timenum && tmplevelnum == gdb.levelnum); 00835 #endif 00836 ifs >> gdb.griddata(); 00837 00838 return ifs; 00839 } 00840 00841 00842 #endif 00843 00844
Quickstart Users Guide Programmers Reference Installation Examples Download
AMROC Main Home Contactlast update: 06/01/04