Commit 076c10d1 authored by Berrill, Mark's avatar Berrill, Mark
Browse files

Updating miniapp

parent f35b03f6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ cmake \
   -D CMAKE_CXX_COMPILER=g++            \
   -D CXX_STD=11                        \
   -D USE_OPENACC=0                     \
   -D USE_OPENMP=1                      \
   -D USE_KOKKOS=0                      \
      -D KOKKOS_DIRECTORY=/usr/local/kokkos \
      -D KOKKOS_WRAPPER=/usr/local/kokkos/config/nvcc_wrapper \
+19 −2
Original line number Diff line number Diff line
@@ -43,6 +43,23 @@ INCLUDE( Find_TIMER.cmake )
CONFIGURE_TIMER( 0 "" )


# Enable OpenMP
IF ( USE_OPENMP )
    ADD_DEFINITIONS( -DUSE_OPENMP )
    IF ( USING_GCC )
        SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp")
        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
    ELSEIF ( USING_CRAY )
    ELSEIF ( USING_PGCC )
        SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -openmp")
        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -openmp")
    ELSE()
        MESSAGE(FATAL_ERROR "Compiling with OpenMP is not yet set for this compiler")
    ENDIF()
    MESSAGE( "Using OpenMP" )
ENDIF()


# Enable OpenACC
IF ( USE_OPENACC )
    ADD_DEFINITIONS( -DUSE_OPENACC )
@@ -96,7 +113,7 @@ IF ( USE_CUDA )
    ENDIF()
    IF(NOT CUDA_NVCC_FLAGS)
        # Set minimum requirements
        SET( CUDA_NVCC_FLAGS "-arch=sm_20 ${CXX_STD_FLAG}" )
        SET( CUDA_NVCC_FLAGS "-arch=sm_30 ${CXX_STD_FLAG}" )
    ENDIF()
    IF ( ${CMAKE_BUILD_TYPE} STREQUAL "Debug" )
        SET( CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -lineinfo" )
@@ -138,7 +155,7 @@ ADD_DISTCLEAN( libRayTrace.* null_timer CreateImage* )
# Create the library
INCLUDE_DIRECTORIES( ${RAYTRACE_SOURCE_DIR} )
ADD_DEFINITIONS( -DDISABLE_WRITE_FAILED_RAYS )
SET( SOURCES RayTrace RayTrace.cpp RayTraceStructures.cpp utilities/RayUtilities.cpp interp.cpp RayTraceImageCPU.cpp )
SET( SOURCES RayTrace RayTraceImage.cpp RayTraceStructures.cpp utilities/RayUtilities.cpp interp.cpp RayTraceImageCPU.cpp )
IF ( USE_OPENACC )
    SET( SOURCES ${SOURCES} RayTraceImageOpenACC.cpp )
ENDIF()
+202 −160
Original line number Diff line number Diff line
@@ -2,28 +2,39 @@
// This miniapp mimics the behavior of create_image

#include "RayTrace.h"
#include <cstring>
#include <iostream>
#include <math.h>
#include <sstream>
#include <stdint.h>
#include <string>
#include <cstring>
#include <sstream>
#include <math.h>

#if defined( WIN32 ) || defined( _WIN32 ) || defined( WIN64 ) || defined( _WIN64 )
#include <windows.h>
#define get_time( x ) QueryPerformanceCounter( x )
#define get_frequency( f ) QueryPerformanceFrequency( f )
    #define get_diff(start,end,f) \
        static_cast<double>(end.QuadPart-start.QuadPart)/static_cast<double>(f.QuadPart)
#define TIME_TYPE LARGE_INTEGER
#define sleep_ms Sleep
inline double get_diff( TIME_TYPE start, TIME_TYPE end, TIME_TYPE f )
{
    return ( ( (double) ( end.QuadPart - start.QuadPart ) ) / ( (double) f.QuadPart ) );
}
#else
#include <sys/time.h>
#define get_time( x ) gettimeofday( x, NULL );
#define get_frequency( f ) ( *f = timeval() )
    #define get_diff(start,end,f) 1e-6*static_cast<double>( \
        0xF4240*(static_cast<int64_t>(end.tv_sec)-static_cast<int64_t>(start.tv_sec)) + \
                (static_cast<int64_t>(end.tv_usec)-static_cast<int64_t>(start.tv_usec)) )
#define TIME_TYPE timeval
#define sleep_ms( X )                        \
    do {                                     \
        struct timespec ts;                  \
        ts.tv_sec  = X / 1000;               \
        ts.tv_nsec = ( X % 1000 ) * 1000000; \
        nanosleep( &ts, NULL );              \
    } while ( 0 )
inline double get_diff( TIME_TYPE start, TIME_TYPE end, TIME_TYPE )
{
    return ( (double) end.tv_sec - start.tv_sec ) + 1e-6 * ( (double) end.tv_usec - start.tv_usec );
}
#endif

#ifdef USE_KOKKOS
@@ -42,8 +53,8 @@ inline void fread2( void *ptr, size_t size, size_t count, FILE *fid )


// Check the answer
inline int check_ans( const double *image0, const double *I_ang0,
    const RayTrace::create_image_struct& data )
inline int check_ans(
    const double *image0, const double *I_ang0, const RayTrace::create_image_struct &data )
{
    size_t N_image  = data.euv_beam->nx * data.euv_beam->ny * data.euv_beam->nv;
    size_t N_ang    = data.euv_beam->na * data.euv_beam->nb;
@@ -66,9 +77,11 @@ inline int check_ans( const double *image0, const double *I_ang0,
    norm1[1] = sqrt( norm1[1] );
    error[0] = sqrt( error[0] ) / norm0[0];
    error[1] = sqrt( error[1] ) / norm0[1];
    const double tol = 5e-6;    // RayTrace uses single precision for some calculations (may need to adjust to 1e-5)
    const double tol =
        5e-6; // RayTrace uses single precision for some calculations (may need to adjust to 1e-5)
    // bool pass = error[0]<=tol && error[1]<=tol;
    bool pass = (norm0[0]-norm1[0])/norm0[0]<=tol && (norm0[1]-norm1[1])/norm0[1]<=tol;
    bool pass =
        ( norm0[0] - norm1[0] ) / norm0[0] <= tol && ( norm0[1] - norm1[1] ) / norm0[1] <= tol;
    if ( !pass ) {
        std::cerr << "  Answers do not match:" << std::endl;
        std::cerr << "    image: " << error[0] << " " << norm0[0] << " " << norm1[0] << std::endl;
@@ -79,7 +92,8 @@ inline int check_ans( const double *image0, const double *I_ang0,


// Scale the input problem
template<class TYPE> void scale_beam( TYPE& beam, double scale )
template <class TYPE>
void scale_beam( TYPE &beam, double scale )
{
    const double x[2] = { beam.x[0] - 0.5 * beam.dx, beam.x[beam.nx - 1] + 0.5 * beam.dx };
    const double y[2] = { beam.y[0] - 0.5 * beam.dy, beam.y[beam.ny - 1] + 0.5 * beam.dy };
@@ -89,24 +103,41 @@ template<class TYPE> void scale_beam( TYPE& beam, double scale )
    int ny            = static_cast<int>( beam.ny * scale );
    int na            = static_cast<int>( beam.na * scale );
    int nb            = static_cast<int>( beam.nb * scale );
    delete [] beam.x;   beam.x = new double[nx];
    delete [] beam.y;   beam.y = new double[ny];
    delete [] beam.a;   beam.a = new double[na];
    delete [] beam.b;   beam.b = new double[nb];
    beam.nx = nx;       beam.dx = (x[1]-x[0])/nx;
    beam.ny = ny;       beam.dy = (y[1]-y[0])/ny;
    beam.na = na;       beam.da = (a[1]-a[0])/na;
    beam.nb = nb;       beam.db = (b[1]-b[0])/nb;
    for (int i=0; i<nx; i++) { beam.x[i] = x[0] + (0.5+i)*beam.dx; }
    for (int i=0; i<ny; i++) { beam.y[i] = y[0] + (0.5+i)*beam.dy; }
    for (int i=0; i<na; i++) { beam.a[i] = a[0] + (0.5+i)*beam.da; }
    for (int i=0; i<nb; i++) { beam.b[i] = b[0] + (0.5+i)*beam.db; }
    delete[] beam.x;
    beam.x = new double[nx];
    delete[] beam.y;
    beam.y = new double[ny];
    delete[] beam.a;
    beam.a = new double[na];
    delete[] beam.b;
    beam.b  = new double[nb];
    beam.nx = nx;
    beam.dx = ( x[1] - x[0] ) / nx;
    beam.ny = ny;
    beam.dy = ( y[1] - y[0] ) / ny;
    beam.na = na;
    beam.da = ( a[1] - a[0] ) / na;
    beam.nb = nb;
    beam.db = ( b[1] - b[0] ) / nb;
    for ( int i = 0; i < nx; i++ ) {
        beam.x[i] = x[0] + ( 0.5 + i ) * beam.dx;
    }
    for ( int i = 0; i < ny; i++ ) {
        beam.y[i] = y[0] + ( 0.5 + i ) * beam.dy;
    }
    for ( int i = 0; i < na; i++ ) {
        beam.a[i] = a[0] + ( 0.5 + i ) * beam.da;
    }
    for ( int i = 0; i < nb; i++ ) {
        beam.b[i] = b[0] + ( 0.5 + i ) * beam.db;
    }
}
void scale_problem( RayTrace::create_image_struct &info, double scale )
{
    scale_beam( *const_cast<RayTrace::EUV_beam_struct *>( info.euv_beam ), pow( scale, 0.25 ) );
    if ( info.seed_beam != NULL )
        scale_beam(*const_cast<RayTrace::seed_beam_struct*>(info.seed_beam),pow(scale,0.25));
        scale_beam(
            *const_cast<RayTrace::seed_beam_struct *>( info.seed_beam ), pow( scale, 0.25 ) );
}


@@ -118,26 +149,33 @@ int main(int argc, char *argv[])

// Initialize kokkos
#ifdef USE_KOKKOS
        /*int argc2 = 1;
#ifdef KOKKOS_HAVE_PTHREAD
    int argc2             = 1;
    const char *argv2[10] = { NULL };
    argv2[0]              = argv[0];
#ifdef KOKKOS_HAVE_PTHREAD
            argv2[argc2] = "--kokkos-threads=4";
    argv2[argc2] = "--kokkos-threads=16";
    argc2++;
#endif
        Kokkos::initialize(argc2,(char**)argv2);*/
    Kokkos::initialize( argc2, (char **) argv2 );
#else
    Kokkos::initialize( argc, argv );
#endif
#endif

    // Check the input arguments
    const char *err_msg = "CreateImage called with the wrong number of arguments:\n"
                          "  CreateImage <args> file.dat\n"
                          "Optional arguments:\n"
        "  -methods=METHODS  Comma seperated list of methods to test.  Default is all availible methods\n"
        "                    cpu, threads, Cuda, OpenAcc, Kokkos-Serial, Kokkos-Thread, Kokkos-OpenMP, Kokkos-Cuda\n";
        "  -iterations=N     Number of iterations to run.  Time returned will be the average time/iteration.\n"
        "  -scale=factor     Increate the size of the problem by ~ this factor. (2.0 - twice as expensive)\n"
        "                    Note: this will disable checking the answer.\n";
                          "  -methods=METHODS  Comma seperated list of methods to test.  Default "
                          "is all availible methods\n"
                          "                    cpu, threads, OpenMP, Cuda, OpenAcc, Kokkos-Serial, "
                          "Kokkos-Thread, Kokkos-OpenMP, Kokkos-Cuda\n"
                          "  -iterations=N     Number of iterations to run.  Time returned will be "
                          "the average time/iteration.\n"
                          "  -scale=factor     Increate the size of the problem by ~ this factor. "
                          "(2.0 - twice as expensive)\n"
                          "                    Note: this will disable checking the answer.\n"
                          "                    Note: the scale factor is only approximate.\n";
    if ( argc < 2 ) {
        std::cerr << err_msg;
@@ -149,7 +187,6 @@ int main(int argc, char *argv[])
    double scale   = 1.0;
    for ( int i = 1; i < argc - 1; i++ ) {
        if ( strncmp( argv[i], "-methods=", 9 ) == 0 ) {
            std::string tmp(&argv[i][9]);
            std::stringstream ss( &argv[i][9] );
            std::string token;
            while ( std::getline( ss, token, ',' ) )
@@ -179,14 +216,17 @@ int main(int argc, char *argv[])
    // Create the image structure
    RayTrace::create_image_struct info;
    info.unpack( std::pair<char *, size_t>( data, N_bytes ) );
    delete [] data;  data = NULL;
    delete[] data;
    data                 = NULL;
    const double *image0 = info.image;
    const double *I_ang0 = info.I_ang;
    info.image           = NULL;
    info.I_ang           = NULL;
    if ( scale != 1.0 ) {
        delete [] image0;   image0 = NULL;
        delete [] I_ang0;   I_ang0 = NULL;
        delete[] image0;
        image0 = NULL;
        delete[] I_ang0;
        I_ang0 = NULL;
        scale_problem( info, scale );
    }

@@ -196,6 +236,9 @@ int main(int argc, char *argv[])
#if CXX_STD == 11 || CXX_STD == 14
        methods.push_back( "threads" );
#endif
#ifdef USE_OPENMP
        methods.push_back( "OpenMP" );
#endif
#ifdef USE_CUDA
        methods.push_back( "Cuda" );
#endif
@@ -218,6 +261,7 @@ int main(int argc, char *argv[])

    // Call create_image for each method
    int N_errors = 0;
    sleep_ms( 50 );
    std::vector<double> time( methods.size() );
    for ( size_t i = 0; i < methods.size(); i++ ) {
        printf( "Running %s\n", methods[i].c_str() );
@@ -256,5 +300,3 @@ int main(int argc, char *argv[])
#endif
    return N_errors;
}

src/RayTrace.cpp

deleted100644 → 0
+0 −427

File deleted.

Preview size limit exceeded, changes collapsed.

src/RayTrace.h

100755 → 100644
+78 −82
Original line number Diff line number Diff line
@@ -4,9 +4,9 @@

#include "RayTraceStructures.h"

#include <ostream>
#include <stdio.h>
#include <stdlib.h>
#include <ostream>


/*! \namespace RayTrace
@@ -34,9 +34,8 @@ namespace RayTrace {
 * @param[out] Iv           The output intensity (1xK)
 * @param[out] ray2         The output ray properties (x,y,a,b)
 */
    int calc_ray( const double ray[4], const int N, const double dz, 
        const ray_gain_struct *gain, const ray_seed_struct *seed, 
        int K, int method, double *Iv, double *ray2 );
int calc_ray( const double ray[4], const int N, const double dz, const ray_gain_struct *gain,
    const ray_seed_struct *seed, int K, int method, double *Iv, double *ray2 );


/*!
@@ -68,9 +67,8 @@ namespace RayTrace {
 * @param[out] Ir           The intensity vs length for the ray paths ( N x Nx x Ny x Na x Nb )
 */
int calc_ray_path( int Nx, int Ny, int Na, int Nb, const double *x, const double *y,
        const double *a, const double *b, const int N, const double dz, 
        const ray_gain_struct *gain, const ray_seed_struct *seed, 
        int K, const double *dv, int method, double c,
    const double *a, const double *b, const int N, const double dz, const ray_gain_struct *gain,
    const ray_seed_struct *seed, int K, const double *dv, int method, double c,
    std::vector<float> &xr, std::vector<float> &yr, std::vector<float> &Ir );


@@ -91,13 +89,11 @@ namespace RayTrace {
 * @brief  Function to create the EUV beam images
 * @details  This function calculates the near and far field beam images.  This function is
 * thread-safe provided unique arrays for mem, image, I_ang are provided in the info struct.
     * @param info          Data structure containing the information needed to create the EUV beam images
 * @param info          Data structure containing the information needed to create the EUV beam
 * images
 */
void create_image( create_image_struct *info, std::string method = "auto" );


}


#endif
Loading