Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/lanl/vpic
Browse files Browse the repository at this point in the history
  • Loading branch information
rfbird committed Aug 23, 2019
2 parents 670b0e4 + 1ebc21e commit 3402e77
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 34 deletions.
18 changes: 13 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ option(ENABLE_INTEGRATED_TESTS "Enable integrated tests" OFF)

option(ENABLE_UNIT_TESTS "Enable unit tests" OFF)

option(ENABLE_PERFORMANCE_TESTS "Enable performance tests" OFF)

option(USE_OPENMP "Use OpenMP" OFF)

option(USE_PTHREADS "Use Pthreads" ON)
Expand Down Expand Up @@ -381,15 +383,15 @@ endif()
if(ENABLE_INTEGRATED_TESTS)
enable_testing()
add_subdirectory(test/integrated)

endif(ENABLE_INTEGRATED_TESTS)

# Add includes for Catch2
set(CATCH_DIR "./test/include")

if(ENABLE_UNIT_TESTS)
enable_testing()

# NOTE: This can also be done by a subdirectory (useful when we have multiple tests)
# Add includes for Catch2
set(TEST_DIR "./test/include")
include_directories(${TEST_DIR})
include_directories(${CATCH_DIR})

# Add tests individually
if (USE_V4)
Expand All @@ -405,6 +407,12 @@ if(ENABLE_UNIT_TESTS)
add_subdirectory(test/unit)

endif(ENABLE_UNIT_TESTS)

if(ENABLE_PERFORMANCE_TESTS)
enable_testing()
include_directories(${CATCH_DIR})
add_subdirectory(test/performance)
endif(ENABLE_PERFORMANCE_TESTS)
#~---------------------------------------------------------------------------~-#
# vim: set tabstop=2 shiftwidth=2 expandtab :
#~---------------------------------------------------------------------------~-#
7 changes: 7 additions & 0 deletions src/util/boot.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "util.h"

#include "stdio.h"

double _boot_timestamp = 0;

double
Expand Down Expand Up @@ -48,6 +50,11 @@ boot_services( int * pargc,
mp_barrier();
_boot_timestamp = 0;
_boot_timestamp = uptime();

if (_world_rank == 0)
{
printf("Booting with %d threads and %d (MPI) ranks \n", thread.n_pipeline, _world_size);
}
}

// This operates in reverse order from boot_services
Expand Down
2 changes: 1 addition & 1 deletion src/vpic/vpic.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class vpic_simulation {
int advance( void );
void finalize( void );

private:
protected:

// Directly initialized by user

Expand Down
2 changes: 2 additions & 0 deletions test/performance/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_subdirectory(perform_uncenter)
#add_subdirectory(perform_advance)
22 changes: 22 additions & 0 deletions test/performance/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# General Idea

The idea behind these tests is to give a user a quick way to benchmark/verify
their install of VPIC for a given platform, and to allow them to collect some
performance data in a reproducible and automated way.

# Tests

## Implemented

- Repeatedly center (`center_p`) and uncenter (`uncenter_p`) the particle
population to give an upper bound of "particle push" speed

## Future

- Add a test to do a full `advance_p` call and then undo it (`uncenter_p`?)

# TODO

- Need to add print output to describe the platform (and possibly the install
configuration of VPIC)

22 changes: 22 additions & 0 deletions test/performance/perform_uncenter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
set(target uncenter)
add_executable(${target} ./uncenter.cpp)
target_link_libraries(${target} vpic)
add_test(NAME ${target} COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 1 ${MPIEXEC_PREFLAGS} ./${target})

set(target uncenter_big)
add_executable(${target} ./uncenter.cpp)
target_compile_definitions(${target} PRIVATE NUM_PARTICLES=4194304)
target_link_libraries(${target} vpic)
add_test(NAME ${target} COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 1 ${MPIEXEC_PREFLAGS} ./${target})

set(target uncenter_sorted)
add_executable(${target} ./uncenter.cpp)
target_compile_definitions(${target} PRIVATE ENABLE_SORT=1)
target_link_libraries(${target} vpic)
add_test(NAME ${target} COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 1 ${MPIEXEC_PREFLAGS} ./${target})

set(target uncenter_sorted_threaded)
add_executable(${target} ./uncenter.cpp)
target_compile_definitions(${target} PRIVATE NUM_THREADS=4)
target_link_libraries(${target} vpic)
add_test(NAME ${target} COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 1 ${MPIEXEC_PREFLAGS} ./${target})
119 changes: 119 additions & 0 deletions test/performance/perform_uncenter/uncenter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#define CATCH_CONFIG_MAIN // This tells Catch to provide a =
#include "catch.hpp"

#include <chrono>

#include "src/species_advance/species_advance.h"
#include "src/vpic/vpic.h"
#include "test/integrated/particle_push/advance_p.h"


class vpic_test_simulation : public vpic_simulation
{
public:
void test()
{
double L = 1e2;
#ifndef NUM_PARTICLES
#define NUM_PARTICLES 1048576 //32768
#endif
int npart = NUM_PARTICLES; // This is independent of the number of cells
int nstep = 100;

define_units( 1, 1 );
define_timestep( 1 );

define_periodic_grid( 0, 0, 0, // Grid low corner
L, L, L, // Grid high corner
8, 8, 8, // Grid resolution
1, 1, 1 ); // Processor configuration

define_material( "vacuum", 1.0, 1.0, 0.0 );
define_field_array();

field(1,1,1).ex = 1;
field(1,2,1).ex = 1;
field(1,1,2).ex = 1;
field(1,2,2).ex = 1;

field(1,1,1).ey = 2;
field(1,1,2).ey = 2;
field(2,1,1).ey = 2;
field(2,1,2).ey = 2;

field(1,1,1).ez = 3;
field(2,1,1).ez = 3;
field(1,2,1).ez = 3;
field(2,2,1).ez = 3;

species_t * sp =
define_species( "test_species", 1., 1., npart, npart, 0, 0 );

for (int i = 0; i < npart; i++)
{
float x = uniform( rng(0), 0, L);
float y = uniform( rng(0), 0, L);
float z = uniform( rng(0), 0, L);

inject_particle( sp , x, y, z, 0., 0., 0., 1., 0., 0);
}

clear_accumulator_array(accumulator_array);

load_interpolator_array( interpolator_array, field_array );

#ifdef ENABLE_SORT
std::cout << "Sort is enabled." << std::endl;
sort_p( sp );
#endif
auto start = std::chrono::system_clock::now();

for( int n=0; n<nstep; n++)
{
uncenter_p( sp, interpolator_array );
center_p( sp, interpolator_array );
}
auto end = std::chrono::system_clock::now();

std::chrono::duration<double> elapsed_seconds = end-start;
auto time_per_p = elapsed_seconds.count() / (sp->np*nstep);
std::cout << "Elapsed time: " << elapsed_seconds.count() << "" << std::endl;
std::cout << "Particles: " << sp->np << ", Steps: " << nstep << std::endl;
std::cout << "Time per particle step: " << time_per_p << ", Particle/s: " << 1.0/time_per_p << std::endl;

}
};

TEST_CASE( "repeatedly center and uncenter particles in a timed loop", "[uncenter]" )
{

#ifndef NUM_THREADS
#define NUM_THREADS 1
#endif

int pargc = 1;

if (NUM_THREADS > 1) { pargc = 3; }

char str[] = "bin/vpic";
char **pargv = (char **) malloc( (pargc+1) *sizeof(char **));
pargv[0] = str;

if (NUM_THREADS > 1)
{
char str2[] = "--tpp";
char str3[] = "" EXPAND_AND_STRINGIFY(NUM_THREADS);
pargv[1] = str2;
pargv[2] = str3;
}

boot_services( &pargc, &pargv );

vpic_test_simulation* simulation = new vpic_test_simulation();
simulation->test();

delete simulation;
if( world_rank==0 ) log_printf( "normal exit\n" );

halt_mp();
}
38 changes: 10 additions & 28 deletions test/unit/particle_push/array_syntax.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ vpic_simulation::user_initialization( int num_cmdline_arguments,
}
}
if( failed )
{ std::cout << "FAIL" << std::endl;
{ std::cout << "FAIL" << std::endl;
}
REQUIRE_FALSE(failed);
}
Expand All @@ -107,41 +107,23 @@ vpic_simulation::user_initialization( int num_cmdline_arguments,
std::cout << "pass" << std::endl;
}

TEST_CASE( "vectors can be sized and resized", "[vector]" ) {

std::vector<int> v( 5 );

REQUIRE( v.size() == 5 );
REQUIRE( v.capacity() >= 5 );
TEST_CASE( "test that calling the push with array syntax matches the result of the old method", "[particle_push]" )
{

//boot_checkpt(NULL, NULL);
int pargc = 0;
char str[] = "bin/vpic";
char **pargv = (char **) malloc(sizeof(char **));
pargv[0] = str;
//serial.boot(&pargc, &pargv);
//thread.boot(&pargc, &pargv);
boot_services( &pargc, &pargv );

SECTION( "resizing bigger changes size and capacity" )
{
int num_particles = 64;
v.resize( 10 );
int num_particles = 64;

REQUIRE( v.size() == 10 );
REQUIRE( v.capacity() >= 10 );
vpic_simulation* simulation = new vpic_simulation;
simulation->initialize( pargc, pargv );

// initialize all the variables
//particle_t *p_arr = particle_arr(num_particles, 1);
//species_t *sp = make_species(p_arr, 1, 1);
simulation->finalize();
delete simulation;
if( world_rank==0 ) log_printf( "normal exit\n" );

vpic_simulation* simulation = new vpic_simulation;
simulation->initialize( pargc, pargv );

simulation->finalize();
delete simulation;
if( world_rank==0 ) log_printf( "normal exit\n" );

halt_mp();
}
halt_mp();
}

0 comments on commit 3402e77

Please sign in to comment.