c++ - Clean code for transforming a Array of Structures(AoS) to Structure of Arrays (SoA)? -


I am trying to change my data structures from the array of structures to the structure of arrays and it seems that I I am writing all the unnecessary code for this. (I want to put both codes, as one is going to run GPU-Cuda on CPU and on second)

For example, I have

  struct constant_node_AoS {int Id; Double Zembed; Double height; Int bestsats; Double gamma; Double e Double cc; Double cs; Double spv 0; Double spvp; } Nodes_constprop; // in fact it's more like nodes_constprop [nNodes];  

So what have I done: I

  struct constant_node_struct_SoA {int * id; As a new structure is created; Double * Zembed; Double * height; Int * Bstatus; Double * Gamma; Double * E; Double * cc; Double * CS; Double * spv0; Double * SPVP; } Nodes_constprop_;  

Then I have allocated memory

  nodes_constprop_.id = new int [nNodes] nodes_constprop_.zmiddle = new double [nnodes to be such a code Should] nodes_constprop_.height = new double [nNodes] .  

and to move a loop data

  (int i = 0; i & lt; nNodes; i ++) for {nodes_constprop_ .id [i] = nodes_constprop [i] .id; Node_conproduct_gammild [i] = nodes_constop [i] .jimmed; Nodes_constprop_.Height [i] = node_scorp [i] .it; . . . }  

Another dirty code to free more data!

So I was thinking with some macro moves or I do not know some other clever ideas bypassing this mess?

For example, the Composition members have an array of pointers for pointers and their sizes, then loop them and allocate them and move data? Or some solutions that can be scaled well, so if I add several other members then it is automatically taken (or with minimal effort)?

For example, there is a way to know how many members are in a straight line (in time compilation - for example, here it should be 10), then use it to know the size of my pointers array Do you?

Thanks

The macro move looks like this. In the file, node (integer, id) node (double, zmiddle) node (double, height) node (integer, bstatus) node (double, gamma) node (double put struct.def E) Put struct.h

node (double, cc) node (double, cv) node #ifdef NODE_AOS struct constant_node_AoS {#define NODE (A, B) AB; #include "struct.def"} nodes_constprop [nNodes]; #define NODE_ID (i) nodes_constprop [(i)] #define NODE_HEIGHT .id (i) nodes_constprop [(i)] fields #endif #ifdef NODE_SOA #define The rest of the node (A, B) for a nodes_. Repeats ## B [Nandus]; #include "struct.def" #define NODE_ID (i) nodes_id [(i)] #define NODE_HEIGHT (i) nodes_Height [(i)] // repeat for the rest of the fields #endif

Your code uses NODE_ID (i) to access the ID.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -