Commit f6b75075 authored by Berrill, Mark's avatar Berrill, Mark
Browse files

Fixing OpenACC bug

parent 750bc065
Loading
Loading
Loading
Loading
+17 −19
Original line number Diff line number Diff line
#include "common/RayTraceImageHelper.h"

// Get the index
#pragma acc routine seq
inline int getIndex( int n, const double *x, double dx, double y )
{
    if ( y < x[0] - 0.5 * dx || y > x[n - 1] + 0.5 * dx )
        return -1;
    return findfirstsingle( x, n, y - 0.5 * dx );
}


void RayTraceImageOpenAccLoop( int N, const RayTrace::EUV_beam_struct &beam, double db,
    const double *dv, const RayTrace::ray_gain_struct *gain_in,
    const RayTrace::ray_seed_struct *seed_in, int method, const std::vector<ray_struct> &rays,
    double scale, double *image, double *I_ang, unsigned int &failure_code,
    std::vector<ray_struct> &failed_rays )
void RayTraceImageOpenAccLoop( int N, const RayTrace::EUV_beam_struct &beam,
    const RayTrace::ray_gain_struct *gain_in, const RayTrace::ray_seed_struct *seed_in,
    int method, const std::vector<ray_struct> &rays, double scale, double *image,
    double *I_ang, unsigned int &failure_code, std::vector<ray_struct> &failed_rays )
{
    // Copy some variables
    const int nx     = beam.nx;
@@ -71,20 +79,10 @@ void RayTraceImageOpenAccLoop( int N, const RayTrace::EUV_beam_struct &beam, dou
                }
            }
            // Get the indicies to the cells in image and I_ang
            // Note: do not replace these lines with findindex, we need to be able to return 0 for
            // the index
            int i1 = static_cast<int>( findfirstsingle( x, nx, ray2.x - 0.5 * dx ) );
            int i2 = static_cast<int>( findfirstsingle( y, ny, ray2.y - 0.5 * dy ) );
            int i3 = static_cast<int>( findfirstsingle( a, na, ray2.a - 0.5 * da ) );
            int i4 = static_cast<int>( findfirstsingle( b, nb, ray2.b - 0.5 * db ) );
            if ( ray2.x < x[0] - 0.5 * dx || ray2.x > x[nx - 1] + 0.5 * dx )
                i1 = -1; // The ray's z position is out of the range of image
            if ( ray2.y < y[0] - 0.5 * dy || ray2.y > y[ny - 1] + 0.5 * dy )
                i2 = -1; // The ray's y position is out of the range of image
            if ( -ray2.a < a[0] - 0.5 * da || -ray2.a > a[na - 1] + 0.5 * da )
                i3 = -1; // The ray's z angle is out of the range of I_ang
            if ( -ray2.b < b[0] - 0.5 * db || -ray2.b > b[nb - 1] + 0.5 * db )
                i4 = -1; // The ray's y angle is out of the range of I_ang
            int i1 = getIndex( nx, x, dx, ray2.x );
            int i2 = getIndex( ny, y, dy, ray2.y );
            int i3 = getIndex( na, a, da, ray2.a );
            int i4 = getIndex( nb, b, db, ray2.b );
            // Copy I_out into image
            if ( i1 >= 0 && i2 >= 0 ) {
                double *Iv2 = &image[nv * ( i1 + i2 * nx )];