From f23edf0d71bf9b06bdeacfaf062d07652362393f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Tue, 26 Mar 2019 11:54:07 +0200 Subject: [PATCH] Default number of threads in scatsystem.c set to 4, debug messages. Former-commit-id: da244d95534eabe2be07327ba174467935518a12 --- qpms/qpms_error.h | 2 ++ qpms/scatsystem.c | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/qpms/qpms_error.h b/qpms/qpms_error.h index c6591fc..8f80796 100644 --- a/qpms/qpms_error.h +++ b/qpms/qpms_error.h @@ -27,6 +27,8 @@ void qpms_pr_debug_at_flf(const char *filename, unsigned int linenum, #define QPMS_WARN(msg, ...) qpms_warn_at_flf(__FILE__,__LINE__,__func__,msg, ##__VA_ARGS__) +#define QPMS_DEBUG(msg, ...) qpms_pr_debug_at_flf(__FILE__,__LINE__,__func__,msg, ##__VA_ARGS__) + #define QPMS_CRASHING_MALLOC(pointer, size) {(pointer) = malloc(size); if(!pointer && (size)) qpms_pr_debug_at_flf(__FILE__,__LINE__,__func__, "Allocation of %zd bytes for " #pointer " failed.", (size_t) (size));} #define QPMS_CRASHING_REALLOC(pointer, size) {(pointer) = realloc(pointer, size); if(!pointer && (size)) qpms_pr_debug_at_flf(__FILE__,__LINE__,__func__, "Rellocation of %zd bytes for " #pointer " failed.", (size_t) (size));} diff --git a/qpms/scatsystem.c b/qpms/scatsystem.c index f3d421f..b25674a 100644 --- a/qpms/scatsystem.c +++ b/qpms/scatsystem.c @@ -21,6 +21,8 @@ #define QPMS_SCATSYS_TMATRIX_ATOL 1e-14 #define QPMS_SCATSYS_TMATRIX_RTOL 1e-12 +long qpms_scatsystem_nthreads_default = 4; + // ------------ Stupid implementation of qpms_scatsys_apply_symmetry() ------------- #define MIN(x,y) (((x)<(y))?(x):(y)) @@ -1418,8 +1420,13 @@ complex double *qpms_scatsys_build_modeproblem_matrix_irrep_packed_parallelR( // FIXME THIS IS NOT PORTABLE: long nthreads = sysconf(_SC_NPROCESSORS_ONLN); - if (nthreads < 1) nthreads = 1; // If something goes wrong... - + if (nthreads < 1) { + QPMS_WARN("_SC_NPROCESSORS_ONLN returned %ld, using %ld thread(s) instead.", + nthreads, qpms_scatsystem_nthreads_default); + nthreads = qpms_scatsystem_nthreads_default; + } else { + QPMS_DEBUG("_SC_NRPOCESSORS_ONLN returned %ld.", nthreads); + } pthread_t thread_ids[nthreads]; for(long thi = 0; thi < nthreads; ++thi) QPMS_ENSURE_SUCCESS(pthread_create(thread_ids + thi, NULL,