Ignore:
Timestamp:
Apr 24, 2012, 2:26:14 PM (14 years ago)
Author:
Julian Iseringhausen <isering@…>
Children:
b51c3b
Parents:
e3dbbf
Message:

Fix energy calculation.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@1729 5161e1c8-67bf-11de-9fd5-51895aff932f

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/comm/mpi/datatypes_local.cpp

    re3dbbf r716da7  
    2323using namespace VMG;
    2424
    25 static inline int to_1d(const int& x, const int& y, const int&  z)
     25static inline int to_1d(const Index& i) __attribute__((always_inline));
     26static inline int to_1d(const Index& i)
    2627{
    27   return z+3*(y+3*x);
     28  return i.Z()+3*(i.Y()+3*i.X());
    2829}
    2930
     
    3637
    3738template <class T>
    38 void VMG::MPI::DatatypesLocal::InitDatatypesLocal(const T& grid, const MPI_Comm& comm)
     39void VMG::MPI::DatatypesLocal::InitDatatypesLocal(const T& grid, const MPI_Comm& comm, const bool& alloc_buffer)
    3940{
    4041  if (comm != MPI_COMM_NULL) {
     
    4344    Index dims, periods, coords;
    4445    Index sizes, subsizes, starts;
     46    Index offset, i;
    4547    const LocalIndices& l = grid.Local();
    4648
    4749    MPI_Cart_get(comm, 3, dims.vec(), periods.vec(), coords.vec());
    4850
    49     for (int i=-1; i<=1; ++i)
    50       for (int j=-1; j<=1; ++j)
    51         for (int k=-1; k<=1; ++k)
    52           if (is_valid(coords + Index(i,j,k), dims, periods))
    53             MPI_Cart_rank(comm, (coords + Index(i,j,k)).vec(), &ranks[to_1d(i+1,j+1,k+1)]);
     51    for (i.X()=-1; i.X()<=1; ++i.X())
     52      for (i.Y()=-1; i.Y()<=1; ++i.Y())
     53        for (i.Z()=-1; i.Z()<=1; ++i.Z())
     54          if (is_valid(coords + i, dims, periods))
     55            MPI_Cart_rank(comm, (coords + i).vec(), &ranks[to_1d(i+1)]);
    5456
    5557    sizes = l.SizeTotal();
    5658
    5759    /* -1 0 0 */
    58     if (is_valid(coords + Index(-1,0,0), dims, periods)) {
    59       index = to_1d(0,1,1);
     60    offset = Index(-1,0,0);
     61    if (is_valid(coords + offset, dims, periods)) {
     62      index = to_1d(offset+1);
    6063      subsizes = Index(l.HaloSize1().X(), l.Size().Y(), l.Size().Z());
    6164      starts = Index(0, l.Begin().Y(), l.Begin().Z());
    62       halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 0, 1));
    63       starts = l.Begin();
    64       nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 0, 1));
     65      _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 0, 1, alloc_buffer));
     66      starts = l.Begin();
     67      _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 0, 1, alloc_buffer));
     68      _offset.push_back(offset);
    6569    }
    6670
    6771    /* 1 0 0 */
    68     if (is_valid(coords + Index(1,0,0), dims, periods)) {
    69       index = to_1d(2,1,1);
     72    offset = Index(1,0,0);
     73    if (is_valid(coords + offset, dims, periods)) {
     74      index = to_1d(offset+1);
    7075      subsizes = Index(l.HaloSize2().X(), l.Size().Y(), l.Size().Z());
    7176      starts = Index(l.End().X(), l.Begin().Y(), l.Begin().Z());
    72       halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 1, 0));
     77      _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 1, 0, alloc_buffer));
    7378      starts = Index(l.End().X()-l.HaloSize2().X(), l.Begin().Y(), l.Begin().Z());
    74       nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 1, 0));
     79      _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 1, 0, alloc_buffer));
     80      _offset.push_back(offset);
    7581    }
    7682
    7783    /* 0 -1 0 */
    78     if (is_valid(coords + Index(0,-1,0), dims, periods)) {
    79       index = to_1d(1,0,1);
     84    offset = Index(0,-1,0);
     85    if (is_valid(coords + offset, dims, periods)) {
     86      index = to_1d(offset+1);
    8087      subsizes = Index(l.Size().X(), l.HaloSize1().Y(), l.Size().Z());
    8188      starts = Index(l.Begin().X(), 0, l.Begin().Z());
    82       halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 2, 3));
    83       starts = l.Begin();
    84       nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 2, 3));
     89      _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 2, 3, alloc_buffer));
     90      starts = l.Begin();
     91      _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 2, 3, alloc_buffer));
     92      _offset.push_back(offset);
    8593    }
    8694
    8795    /* 0 1 0 */
    88     if (is_valid(coords + Index(0,1,0), dims, periods)) {
    89       index = to_1d(1,2,1);
     96    offset = Index(0,1,0);
     97    if (is_valid(coords + offset, dims, periods)) {
     98      index = to_1d(offset+1);
    9099      subsizes = Index(l.Size().X(), l.HaloSize2().Y(), l.Size().Z());
    91100      starts = Index(l.Begin().X(), l.End().Y(), l.Begin().Z());
    92       halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 3, 2));
     101      _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 3, 2, alloc_buffer));
    93102      starts = Index(l.Begin().X(), l.End().Y()-l.HaloSize2().Y(), l.Begin().Z());
    94       nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 3, 2));
     103      _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 3, 2, alloc_buffer));
     104      _offset.push_back(offset);
    95105    }
    96106
    97107    /* 0 0 -1 */
    98     if (is_valid(coords + Index(0,0,-1), dims, periods)) {
    99       index = to_1d(1,1,0);
     108    offset = Index(0,0,-1);
     109    if (is_valid(coords + offset, dims, periods)) {
     110      index = to_1d(offset+1);
    100111      subsizes = Index(l.Size().X(), l.Size().Y(), l.HaloSize1().Z());
    101112      starts = Index(l.Begin().X(), l.Begin().Y(), 0);
    102       halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 4, 5));
    103       starts = l.Begin();
    104       nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 4, 5));
     113      _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 4, 5, alloc_buffer));
     114      starts = l.Begin();
     115      _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 4, 5, alloc_buffer));
     116      _offset.push_back(offset);
    105117    }
    106118
    107119    /* 0 0 1 */
    108     if (is_valid(coords + Index(0,0,1), dims, periods)) {
    109       index = to_1d(1,1,2);
     120    offset = Index(0,0,1);
     121    if (is_valid(coords + offset, dims, periods)) {
     122      index = to_1d(offset+1);
    110123      subsizes = Index(l.Size().X(), l.Size().Y(), l.HaloSize2().Z());
    111124      starts = Index(l.Begin().X(), l.Begin().Y(), l.End().Z());
    112       halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 5, 4));
     125      _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 5, 4, alloc_buffer));
    113126      starts = Index(l.Begin().X(), l.Begin().Y(), l.End().Z()-l.HaloSize2().Z());
    114       nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 5, 4));
     127      _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 5, 4, alloc_buffer));
     128      _offset.push_back(offset);
    115129    }
    116130
    117131    /* -1 -1 0 */
    118     if (is_valid(coords + Index(-1,-1,0), dims, periods)) {
    119       index = to_1d(0,0,1);
     132    offset = Index(-1,-1,0);
     133    if (is_valid(coords + offset, dims, periods)) {
     134      index = to_1d(offset+1);
    120135      subsizes = Index(l.HaloSize1().X(), l.HaloSize1().Y(), l.Size().Z());
    121136      starts = Index(0, 0, l.Begin().Z());
    122       halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 6, 7));
    123       starts = l.Begin();
    124       nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 6, 7));
     137      _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 6, 7, alloc_buffer));
     138      starts = l.Begin();
     139      _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 6, 7, alloc_buffer));
     140      _offset.push_back(offset);
    125141    }
    126142
    127143    /* -1 1 0 */
    128     if (is_valid(coords + Index(-1,1,0), dims, periods)) {
    129       index = to_1d(0,2,1);
     144    offset = Index(-1,1,0);
     145    if (is_valid(coords + offset, dims, periods)) {
     146      index = to_1d(offset+1);
    130147      subsizes = Index(l.HaloSize1().X(), l.HaloSize2().Y(), l.Size().Z());
    131148      starts = Index(0, l.End().Y(), l.Begin().Z());
    132       halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 8, 9));
     149      _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 8, 9, alloc_buffer));
    133150      starts = Index(l.Begin().X(), l.End().Y()-l.HaloSize2().Y(), l.Begin().Z());
    134       nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 8, 9));
     151      _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 8, 9, alloc_buffer));
     152      _offset.push_back(offset);
    135153    }
    136154
    137155    /* 1 -1 0 */
    138     if (is_valid(coords + Index(1,-1,0), dims, periods)) {
    139       index = to_1d(2,0,1);
     156    offset = Index(1,-1,0);
     157    if (is_valid(coords + offset, dims, periods)) {
     158      index = to_1d(offset+1);
    140159      subsizes = Index(l.HaloSize2().X(), l.HaloSize1().Y(), l.Size().Z());
    141160      starts = Index(l.End().X(), 0, l.Begin().Z());
    142       halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 9, 8));
     161      _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 9, 8, alloc_buffer));
    143162      starts = Index(l.End().X()-l.HaloSize2().X(), l.Begin().Y(), l.Begin().Z());
    144       nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 9, 8));
     163      _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 9, 8, alloc_buffer));
     164      _offset.push_back(offset);
    145165    }
    146166
    147167    /* 1 1 0 */
    148     if (is_valid(coords + Index(1,1,0), dims, periods)) {
    149       index = to_1d(2,2,1);
     168    offset = Index(1,1,0);
     169    if (is_valid(coords + offset, dims, periods)) {
     170      index = to_1d(offset+1);
    150171      subsizes = Index(l.HaloSize2().X(), l.HaloSize2().Y(), l.Size().Z());
    151172      starts = Index(l.End().X(), l.End().Y(), l.Begin().Z());
    152       halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 7, 6));
     173      _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 7, 6, alloc_buffer));
    153174      starts = Index(l.End().X()-l.HaloSize2().X(), l.End().Y()-l.HaloSize2().Y(), l.Begin().Z());
    154       nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 7, 6));
     175      _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 7, 6, alloc_buffer));
     176      _offset.push_back(offset);
    155177    }
    156178
    157179    /* -1 0 -1 */
    158     if (is_valid(coords + Index(-1,0,-1), dims, periods)) {
    159       index = to_1d(0,1,0);
     180    offset = Index(-1,0,-1);
     181    if (is_valid(coords + offset, dims, periods)) {
     182      index = to_1d(offset+1);
    160183      subsizes = Index(l.HaloSize1().X(), l.Size().Y(), l.HaloSize1().Z());
    161184      starts = Index(0, l.Begin().Y(), 0);
    162       halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 10, 11));
    163       starts = l.Begin();
    164       nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 10, 11));
     185      _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 10, 11, alloc_buffer));
     186      starts = l.Begin();
     187      _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 10, 11, alloc_buffer));
     188      _offset.push_back(offset);
    165189    }
    166190
    167191    /* -1 0 1 */
    168     if (is_valid(coords + Index(-1,0,1), dims, periods)) {
    169       index = to_1d(0,1,2);
     192    offset = Index(-1,0,1);
     193    if (is_valid(coords + offset, dims, periods)) {
     194      index = to_1d(offset+1);
    170195      subsizes = Index(l.HaloSize1().X(), l.Size().Y(), l.HaloSize2().Z());
    171196      starts = Index(0, l.Begin().Y(), l.End().Z());
    172       halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 12, 13));
     197      _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 12, 13, alloc_buffer));
    173198      starts = Index(l.Begin().X(), l.Begin().Y(), l.End().Z()-l.HaloSize2().Z());
    174       nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 12, 13));
     199      _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 12, 13, alloc_buffer));
     200      _offset.push_back(offset);
    175201    }
    176202
    177203    /* 1 0 -1 */
    178     if (is_valid(coords + Index(1,0,-1), dims, periods)) {
    179       index = to_1d(2,1,0);
     204    offset = Index(1,0,-1);
     205    if (is_valid(coords + offset, dims, periods)) {
     206      index = to_1d(offset+1);
    180207      subsizes = Index(l.HaloSize2().X(), l.Size().Y(), l.HaloSize1().Z());
    181208      starts = Index(l.End().X(), l.Begin().Y(), 0);
    182       halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 13, 12));
     209      _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 13, 12, alloc_buffer));
    183210      starts = Index(l.End().X()-l.HaloSize2().X(), l.Begin().Y(), l.Begin().Z());
    184       nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 13, 12));
     211      _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 13, 12, alloc_buffer));
     212      _offset.push_back(offset);
    185213    }
    186214
    187215    /* 1 0 1 */
    188     if (is_valid(coords + Index(1,0,1), dims, periods)) {
    189       index = to_1d(2,1,2);
     216    offset = Index(1,0,1);
     217    if (is_valid(coords + offset, dims, periods)) {
     218      index = to_1d(offset+1);
    190219      subsizes = Index(l.HaloSize2().X(), l.Size().Y(), l.HaloSize2().Z());
    191220      starts = Index(l.End().X(), l.Begin().Y(), l.End().Z());
    192       halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 11, 10));
     221      _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 11, 10, alloc_buffer));
    193222      starts = Index(l.End().X()-l.HaloSize2().X(), l.Begin().Y(), l.End().Z()-l.HaloSize2().Z());
    194       nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 11, 10));
     223      _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 11, 10, alloc_buffer));
     224      _offset.push_back(offset);
    195225    }
    196226
    197227    /* 0 -1 -1 */
    198      if (is_valid(coords + Index(0,-1,-1), dims, periods)) {
    199        index = to_1d(1,0,0);
     228    offset = Index(0,-1,-1);
     229     if (is_valid(coords + offset, dims, periods)) {
     230       index = to_1d(offset+1);
    200231       subsizes = Index(l.Size().X(), l.HaloSize1().Y(), l.HaloSize1().Z());
    201232       starts = Index(l.Begin().X(), 0, 0);
    202        halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 14, 15));
     233       _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 14, 15, alloc_buffer));
    203234       starts = l.Begin();
    204        nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 14, 15));
     235       _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 14, 15, alloc_buffer));
     236       _offset.push_back(offset);
    205237     }
    206238
    207239    /* 0 -1 1 */
    208      if (is_valid(coords + Index(0,-1,1), dims, periods)) {
    209        index = to_1d(1,0,2);
     240     offset = Index(0,-1,1);
     241     if (is_valid(coords + offset, dims, periods)) {
     242       index = to_1d(offset+1);
    210243       subsizes = Index(l.Size().X(), l.HaloSize1().Y(), l.HaloSize2().Z());
    211244       starts = Index(l.Begin().X(), 0, l.End().Z());
    212        halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 16, 17));
     245       _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 16, 17, alloc_buffer));
    213246       starts = Index(l.Begin().X(), l.Begin().Y(), l.End().Z()-l.HaloSize2().Z());
    214        nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 16, 17));
     247       _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 16, 17, alloc_buffer));
     248       _offset.push_back(offset);
    215249     }
    216250
    217251    /* 0 1 -1 */
    218      if (is_valid(coords + Index(0,1,-1), dims, periods)) {
    219        index = to_1d(1,2,0);
     252     offset = Index(0,1,-1);
     253     if (is_valid(coords + offset, dims, periods)) {
     254       index = to_1d(offset+1);
    220255       subsizes = Index(l.Size().X(), l.HaloSize2().Y(), l.HaloSize1().Z());
    221256       starts = Index(l.Begin().X(), l.End().Y(), 0);
    222        halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 17, 16));
     257       _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 17, 16, alloc_buffer));
    223258       starts = Index(l.Begin().X(), l.End().Y()-l.HaloSize2().Y(), l.Begin().Z());
    224        nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 17, 16));
     259       _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 17, 16, alloc_buffer));
     260       _offset.push_back(offset);
    225261     }
    226262
    227263    /* 0 1 1 */
    228      if (is_valid(coords + Index(0,1,1), dims, periods)) {
    229        index = to_1d(1,2,2);
     264     offset = Index(0,1,1);
     265     if (is_valid(coords + offset, dims, periods)) {
     266       index = to_1d(offset+1);
    230267       subsizes = Index(l.Size().X(), l.HaloSize2().Y(), l.HaloSize2().Z());
    231268       starts = Index(l.Begin().X(), l.End().Y(), l.End().Z());
    232        halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 15, 14));
     269       _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 15, 14, alloc_buffer));
    233270       starts = Index(l.Begin().X(), l.End().Y()-l.HaloSize2().Y(), l.End().Z()-l.HaloSize2().Z());
    234        nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 15, 14));
     271       _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 15, 14, alloc_buffer));
     272       _offset.push_back(offset);
    235273     }
    236274
    237275    /* -1 -1 -1 */
    238      if (is_valid(coords + Index(-1,-1,-1), dims, periods)) {
    239        index = to_1d(0,0,0);
     276     offset = Index(-1,-1,-1);
     277     if (is_valid(coords + offset, dims, periods)) {
     278       index = to_1d(offset+1);
    240279       subsizes = l.HaloSize1();
    241280       starts = 0;
    242        halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 18, 19));
     281       _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 18, 19, alloc_buffer));
    243282       starts = l.Begin();
    244        nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 18, 19));
     283       _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 18, 19, alloc_buffer));
     284       _offset.push_back(offset);
    245285     }
    246286
    247287    /* -1 -1 1 */
    248      if (is_valid(coords + Index(-1,-1,1), dims, periods)) {
    249        index = to_1d(0,0,2);
     288     offset = Index(-1,-1,1);
     289     if (is_valid(coords + offset, dims, periods)) {
     290       index = to_1d(offset+1);
    250291       subsizes = Index(l.HaloSize1().X(), l.HaloSize1().Y(), l.HaloSize2().Z());
    251292       starts = Index(0, 0, l.End().Z());;
    252        halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 20, 21));
     293       _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 20, 21, alloc_buffer));
    253294       starts = Index(l.Begin().X(), l.Begin().Y(), l.End().Z()-l.HaloSize2().Z());
    254        nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 20, 21));
     295       _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 20, 21, alloc_buffer));
     296       _offset.push_back(offset);
    255297     }
    256298
    257299    /* -1 1 -1 */
    258      if (is_valid(coords + Index(-1,1,-1), dims, periods)) {
    259        index = to_1d(0,2,0);
     300     offset = Index(-1,1,-1);
     301     if (is_valid(coords + offset, dims, periods)) {
     302       index = to_1d(offset+1);
    260303       subsizes = Index(l.HaloSize1().X(), l.HaloSize2().Y(), l.HaloSize1().Z());
    261304       starts = Index(0, l.End().Y(), 0);
    262        halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 22, 23));
     305       _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 22, 23, alloc_buffer));
    263306       starts = Index(l.Begin().X(), l.End().Y()-l.HaloSize2().Y(), l.Begin().Z());
    264        nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 22, 23));
     307       _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 22, 23, alloc_buffer));
     308       _offset.push_back(offset);
    265309     }
    266310
    267311    /* 1 -1 -1 */
    268      if (is_valid(coords + Index(1,-1,-1), dims, periods)) {
    269        index = to_1d(2,0,0);
     312     offset = Index(1,-1,-1);
     313     if (is_valid(coords + offset, dims, periods)) {
     314       index = to_1d(offset+1);
    270315       subsizes = Index(l.HaloSize2().X(), l.HaloSize1().Y(), l.HaloSize1().Z());
    271316       starts = Index(l.End().X(), 0, 0);
    272        halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 24, 25));
     317       _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 24, 25, alloc_buffer));
    273318       starts = Index(l.End().X()-l.HaloSize2().X(), l.Begin().Y(), l.Begin().Z());
    274        nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 24, 25));
     319       _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 24, 25, alloc_buffer));
     320       _offset.push_back(offset);
    275321     }
    276322
    277323    /* -1 1 1 */
    278      if (is_valid(coords + Index(-1,1,1), dims, periods)) {
    279        index = to_1d(0,2,2);
     324     offset = Index(-1,1,1);
     325     if (is_valid(coords + offset, dims, periods)) {
     326       index = to_1d(offset+1);
    280327       subsizes = Index(l.HaloSize1().X(), l.HaloSize2().Y(), l.HaloSize2().Z());
    281328       starts = Index(0, l.End().Y(), l.End().Z());
    282        halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 25, 24));
     329       _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 25, 24, alloc_buffer));
    283330       starts = Index(l.Begin().X(), l.End().Y()-l.HaloSize2().Y(), l.End().Z()-l.HaloSize2().Z());
    284        nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 25, 24));
     331       _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 25, 24, alloc_buffer));
     332       _offset.push_back(offset);
    285333     }
    286334
    287335    /* 1 -1 1 */
    288      if (is_valid(coords + Index(1,-1,1), dims, periods)) {
    289        index = to_1d(2,0,2);
     336     offset = Index(1,-1,1);
     337     if (is_valid(coords + offset, dims, periods)) {
     338       index = to_1d(offset+1);
    290339       subsizes = Index(l.HaloSize2().X(), l.HaloSize1().Y(), l.HaloSize2().Z());
    291340       starts = Index(l.End().X(), 0, l.End().Z());
    292        halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 23, 22));
     341       _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 23, 22, alloc_buffer));
    293342       starts = Index(l.End().X()-l.HaloSize2().X(), l.Begin().Y(), l.End().Z()-l.HaloSize2().Z());
    294        nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 23, 22));
     343       _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 23, 22, alloc_buffer));
     344       _offset.push_back(offset);
    295345     }
    296346
    297347    /* 1 1 -1 */
    298      if (is_valid(coords + Index(1,1,-1), dims, periods)) {
    299        index = to_1d(2,2,0);
     348     offset = Index(1,1,-1);
     349     if (is_valid(coords + offset, dims, periods)) {
     350       index = to_1d(offset+1);
    300351       subsizes = Index(l.HaloSize2().X(), l.HaloSize2().Y(), l.HaloSize1().Z());
    301352       starts = Index(l.End().X(), l.End().Y(), 0);
    302        halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 21, 20));
     353       _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 21, 20, alloc_buffer));
    303354       starts = Index(l.End().X()-l.HaloSize2().X(), l.End().Y()-l.HaloSize2().Y(), l.Begin().Z());
    304        nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 21, 20));
     355       _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 21, 20, alloc_buffer));
     356       _offset.push_back(offset);
    305357     }
    306358
    307359    /* 1 1 1 */
    308      if (is_valid(coords + Index(1,1,1), dims, periods)) {
    309        index = to_1d(2,2,2);
     360     offset = Index(1,1,1);
     361     if (is_valid(coords + offset, dims, periods)) {
     362       index = to_1d(offset+1);
    310363       subsizes = l.HaloSize2();
    311364       starts = l.End();
    312        halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 19, 18));
     365       _halo.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 19, 18, alloc_buffer));
    313366       starts = l.End()-l.HaloSize2();
    314        nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 19, 18));
     367       _nb.push_back(VMG::MPI::Datatype(sizes, subsizes, starts, ranks[index], 19, 18, alloc_buffer));
     368       _offset.push_back(offset);
    315369     }
    316370
     
    318372}
    319373
    320 template void VMG::MPI::DatatypesLocal::InitDatatypesLocal<VMG::Grid>(const VMG::Grid& grid, const MPI_Comm& comm);
    321 template void VMG::MPI::DatatypesLocal::InitDatatypesLocal<VMG::Particle::LinkedCellList>(const VMG::Particle::LinkedCellList& grid, const MPI_Comm& comm);
    322 
     374template void VMG::MPI::DatatypesLocal::InitDatatypesLocal<VMG::Grid>(const VMG::Grid& grid, const MPI_Comm& comm, const bool& alloc_buffer);
     375template void VMG::MPI::DatatypesLocal::InitDatatypesLocal<VMG::Particle::LinkedCellList>(const VMG::Particle::LinkedCellList& grid, const MPI_Comm& comm, const bool& alloc_buffer);
     376
Note: See TracChangeset for help on using the changeset viewer.