commit 295f2c1269253874260ddf48d89eee26df7e2960
parent adf0b3137f54dbba6d35d965c64fc984323c5369
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 7 Oct 2021 11:20:38 +0200
Merge branch 'release_0.4.1'
Diffstat:
16 files changed, 116 insertions(+), 74 deletions(-)
diff --git a/README.md b/README.md
@@ -22,10 +22,16 @@ project.
## Release notes
+### Version 0.4.1
+
+- Add a progress log during computations.
+- Sets the CMake minimum version to 3.1: since CMake 3.20, version 2.8 has
+ become obsolete.
+
### Version 0.4
- Remove the raw integration functionality.
-- Rename the `max_steps` integrator attribute in `max_realisation`.
+- Rename the `max_steps` integrator attribute in `max_realisations`.
- Update the profile of the integrand function of the integrator: the
identifier of the thread that invokes the integrand is provided has an input
parameter.
@@ -34,8 +40,7 @@ project.
## License
-Star-MC is Copyright (C) |Meso|Star> 2015-2018 (<contact@meso-star.com>). It is
-a free software released under the [OSI](http://opensource.org)-approved CeCILL
-license. You are welcome to redistribute it under certain conditions; refer to
-the COPYING files for details.
-
+Copyright (C) 2015-2018, 2021 |Meso|Star> (<contact@meso-star.com>).
+Star-MC is free software released under the CeCILLv2.1 license. You are welcome
+to redistribute it under certain conditions; refer to the COPYING files for
+details.
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (C) |Meso|Star> 2015-2018 (contact@meso-star.com)
+# Copyright (C) 2015-2018, 2021 |Meso|Star> (contact@meso-star.com)
#
# This software is a computer program whose purpose is to generate files
# used to build the Star-MC library.
@@ -29,7 +29,7 @@
# The fact that you are presently reading this means that you have had
# knowledge of the CeCILL license and that you accept its terms.
-cmake_minimum_required(VERSION 2.8)
+cmake_minimum_required(VERSION 3.1)
project(star-mc C)
enable_testing()
@@ -60,7 +60,7 @@ include(rcmake_runtime)
################################################################################
set(VERSION_MAJOR 0)
set(VERSION_MINOR 4)
-set(VERSION_PATCH 0)
+set(VERSION_PATCH 1)
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
set(SMC_FILES_SRC
diff --git a/src/smc.h b/src/smc.h
@@ -1,4 +1,4 @@
-/* Copyright (C) |Meso|Star> 2015-2018 (contact@meso-star.com)
+/* Copyright (C) 2015-2018, 2021 |Meso|Star> (contact@meso-star.com)
*
* This software is a computer program whose purpose is to manage the
* statistical estimation of a function.
diff --git a/src/smc_device.c b/src/smc_device.c
@@ -1,4 +1,4 @@
-/* Copyright (C) |Meso|Star> 2015-2018 (contact@meso-star.com)
+/* Copyright (C) 2015-2018, 2021 |Meso|Star> (contact@meso-star.com)
*
* This software is a computer program whose purpose is to manage the
* statistical estimation of a function.
diff --git a/src/smc_device_c.h b/src/smc_device_c.h
@@ -1,4 +1,4 @@
-/* Copyright (C) |Meso|Star> 2015-2018 (contact@meso-star.com)
+/* Copyright (C) 2015-2018, 2021 |Meso|Star> (contact@meso-star.com)
*
* This software is a computer program whose purpose is to manage the
* statistical estimation of a function.
diff --git a/src/smc_doubleN.c b/src/smc_doubleN.c
@@ -1,4 +1,4 @@
-/* Copyright (C) |Meso|Star> 2015-2018 (contact@meso-star.com)
+/* Copyright (C) 2015-2018, 2021 |Meso|Star> (contact@meso-star.com)
*
* This software is a computer program whose purpose is to manage the
* statistical estimation of a function.
diff --git a/src/smc_estimator.c b/src/smc_estimator.c
@@ -1,4 +1,4 @@
-/* Copyright (C) |Meso|Star> 2015-2018 (contact@meso-star.com)
+/* Copyright (C) 2015-2018, 2021 |Meso|Star> (contact@meso-star.com)
*
* This software is a computer program whose purpose is to manage the
* statistical estimation of a function.
@@ -33,6 +33,7 @@
#include "smc_device_c.h"
#include "smc_type_c.h"
+#include <rsys/logger.h>
#include <rsys/mem_allocator.h>
#include <limits.h>
@@ -157,9 +158,11 @@ smc_solve
void** accums = NULL;
void** accums_sqr = NULL;
size_t* nsamples = NULL;
- res_T res = RES_OK;
size_t nfailed = 0;
- int cancel = 0;
+ int progress = 0;
+ ATOMIC cancel = 0;
+ ATOMIC nsolved_realisations = 0;
+ res_T res = RES_OK;
if(!dev || !integrator || !out_estimator || !check_integrator(integrator)) {
res = RES_BAD_ARG;
@@ -198,30 +201,46 @@ smc_solve
if(res != RES_OK) goto error;
/* Parallel evaluation of the simulation */
- #pragma omp parallel shared(cancel, nfailed)
- {
+ logger_print(dev->logger, LOG_OUTPUT, "Solving: %3d%%\r", progress);
+ #pragma omp parallel for schedule(static)
+ for(i = 0; i < (int64_t)integrator->max_realisations; ++i) {
const int ithread = omp_get_thread_num();
- #pragma omp for schedule(static)
- for(i = 0; i < (int64_t)integrator->max_realisations; ++i) {
- if(!cancel) {
- const res_T res_local = integrator->integrand
- (vals[ithread], dev->rngs[ithread], (unsigned)ithread, ctx);
- if(res_local == RES_OK) {
- /* call succeded */
- integrator->type->add(accums[ithread], accums[ithread], vals[ithread]);
- integrator->type->mul(vals[ithread], vals[ithread], vals[ithread]);
- integrator->type->add(accums_sqr[ithread], accums_sqr[ithread], vals[ithread]);
- ++nsamples[ithread];
- } else {
- #pragma omp atomic
- ++nfailed;
- if (nfailed > integrator->max_failures) {
- cancel = 1;
- }
+ int64_t n = 0;
+ int pcent = 0;
+ res_T res_local = RES_OK;
+
+ if(ATOMIC_GET(&cancel)) continue;
+
+ res_local = integrator->integrand
+ (vals[ithread], dev->rngs[ithread], (unsigned)ithread, ctx);
+
+ if(res_local != RES_OK) {
+ #pragma omp critical
+ {
+ nfailed += 1;
+ if(nfailed >= integrator->max_failures) {
+ ATOMIC_SET(&cancel, 1);
}
}
+ continue;
+ }
+
+ /* call succeded */
+ integrator->type->add(accums[ithread], accums[ithread], vals[ithread]);
+ integrator->type->mul(vals[ithread], vals[ithread], vals[ithread]);
+ integrator->type->add(accums_sqr[ithread], accums_sqr[ithread], vals[ithread]);
+ ++nsamples[ithread];
+
+ n = ATOMIC_INCR(&nsolved_realisations);
+ pcent = (int)
+ ((double)n * 100.0 / (double)integrator->max_realisations + 0.5/*round*/);
+ #pragma omp critical
+ if(pcent > progress) {
+ progress = pcent;
+ logger_print(dev->logger, LOG_OUTPUT, "Solving: %3d%%\r", progress);
}
}
+ logger_print(dev->logger, LOG_OUTPUT, "Solving: %3d%%\n", progress);
/* Merge the parallel estimation into the final estimator */
FOR_EACH(i, 0, (int64_t)nthreads) {
@@ -260,11 +279,13 @@ smc_solve_N
const size_t sizeof_ctx,
struct smc_estimator* estimators[])
{
- res_T res = RES_OK;
+ void** vals = NULL;
int64_t i;
unsigned nthreads = 0;
- void** vals = NULL;
- int cancel = 0;
+ int progress = 0;
+ ATOMIC cancel = 0;
+ ATOMIC nsolved = 0;
+ res_T res = RES_OK;
if(!estimators) {
res = RES_BAD_ARG;
@@ -297,36 +318,52 @@ smc_solve_N
}
/* Parallel estimation of N simulations */
- #pragma omp parallel shared(cancel)
- {
+ logger_print(dev->logger, LOG_OUTPUT, "Solving: %3d%%\r", progress);
+ #pragma omp parallel for schedule(static, 1)
+ for(i = 0; i < (int64_t)count; ++i) {
+ size_t istep;
+ int64_t n = 0;
+ int pcent = 0;
const int ithread = omp_get_thread_num();
- #pragma omp for schedule(static, 1)
- for(i = 0; i < (int64_t)count; ++i) {
- size_t istep;
- FOR_EACH(istep, 0, integrator->max_realisations) {
- if(!cancel) {
- const res_T res_local = integrator->integrand
- (vals[ithread], dev->rngs[ithread], (unsigned)ithread,
- (char*)ctx + (size_t)i*sizeof_ctx);
- if(res_local == RES_OK) {
- /* call succeded */
- integrator->type->add
- (estimators[i]->value, estimators[i]->value, vals[ithread]);
- integrator->type->mul(vals[ithread], vals[ithread], vals[ithread]);
- integrator->type->add
- (estimators[i]->square_value, estimators[i]->square_value, vals[ithread]);
- ++estimators[i]->nsamples;
- } else {
- #pragma omp atomic
- ++estimators[i]->nfailed;
- if (estimators[i]->nfailed > integrator->max_failures) {
- cancel = 1;
- }
- }
+ res_T res_local = RES_OK;
+
+ if(ATOMIC_GET(&cancel)) continue;
+
+ FOR_EACH(istep, 0, integrator->max_realisations) {
+ if(ATOMIC_GET(&cancel)) break;
+
+ res_local = integrator->integrand
+ (vals[ithread], dev->rngs[ithread], (unsigned)ithread,
+ (char*)ctx + (size_t)i*sizeof_ctx);
+
+ if(res_local != RES_OK) {
+ ++estimators[i]->nfailed;
+ if(estimators[i]->nfailed > integrator->max_failures) {
+ ATOMIC_SET(&cancel, 1);
}
+ break;
}
+
+ /* call succeded */
+ integrator->type->add
+ (estimators[i]->value, estimators[i]->value, vals[ithread]);
+ integrator->type->mul
+ (vals[ithread], vals[ithread], vals[ithread]);
+ integrator->type->add
+ (estimators[i]->square_value, estimators[i]->square_value, vals[ithread]);
+ ++estimators[i]->nsamples;
+ }
+
+ n = ATOMIC_INCR(&nsolved);
+ pcent = (int)((double)n * 100.0 / (double)count + 0.5/*round*/);
+ #pragma omp critical
+ if(pcent > progress) {
+ progress = pcent;
+ logger_print(dev->logger, LOG_OUTPUT, "Solving: %3d%%\r", progress);
}
+
}
+ logger_print(dev->logger, LOG_OUTPUT, "Solving: %3d%%\n", progress);
exit:
if(vals) {
diff --git a/src/smc_type.c b/src/smc_type.c
@@ -1,4 +1,4 @@
-/* Copyright (C) |Meso|Star> 2015-2018 (contact@meso-star.com)
+/* Copyright (C) 2015-2018, 2021 |Meso|Star> (contact@meso-star.com)
*
* This software is a computer program whose purpose is to manage the
* statistical estimation of a function.
diff --git a/src/smc_type_c.h b/src/smc_type_c.h
@@ -1,4 +1,4 @@
-/* Copyright (C) |Meso|Star> 2015-2018 (contact@meso-star.com)
+/* Copyright (C) 2015-2018, 2021 |Meso|Star> (contact@meso-star.com)
*
* This software is a computer program whose purpose is to manage the
* statistical estimation of a function.
diff --git a/src/smc_type_real.h b/src/smc_type_real.h
@@ -1,4 +1,4 @@
-/* Copyright (C) |Meso|Star> 2015-2018 (contact@meso-star.com)
+/* Copyright (C) 2015-2018, 2021 |Meso|Star> (contact@meso-star.com)
*
* This software is a computer program whose purpose is to manage the
* statistical estimation of a function.
diff --git a/src/test_smc_device.c b/src/test_smc_device.c
@@ -1,4 +1,4 @@
-/* Copyright (C) |Meso|Star> 2015-2018 (contact@meso-star.com)
+/* Copyright (C) 2015-2018, 2021 |Meso|Star> (contact@meso-star.com)
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
diff --git a/src/test_smc_doubleN.c b/src/test_smc_doubleN.c
@@ -1,4 +1,4 @@
-/* Copyright (C) |Meso|Star> 2015-2018 (contact@meso-star.com)
+/* Copyright (C) 2015-2018, 2021 |Meso|Star> (contact@meso-star.com)
*
* This software is a computer program whose purpose is to manage the
* statistical estimation of a function.
diff --git a/src/test_smc_errors.c b/src/test_smc_errors.c
@@ -1,4 +1,4 @@
-/* Copyright (C) |Meso|Star> 2015-2018 (contact@meso-star.com)
+/* Copyright (C) 2015-2018, 2021 |Meso|Star> (contact@meso-star.com)
*
* This software is a computer program whose purpose is to manage the
* statistical estimation of a function.
diff --git a/src/test_smc_light_path.c b/src/test_smc_light_path.c
@@ -1,4 +1,4 @@
-/* Copyright (C) |Meso|Star> 2015-2018 (contact@meso-star.com)
+/* Copyright (C) 2015-2018, 2021 |Meso|Star> (contact@meso-star.com)
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
@@ -378,7 +378,7 @@ main(int argc, char** argv)
integrator.integrand = light_path_integrator;
integrator.type = &smc_float;
- integrator.max_realisations = 4;
+ integrator.max_realisations = 64;
contexts = MEM_CALLOC
(&allocator, IMG_WIDTH*IMG_HEIGHT, sizeof(struct integrator_context));
@@ -418,7 +418,7 @@ main(int argc, char** argv)
CHK(smc_estimator_ref_put(estimators[iestimator]) == RES_OK);
}}
- image_write_ppm_stream(&img, 0, stdout);
+ image_write_ppm_stream(&img, 0, stderr);
CHK(image_release(&img) == RES_OK);
MEM_RM(&allocator, contexts);
diff --git a/src/test_smc_solve.c b/src/test_smc_solve.c
@@ -1,4 +1,4 @@
-/* Copyright (C) |Meso|Star> 2015-2018 (contact@meso-star.com)
+/* Copyright (C) 2015-2018, 2021 |Meso|Star> (contact@meso-star.com)
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
diff --git a/src/test_smc_utils.h b/src/test_smc_utils.h
@@ -1,4 +1,4 @@
-/* Copyright (C) |Meso|Star> 2015-2018 (contact@meso-star.com)
+/* Copyright (C) 2015-2018, 2021 |Meso|Star> (contact@meso-star.com)
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,