Elegant (and typical) workaround for OpenMP reduction on complex variable in C++?

后端 未结 2 603
遥遥无期
遥遥无期 2020-12-30 04:45

I realize that reduction is only usable for POD types in C++. What would you do to implement a reduction for a complex type accumulator?

complex

        
2条回答
  •  甜味超标
    2020-12-30 05:08

    The typical workaround in absence of user-defined reductions in OpenMP is even uglier than what you suggested. Usually, prior to the parallel region people create an array of (at least) as many elements as there will be threads in the region, accumulate partial results separately for each thread using omp_get_thread_num() as an index to the array, and do final reduction of the accumulated results in a loop after the parallel region.

    As far as I know, OpenMP language committee works on adding user-defined reductions to the specification, so maybe it will be finally resolved in a few years.

提交回复
热议问题