[mpich-discuss] Contiguous memory random access

Robert Kubrick robertkubrick at gmail.com
Sat Aug 16 08:05:46 CDT 2008


I have the following structure:

struct Employee
{
   char lastName[64];
   char firstName[64];
   double salary;
};

I want to allocate an array of 100 employees in memory for use with  
MPI collective data transfer and maybe one-sided window operations:

Employee* pEmp = (Employee*)calloc(100, sizeof(Employee));

Now the problem is that I also want to randomly access each slot in  
the pEmp array by 'lastName'. Normally I would allocate an STL map  
collection indexed by last name to do this, but here I need to  
maintain contiguous memory space to run MPI_Scatter/MPI_Gather  
collectives.

One way to solve the problem is to maintain a collection that maps  
each last name with the relative index in the array. For example:

typedef std::map<std::string, int> MYRANDIDX;
MYRANDIDX _mRandIdx;

MYRANDIDX::const_iterator citer = _mRandIdx.find("Smith");
Employee smith = pEmp[citer->second];

Of course all insert/erase operations must be managed to keep the  
random indexing and the contiguous array in sync.
I thought this must be a common problem in MPI and maybe there are  
some standard techniques or libraries to manage random indexing on a  
contiguous memory array?




More information about the mpich-discuss mailing list