framework icon indicating copy to clipboard operation
framework copied to clipboard

SoA of item variables or view of item variable with a memory area

Open DavidDureau opened this issue 3 years ago • 2 comments

Goal: to have or to "manipulate" a dynamic number of item variables

Choice 1: Array of MeshVariableArrayRefT< ItemTypeT, DataTypeT>

We could have a N-dimensional array of MeshVariableArrayRefT<>

Here, an example with a two-dimensional array.

// Pseudo-code
"UniqueArray2< VariableCellArrayReal >" m_aof_arr;

Integer dim1 = 8;
Integer dim2 = 100;

m_aof_arr.resize(dim1, dim2, VariableBuildInfo(mesh(), "MyCellArray"));
// m_aof_arr is a two-dimensional array of VariableCellArrayReal 
//                             named String::format("MyCellArray_{0}_{1}", i1, i2)


for(Integer i1=0 ; i1<dim1 ; ++i1) {
  for(Integer i2=0 ; i2<dim2 ; ++i2) {
    ENUMERATE_CELL(icell, allCells()) {
      m_aof_arr[i1][i2][icell] = ... ;
    }
  }
}

// We could synchronize just one Cell variable array
m_aof_arr[1][2].synchronize();

Choice 2: a view MeshVariableArrayViewT< ItemTypeT, DataTypeT>

Thanks to a memory area, we could create a kind of view on a Cell variable array.

Here an example, I don't know if we could use NumArray to pre-allocate data.

// Psuedo-code
Integer dim1 = 8;
Integer dim2 = 100;
NumArray<Real, 3> num_arr(dim1, dim2, allCells().size());


for(Integer i1=0 ; i1<dim1 ; ++i1) {
  for(Integer i2=0 ; i2<dim2 ; ++i2) {

    MeshVariableArrayViewT<Cell, Real> arr_i1_i2(num_arr(i1,i2).data(), mesh());

    ENUMERATE_CELL(icell, allCells()) {
      arr_i1_i2[icell] = ... ;
    }
  }
}

MeshVariableArrayViewT<Cell, Real> arr_1_2(num_arr(1,2).data(), mesh());
arr_1_2.synchronize();

DavidDureau avatar Jul 27 '22 10:07 DavidDureau

Thanks for the issue. I'm gonna think about it. I have several questions:

  • What kind of operation do you need ? Is synchronize() the only needed operation ?
  • Are the number dim1 and dim2 allowed to change during the simulation ?

grospelliergilles avatar Jul 27 '22 13:07 grospelliergilles

I think we could consider dim1 and dim2 are not allowed to change during the simulation. Note: the number of dimensions is not limited to 2, we could have 2 or more dimensions (dim3, dim4 and so on).

I don't know if synchronize would be the only needed operation. Of course, we need to read and/or write at item in a loop ...

Maybe, we need to dump/restore the array so, at the end, the only right choice could be "choice 1" ("choice 2" is only a temporary view so we couldn't dump/restore).

DavidDureau avatar Aug 22 '22 13:08 DavidDureau