SCOREC / particle_structures

unstructured mesh particle data structure
BSD 3-Clause "New" or "Revised" License
3 stars 0 forks source link

Macros with commas #5

Closed diamog closed 5 years ago

diamog commented 5 years ago

We are able to simply pass the code as an argument into the macros, but with one problem. The code cannot have any unprotected commas (protected commas appear within a set of parentheses () brackets, [] and {}, do not count). So with our current Push algorithm, the following lines cannot be done as they are currently inside the macro:

https://github.com/SCOREC/particle_structures/blob/master/algorithms/Push.cpp#L345-L350

cwsmith commented 5 years ago

OK. That's fine. Will the compiler error be obvious when unprotected commas are found?

Using for loops in the following block would help readability:

https://github.com/SCOREC/particle_structures/blob/f4bba868d625456b4fd39120753bed82cdd23c0f/algorithms/Push.cpp#L325-L343

diamog commented 5 years ago

The compiler error isn't too obvious. For example:

Push.cpp:355:6: error: macro "PARALLEL_FOR_ELEMENTS" passed 5 arguments, but takes just 4 });

You would need to know about the unprotected commas being a problem to understand what this error means.

I was going to use for loops, but I unrolled them since its on the gpu at that point.

cwsmith commented 5 years ago

Closing this issue as we now have a functor/lambda based procedure to abstract these loops:

https://github.com/SCOREC/particle_structures/blob/26fa28dc72dc4a24e607726a00244fcf05d34ba3/test/lambdaTest.cpp#L33-L38