AMROC Main     Blockstructured Adaptive Mesh Refinement in object-oriented C++


Main Page   Class Hierarchy   Compound List   File List  

PackedDataBucketVoid.C

Go to the documentation of this file.
00001 
00006 #include "PackedDataBucketVoid.h"
00007 
00008 #ifdef DEBUG_PRINT_DBKT
00009 #include "CommServer.h"
00010 #endif
00011 
00012 DataBucketVoid::DataBucketVoid(unsigned const hsize, unsigned const dsize)
00013         : headsize(0), datasize(0), cnt(1), hs(0), ds(0), bkt(0)
00014   {
00015    hs = new unsigned[1];
00016    ds = new unsigned[1];
00017 
00018 #ifdef DEBUG_PRINT_DBKT_MEMORY
00019    DAGHMemoryTrace::alloc(sizeof(unsigned)*1); // hs
00020    DAGHMemoryTrace::alloc(sizeof(unsigned)*1); // ds
00021 #endif
00022 
00023    headsize = hsize + sizeof(struct dbkthdr);
00024    unsigned int align = ((headsize > 8) ? 16 : ((headsize > 4) ? 8 : 4));
00025    headsize = (headsize+align-1) & (~(align-1));
00026    hs[0] = 0;
00027 
00028    align = ((dsize > 8) ? 16 : ((dsize > 4) ? 8 : 4));
00029    datasize = (dsize+align-1) & (~(align-1));
00030    ds[0] = headsize;
00031 
00032    char *chunk;
00033    assert ((chunk = new char[headsize+datasize]) != (char *) 0);
00034 
00035 #ifdef DEBUG_PRINT_DBKT_MEMORY
00036    DAGHMemoryTrace::alloc(sizeof(char)*(headsize+datasize));
00037 #endif  
00038 
00039    bkt = (union drecord *) chunk;
00040    bkt->head.headsize = headsize;
00041    bkt->head.datasize = datasize;
00042    bkt->head.cnt = cnt;
00043 
00044 #ifdef DEBUG_PRINT_DBKT
00045      ( comm_service::log() << "\n************* Grid Data Bucket *************\n"
00046                            << "Cnt: " << cnt << " "
00047                            << "HSize: " << headsize << " "
00048                            << "DSize: " << datasize << " "
00049                            << "\n" ).flush();
00050      for (int db_i=0;db_i<cnt;db_i++) {
00051       ( comm_service::log() << "[" << hs[db_i] << " , " << ds[db_i] << "]\n");
00052      }
00053      ( comm_service::log() << "\n************* ***************** *************\n"
00054                            ).flush();
00055 #endif
00056   }
00057 
00058 DataBucketVoid::DataBucketVoid(unsigned *hsize, unsigned *dsize, int const n)
00059         : headsize(0), datasize(0), cnt(n), hs(0), ds(0), bkt(0)
00060   {
00061    hs = new unsigned[cnt];
00062    ds = new unsigned[cnt];
00063 
00064 #ifdef DEBUG_PRINT_DBKT_MEMORY
00065    DAGHMemoryTrace::alloc(sizeof(unsigned)*cnt); // hs
00066    DAGHMemoryTrace::alloc(sizeof(unsigned)*cnt); // ds
00067 #endif
00068 
00069    unsigned h = 0, d = 0;
00070    unsigned s = sizeof(struct dbkthdr);
00071    unsigned a = 0;
00072    int i;
00073    for (i=0;i<cnt;i++) {
00074      hs[i] = headsize + datasize;
00075 
00076      h = hsize[i] + s;
00077      a = ((h > 8) ? 16 : ((h > 4) ? 8 : 4));
00078      h = (h+a-1) & (~(a-1));
00079      headsize += h;
00080 
00081      ds[i] = headsize + datasize;
00082 
00083      a = ((dsize[i] > 8) ? 16 : ((dsize[i] > 4) ? 8 : 4));
00084      d = (dsize[i]+a-1) & (~(a-1));
00085      datasize += d;
00086 
00087      hsize[i] = h;
00088      dsize[i] = d;
00089    }
00090 
00091    char *chunk;
00092    assert ((chunk = new char[headsize+datasize]) != (char *) 0);
00093 
00094 #ifdef DEBUG_PRINT_DBKT_MEMORY
00095    DAGHMemoryTrace::alloc(sizeof(char)*(headsize+datasize));
00096 #endif
00097 
00098    bkt = (union drecord *) chunk;
00099 
00100    for (i=0;i<cnt;i++) {
00101      ((union drecord *)((char *)(bkt)+hs[i]))->head.headsize == hsize[i];
00102      ((union drecord *)((char *)(bkt)+hs[i]))->head.datasize == dsize[i];
00103      ((union drecord *)((char *)(bkt)+hs[i]))->head.cnt == cnt;
00104    }
00105 #ifdef DEBUG_PRINT_DBKT
00106      ( comm_service::log() << "\n************* Grid Data Bucket *************\n"
00107                            << "Cnt: " << cnt << " "
00108                            << "HSize: " << headsize << " "
00109                            << "DSize: " << datasize << " "
00110                            << "\n" ).flush();
00111      for (int db_i=0;db_i<cnt;db_i++) {
00112       ( comm_service::log() << "[" << hs[db_i] << " , " << ds[db_i] << "]\n");
00113      }
00114      ( comm_service::log() << "\n************* ***************** *************\n"
00115                            ).flush();
00116 #endif
00117   }
00118 
00119 DataBucketVoid::DataBucketVoid(unsigned hsize, unsigned *dsize, int const n)
00120         : headsize(0), datasize(0), cnt(n), hs(0), ds(0), bkt(0)
00121   {
00122    hs = new unsigned[cnt];
00123    ds = new unsigned[cnt];
00124 
00125 #ifdef DEBUG_PRINT_DBKT_MEMORY
00126    DAGHMemoryTrace::alloc(sizeof(unsigned)*cnt); // hs
00127    DAGHMemoryTrace::alloc(sizeof(unsigned)*cnt); // ds
00128 #endif
00129 
00130    unsigned h = 0, d = 0;
00131    unsigned s = sizeof(struct dbkthdr);
00132    unsigned a = 0;
00133 
00134    h = hsize + s;
00135    a = ((h > 8) ? 16 : ((h > 4) ? 8 : 4));
00136    h = (h+a-1) & (~(a-1));
00137    hsize = h;
00138 
00139    int i;
00140    for (i=0;i<cnt;i++) {
00141      hs[i] = headsize + datasize;
00142 
00143      headsize += h;
00144 
00145      ds[i] = headsize + datasize;
00146 
00147      a = ((dsize[i] > 8) ? 16 : ((dsize[i] > 4) ? 8 : 4));
00148      d = (dsize[i]+a-1) & (~(a-1));
00149      datasize += d;
00150 
00151      dsize[i] = d;
00152    }
00153 
00154    char *chunk;
00155    assert ((chunk = new char[headsize+datasize]) != (char *) 0);
00156 
00157 #ifdef DEBUG_PRINT_DBKT_MEMORY
00158    DAGHMemoryTrace::alloc(sizeof(char)*(headsize+datasize));
00159 #endif
00160 
00161    bkt = (union drecord *) chunk;
00162 
00163    for (i=0;i<cnt;i++) {
00164      ((union drecord *)((char *)(bkt)+hs[i]))->head.headsize == hsize;
00165      ((union drecord *)((char *)(bkt)+hs[i]))->head.datasize == dsize[i];
00166      ((union drecord *)((char *)(bkt)+hs[i]))->head.cnt == cnt;
00167    }
00168 #ifdef DEBUG_PRINT_DBKT
00169      ( comm_service::log() << "\n************* Grid Data Bucket *************\n"
00170                            << "Cnt: " << cnt << " "
00171                            << "HSize: " << headsize << " "
00172                            << "DSize: " << datasize << " "
00173                            << "\n" ).flush();
00174      for (int db_i=0;db_i<cnt;db_i++) {
00175       ( comm_service::log() << "[" << hs[db_i] << " , " << ds[db_i] << "]\n");
00176      }
00177      ( comm_service::log() << "\n************* ***************** *************\n"
00178                            ).flush();
00179 #endif
00180   }
00181 
00182 DataBucketVoid::DataBucketVoid(union drecord const *package)
00183         : headsize(0), datasize(0), cnt(0), hs(0), ds(0), bkt(0)
00184   {
00185    cnt = package->head.cnt;
00186    hs = new unsigned[cnt];
00187    ds = new unsigned[cnt];
00188 
00189 #ifdef DEBUG_PRINT_DBKT_MEMORY
00190    DAGHMemoryTrace::alloc(sizeof(unsigned)*cnt); // hs
00191    DAGHMemoryTrace::alloc(sizeof(unsigned)*cnt); // ds
00192 #endif
00193 
00194    int i;
00195    for (i=0;i<cnt;i++) {
00196      hs[i] = headsize + datasize;
00197      headsize += ((union drecord *)((char *)(package)+hs[i]))->head.headsize;
00198      ds[i] = headsize + datasize;
00199      datasize += ((union drecord *)((char *)(package)+hs[i]))->head.datasize;
00200    }
00201 
00202    char *nchunk, *ochunk;
00203    ochunk = (char *) package;
00204    assert ((nchunk = new char[headsize+datasize]) != (char *) 0);
00205 
00206 #ifdef DEBUG_PRINT_DBKT_MEMORY
00207    DAGHMemoryTrace::alloc(sizeof(char)*(headsize+datasize));
00208 #endif
00209 
00210 
00211    //for (register int i=0;i<headsize+datasize;i++)
00212    //   nchunk[i] = ochunk[i];
00213    memcpy((void *)nchunk, (void *)ochunk, headsize+datasize);
00214 
00215    bkt = (union drecord *) nchunk;
00216 #ifdef DEBUG_PRINT_DBKT
00217      ( comm_service::log() << "\n************* Grid Data Bucket *************\n"
00218                            << "Cnt: " << cnt << " "
00219                            << "HSize: " << headsize << " "
00220                            << "DSize: " << datasize << " "
00221                            << "\n" ).flush();
00222      for (int db_i=0;db_i<cnt;db_i++) {
00223       ( comm_service::log() << "[" << hs[db_i] << " , " << ds[db_i] << "]\n");
00224      }
00225      ( comm_service::log() << "\n************* ***************** *************\n"
00226                            ).flush();
00227 #endif
00228   }
00229 
00230 DataBucketVoid::DataBucketVoid(union drecord *package)
00231         : headsize(0), datasize(0), cnt(0), hs(0), ds(0), bkt(0)
00232   {
00233    cnt = package->head.cnt;
00234    hs = new unsigned[cnt];
00235    ds = new unsigned[cnt];
00236 
00237 #ifdef DEBUG_PRINT_DBKT_MEMORY
00238    DAGHMemoryTrace::alloc(sizeof(unsigned)*cnt); // hs
00239    DAGHMemoryTrace::alloc(sizeof(unsigned)*cnt); // ds
00240 #endif
00241 
00242    for (int i=0;i<cnt;i++) {
00243      hs[i] = headsize + datasize;
00244      headsize += ((union drecord *)((char *)(package)+hs[i]))->head.headsize;
00245      ds[i] = headsize + datasize;
00246      datasize += ((union drecord *)((char *)(package)+hs[i]))->head.datasize;
00247    }
00248 
00249 #ifdef DEBUG_PRINT_DBKT_MEMORY
00250    DAGHMemoryTrace::alloc(sizeof(char)*(headsize+datasize));
00251 #endif
00252 
00253    bkt = package;
00254 #ifdef DEBUG_PRINT_DBKT
00255      ( comm_service::log() << "\n************* Grid Data Bucket *************\n"
00256                            << "Cnt: " << cnt << " "
00257                            << "HSize: " << headsize << " "
00258                            << "DSize: " << datasize << " "
00259                            << "\n" ).flush();
00260      for (int db_i=0;db_i<cnt;db_i++) {
00261       ( comm_service::log() << "[" << hs[db_i] << " , " << ds[db_i] << "]\n");
00262      }
00263      ( comm_service::log() << "\n************* ***************** *************\n"
00264                            ).flush();
00265 #endif
00266   }
00267 
00268 DataBucketVoid::DataBucketVoid(union drecord const *package, int const n)
00269         : headsize(0), datasize(0), cnt(0), hs(0), ds(0), bkt(0)
00270   { 
00271    assert (n < package->head.cnt);
00272 
00273    cnt = 1;
00274    hs = new unsigned[1];
00275    ds = new unsigned[1];
00276 
00277 #ifdef DEBUG_PRINT_DBKT_MEMORY
00278    DAGHMemoryTrace::alloc(sizeof(unsigned)*1); // hs
00279    DAGHMemoryTrace::alloc(sizeof(unsigned)*1); // ds
00280 #endif
00281 
00282    unsigned hoff = 0;
00283    int i;
00284    for (i=0;i<n;i++) {
00285      headsize = ((union drecord *)((char *)(package)+hoff))->head.headsize;
00286      datasize = ((union drecord *)((char *)(package)+hoff))->head.datasize;
00287      hoff += (headsize + datasize);
00288    }
00289    headsize = ((union drecord *)((char *)(package)+hoff))->head.headsize;
00290    datasize = ((union drecord *)((char *)(package)+hoff))->head.datasize;
00291 
00292    hs[0] = 0;
00293    ds[0] = headsize;
00294 
00295    char *nchunk, *ochunk;
00296    ochunk = (char *) ((char *)(package)+hoff);
00297    assert ((nchunk = new char[headsize+datasize]) != (char *) 0);
00298 
00299 #ifdef DEBUG_PRINT_DBKT_MEMORY
00300    DAGHMemoryTrace::alloc(sizeof(char)*(headsize+datasize));
00301 #endif
00302 
00303    //for (register int i=0;i<headsize+datasize;i++)
00304    //   nchunk[i] = ochunk[i];
00305    memcpy((void *)nchunk, (void *)ochunk, headsize+datasize);
00306 
00307    bkt = (union drecord *) nchunk;
00308    bkt->head.cnt = cnt;
00309 
00310 #ifdef DEBUG_PRINT_DBKT
00311      ( comm_service::log() << "\n************* Grid Data Bucket *************\n"
00312                            << "Cnt: " << cnt << " "
00313                            << "HSize: " << headsize << " "
00314                            << "DSize: " << datasize << " "
00315                            << "\n" ).flush();
00316      for (int db_i=0;db_i<cnt;db_i++) {
00317       ( comm_service::log() << "[" << hs[db_i] << " , " << ds[db_i] << "]\n");
00318      }
00319      ( comm_service::log() << "\n************* ***************** *************\n"
00320                            ).flush();
00321 #endif
00322   }


Quickstart     Users Guide     Programmers Reference     Installation      Examples     Download



AMROC Main      Home      Contact
last update: 06/01/04