Hello there
I'm writing a parallel evolutionary algorithm library using C++, MPI and CUDA. I need to extract the raw data from my object oriented design and stick it into a flat array (or std::vector using stl-mpi) for it to be sent across to nodes or the cuda device.
The complete design is quite complex with a lot of inheritance to keep the library flexible. But the classes of interest are:
Genome class - contains vector of data. e.g. floats or bools.
Population class - contains vector of Genome objects and is initailised with a genome object.
First a genome object is created, then a reference to it is passed to population class constructor which creates its own vector of genomes based on passed one. (Hope that makes sense!)
So I thought I would add another member vector, say rawData
to the population class. But the type of rawData would need to depend on the type of data stored in the genomes (or the original genome object).
Here lies the problem, as far as I am aware there is no way to dynamically set the type passed to template.
my pseudo-code would be
class genome {
std::vector<bool> data;
}
template <class T>
class population {
std::vector<genome> population;
std::vector<T> rawData;
void PackDataIntoRawData();
};
then when i create the population (which is actually a member object of another class), I would call:
genome myBitGenome();
population<type of myBitGenome.data> pop(myBitGenome);
Is there anyway to do this, or can anyone suggest another way to implement this.
Thanks in advance