// $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetSlab/src/Attic/carpetslab.cc,v 1.10 2001/07/04 12:29:52 schnetter Exp $ #include #include #include #include "cctk.h" #include "Carpet/CarpetLib/src/bbox.hh" #include "Carpet/CarpetLib/src/bboxset.hh" #include "Carpet/CarpetLib/src/dh.hh" #include "Carpet/CarpetLib/src/gdata.hh" #include "Carpet/CarpetLib/src/gh.hh" #include "Carpet/CarpetLib/src/ggf.hh" #include "Carpet/CarpetLib/src/vect.hh" #include "Carpet/Carpet/src/carpet.hh" #include "carpetslab.hh" static const char* rcsid = "$Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetSlab/src/Attic/carpetslab.cc,v 1.10 2001/07/04 12:29:52 schnetter Exp $"; namespace CarpetSlab { using namespace Carpet; void* GetSlab (cGH* const cgh, const int dest_proc, const int n, const int ti, const int hdim, const int origin[/*vdim*/], const int dirs[/*hdim*/], const int stride[/*hdim*/], const int length[/*hdim*/]) { // Check global state assert (reflevel>=0); assert (mglevel>=0); // Save global state int saved_component = component; component = -1; // Check Cactus grid hierarchy assert (cgh); // Check destination processor assert (dest_proc>=-1 && dest_proc=0 && n=0); const int n0 = CCTK_FirstVarIndexI(group); assert (n0>=0); const int var = n - n0; assert (var>=0); // Get info about group cGroup gp; CCTK_GroupData (group, &gp); assert (gp.dim<=dim); assert (CCTK_QueryGroupStorageI(cgh, group)); const int typesize = CCTK_VarTypeSize(gp.vartype); assert (typesize>0); // Check dimension assert (hdim>=0 && hdim<=gp.dim); // Check timelevel const int num_tl = gp.numtimelevels; assert (ti>=0 && ti=0 && origin[d]<=sizes[d]); // } // Check directions for (int dd=0; dd=1 && dirs[dd]<=dim); } // Check stride for (int dd=0; dd0); } // Check length for (int dd=0; dd=0); } // Check extent // for (int dd=0; dd* myhh; const dh* mydd; const generic_gf* myff; switch (gp.grouptype) { case CCTK_SCALAR: abort(); case CCTK_ARRAY: assert (group < (int)arrdata.size()); myhh = arrdata[group].hh; mydd = arrdata[group].dd; assert (var < (int)arrdata[group].data.size()); myff = arrdata[group].data[var]; break; case CCTK_GF: myhh = hh; mydd = Carpet::dd; // dd is int dd above for old C++ compilers assert (group < (int)gfdata.size()); assert (var < (int)gfdata[group].data.size()); myff = gfdata[group].data[var]; break; default: abort(); } assert (myhh); assert (mydd); assert (myff); // Detemine collecting processor const int collect_proc = dest_proc<0 ? 0 : dest_proc; // Determine own rank const int rank = CCTK_MyProc(cgh); // Calculate global size int totalsize = 1; for (int dd=0; ddcomponents(reflevel) > 0) { // Only temporarily component = 0; // Get sample data const generic_data* mydata; mydata = (*myff)(tl, reflevel, component, mglevel); // Stride of data in memory const vect str = mydata->extent().stride(); // Stride of collected data vect hstr = str; for (int dd=0; dd hlb(0); for (int d=0; d hub = hlb; for (int dd=0; dd hextent (hlb, hub, hstr); assert (hextent.num_points() == totalsize); // Create collector data object void* myhdata = rank==collect_proc ? hdata : 0; generic_data* const alldata = mydata->make_typed(); alldata->allocate (hextent, collect_proc, myhdata); // Done with the temporary stuff mydata = 0; component = -1; // Loop over all components, copying data from them assert (component == -1); for (component=0; componentcomponents(reflevel); ++component) { // Get data object mydata = (*myff)(tl, reflevel, component, mglevel); // Calculate overlapping extents const bboxset myextents = ((mydd->boxes[reflevel][component][mglevel].sync_not | mydd->boxes[reflevel][component][mglevel].interior) & hextent); // Loop over overlapping extents for (bboxset::const_iterator ext_iter = myextents.begin(); ext_iter != myextents.end(); ++ext_iter) { // Copy data alldata->copy_from (mydata, *ext_iter); } } // Loop over components component = -1; // Copy result to all processors if (dest_proc == -1) { for (int proc=0; proc* const tmpdata = mydata->make_typed(); tmpdata->allocate (alldata->extent(), proc, myhdata); tmpdata->copy_from (alldata, alldata->extent()); delete tmpdata; } } } // Copy result delete alldata; } // if components>0 // Restore global state component = saved_component; // Success return hdata; } int Hyperslab_GetHyperslab (cGH* const GH, const int target_proc, const int vindex, const int vtimelvl, const int hdim, const int global_startpoint [/*vdim*/], const int directions [/*vdim*/], const int lengths [/*hdim*/], const int downsample [/*hdim*/], void** const hdata, int hsize [/*hdim*/]) { const int gpdim = CCTK_GroupDimFromVarI(vindex); assert (gpdim>=1 && gpdim<=dim); // Check some arguments assert (hdim>=0 && hdim<=dim); // Check output arguments assert (hdata); assert (hsize); // Calculate more convenient representation of the direction int* const dirs = (int*)alloca(hdim * sizeof(int)); // The following if statement is written according to the // definition of "dir". if (hdim==1) { // 1-dimensional hyperslab int mydir = 0; for (int d=0; d0); for (int d=0; d0); for (int d=0; d=0); // Partial argument check assert (global_startpoint[dirs[dd]-1]>=0); assert (global_startpoint[dirs[dd]-1]<=totlen); assert (downsample[dd]>0); hsize[dd] = (totlen - global_startpoint[dirs[dd]-1]) / downsample[dd]; } else { hsize[dd] = lengths[dd]; } assert (hsize[dd]>=0); } // Get the slab *hdata = GetSlab (GH, target_proc, vindex, vtimelvl, hdim, global_startpoint, dirs, downsample, hsize); // Return with success return 1; } } // namespace CarpetSlab