diff --git a/examples/cpp/ensemble/src/main.cu b/examples/cpp/ensemble/src/main.cu index df87d3a43..a0e104cd1 100644 --- a/examples/cpp/ensemble/src/main.cu +++ b/examples/cpp/ensemble/src/main.cu @@ -17,8 +17,7 @@ FLAMEGPU_INIT_FUNCTION(Init) { std::atomic atomic_init = {0}; std::atomic atomic_result = {0}; FLAMEGPU_EXIT_FUNCTION(Exit) { - atomic_init += FLAMEGPU->environment.getProperty("init"); - atomic_result += FLAMEGPU->agent("Agent").sum("x"); + FLAMEGPU->environment.setProperty("result", FLAMEGPU->agent("Agent").sum("x")); } int main(int argc, const char ** argv) { flamegpu::ModelDescription model("boids_spatial3D"); @@ -35,6 +34,7 @@ int main(int argc, const char ** argv) { env.newProperty("init", 0); env.newProperty("init_offset", 0); env.newProperty("offset", 1); + env.newProperty("result", 0); } { // Agent flamegpu::AgentDescription agent = model.newAgent("Agent"); @@ -64,27 +64,45 @@ int main(int argc, const char ** argv) { runs.setPropertyLerpRange("init_offset", 1, 0); runs.setPropertyLerpRange("offset", 0, 99); } - + /** + * Create a logging config + */ + flamegpu::LoggingConfig exit_log_cfg(model); + exit_log_cfg.logEnvironment("init"); + exit_log_cfg.logEnvironment("result"); /** * Create Model Runner */ flamegpu::CUDAEnsemble cuda_ensemble(model, argc, argv); - + cuda_ensemble.setExitLog(exit_log_cfg); cuda_ensemble.simulate(runs); - // Check result - // Don't currently have logging - unsigned int init_sum = 0; - uint64_t result_sum = 0; - for (int i = 0 ; i < 100; ++i) { + /** + * Check result for each log + */ + const std::map &logs = cuda_ensemble.getLogs(); + unsigned int init_sum = 0, expected_init_sum = 0; + uint64_t result_sum = 0, expected_result_sum = 0; + + for (const auto &[i, log] : logs) { const int init = i/10; const int init_offset = 1 - i/50; - init_sum += init; - result_sum += POPULATION_TO_GENERATE * init + init_offset * ((POPULATION_TO_GENERATE-1)*POPULATION_TO_GENERATE/2); // Initial agent values - result_sum += POPULATION_TO_GENERATE * STEPS * i; // Agent values added by steps + expected_init_sum += init; + expected_result_sum += POPULATION_TO_GENERATE * init + init_offset * ((POPULATION_TO_GENERATE-1)*POPULATION_TO_GENERATE/2); // Initial agent values + expected_result_sum += POPULATION_TO_GENERATE * STEPS * i; // Agent values added by steps + const flamegpu::ExitLogFrame &exit_log = log.getExitLog(); + init_sum += exit_log.getEnvironmentProperty("init"); + result_sum += exit_log.getEnvironmentProperty("result"); + } + printf("Ensemble init: %u, calculated init %u\n", expected_init_sum, init_sum); + printf("Ensemble result: %zu, calculated result %zu\n", expected_result_sum, result_sum); + + /** + * Report if MPI was enabled + */ + if (cuda_ensemble.Config().mpi) { + printf("Local MPI runner completed %u/%u runs.\n", static_cast(logs.size()), static_cast(runs.size())); } - printf("Ensemble init: %u, calculated init %u\n", atomic_init.load(), init_sum); - printf("Ensemble result: %zu, calculated result %zu\n", atomic_result.load(), result_sum); // Ensure profiling / memcheck work correctly flamegpu::util::cleanup();