Skip to content

Use int64 for indexing

Markus Holzer requested to merge holzer/pystencils:type_boundary into master

For indexed kernels, int32 is too small for large domain sizes. Thus the coordinates are cast to int64 in this MR to allow huge domain sizes.

As an example of the adaption the generated code for a Neumann boundary is shown. Before:

FUNC_PREFIX void kernel(double * RESTRICT _data_C, uint8_t * RESTRICT const _data_indexField, int64_t const _size_indexField_0, int64_t const _stride_indexField_0)
{
   #pragma omp parallel
   {
      #pragma omp for schedule(static)
      for (int64_t ctr_0 = 0; ctr_0 < _size_indexField_0; ctr_0 += 1)
      {
         const int32_t x = *((int32_t *)(& _data_indexField[12*_stride_indexField_0*ctr_0]));
         const int32_t y = *((int32_t *)(& _data_indexField[12*_stride_indexField_0*ctr_0 + 4]));
         
         
         const int64_t cx [] = { 0, 0, 0, -1, 1, -1, 1, -1, 1 };
         const int64_t cy [] = { 0, 1, -1, 0, 0, 1, 1, -1, -1 };
         const int invdir [] = { 0, 2, 1, 4, 3, 8, 7, 6, 5 };
         
         const int32_t dir = *((int32_t *)(& _data_indexField[12*_stride_indexField_0*ctr_0 + 8]));
         _data_C[x + 11*y] = _data_C[x + 11*y + cx[dir] + 11*cy[dir]];
      }
   }
}

After:

FUNC_PREFIX void kernel(double * RESTRICT _data_C, uint8_t * RESTRICT const _data_indexField, int64_t const _size_indexField_0, int64_t const _stride_indexField_0)
{
   #pragma omp parallel
   {
      #pragma omp for schedule(static)
      for (int64_t ctr_0 = 0; ctr_0 < _size_indexField_0; ctr_0 += 1)
      {
         const int64_t x = *((int32_t *)(& _data_indexField[12*_stride_indexField_0*ctr_0]));
         const int64_t y = *((int32_t *)(& _data_indexField[12*_stride_indexField_0*ctr_0 + 4]));
         
         
         const int64_t cx [] = { 0, 0, 0, -1, 1, -1, 1, -1, 1 };
         const int64_t cy [] = { 0, 1, -1, 0, 0, 1, 1, -1, -1 };
         const int64_t invdir [] = { 0, 2, 1, 4, 3, 8, 7, 6, 5 };
         
         const int64_t dir = *((int32_t *)(& _data_indexField[12*_stride_indexField_0*ctr_0 + 8]));
         _data_C[x + 11*y] = _data_C[x + 11*y + cx[dir] + 11*cy[dir]];
      }
   }
}
Edited by Markus Holzer

Merge request reports