8 Handling Sparse Object Arrays

In Charisma, when we declare an object array, by default a dense array is created with all the elements populated. For instance, when we have the following declaration in the orchestration code, an array of NxNxN is created.

{foodecl}
    class Cell : ChareArray3D;
    obj cells : Cell[N,N,N];

There are certain occasions when the programmer may need sparse object arrays, in which not all elements are created. An example is neighborhood force calculation in molecular dynamics application. We have a 3D array of Cell objects to hold the atom coordinates, and a 6D array of CellPair objects to perform pairwise force calculation between neighboring cells. In this case, not all elements in the 6D array of CellPair are necessary in the program. Only those which represent two immediately neighboring cells are needed for the force calculation. In this case, Charisma provides flexibility of declaring a sparse object array, with a sparse keyword following the object array declaration, as follows.

{foodecl}
    class CellPair : ChareArray6D;	
    obj cellpairs : CellPair[N,N,N,N,N,N],sparse;

Then the programmer is expected to supply a sequential function with the name getIndex_ARRAYNAME to generate a list of selected indices of the elements to create. As an example, the following function essentially tells the system to generate all the NxNxNxNxNxN elements for the 6D array.

{foodecl}
  void getIndex_cellpairs(CkVec<CkArrayIndex6D>& vec){
    int i,j,k,l,m,n;
    for(i=0;i<N;i++)
      for(j=0;j<N;j++)
        for(k=0;k<N;k++)
          for(l=0;l<N;l++)
            for(m=0;m<N;m++)
              for(n=0;n<N;n++)
                vec.push_back(CkArrayIndex6D(i,j,k,l,m,n));
  }

November 23, 2009
Charisma Homepage
Charm Homepage