Well my answer to my question :D
I used subscript operator overloading.
struct constant_node_AoS {
union {int id;double id_double;}
double Zmiddle;
double Height;
union {int Bstatus;double Bstatus_double;}
double gamma;
double e;
double cc;
double cs;
double spv0;
double spvp;
double &operator[](int i){
switch (i){
case 0:
return id_double;
case 1:
return Zmiddle;
case 2:
return Height;
case 3:
return Bstatus_double;
case 4:
return gamma;
case 5:
return e;
case 6:
return cc;
case 7:
return cs;
case 8:
return spv0;
case 9:
return spvp;
}
} nodes_constprop[nNodes];
and also similar for other structure!
struct constant_node_struct_SoA {
union {long long *id;double *id_double}
double *Zmiddle;
double *Height;
union {long long *Bstatus;double *Bstatus_double}
double *gamma;
double *e;
double *cc;
double *cs;
double *spv0;
double *spvp;
double* &operator[](int i){
switch (i){
case 0:
return id_double;
case 1:
return Zmiddle;
case 2:
return Height;
case 3:
return Bstatus_double;
case 4:
return gamma;
case 5:
return e;
case 6:
return cc;
case 7:
return cs;
case 8:
return spv0;
case 9:
return spvp;
}
}nodes_constprop_;
so now I can easily have this
for (int i=0;i<10;i++)
g_.nodes_constprop_[i] = new double[nNodes];
for (int i=0;i<nNodes;i++)
for (int j=0;j<10;j++)
(g_.nodes_constprop_[j])[i] = (g_tmp->nodes_constprop[i])[j];
The reason I added union was I couldnt figure out type casting errors without it (although I should anyway added __align(8) to it. Also the reason for long long was also whatever I did, pointer operations on int was 4 bytes. I added following code
typedef int int_align_double __attribute__ ((aligned(sizeof(double))));
typedef int_align_double* pint_align_double;
but still variables of type pint_align_double, were 4 byte pointers. So I changed it to long long so I can get 8 byte pointer alignment.