Merge branch 'master' of necada.org:~/repo/qpms

Conflicts:
	misc/201903_finiterectlat_AaroBEC_fatMie.py

Former-commit-id: 6e9130313939be2eec80f4df9a703c8e9cb42456
This commit is contained in:
Marek Nečada 2019-03-26 13:37:16 +02:00
commit 38bd16f94a
6 changed files with 39 additions and 8 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# coding: utf-8 # coding: utf-8
from qpms import Particle, CTMatrix, BaseSpec, FinitePointGroup, ScatteringSystem, TMatrixInterpolator, eV, hbar, c, MaterialInterpolator from qpms import Particle, CTMatrix, BaseSpec, FinitePointGroup, ScatteringSystem, TMatrixInterpolator, eV, hbar, c, MaterialInterpolator, scatsystem_set_nthreads
from qpms.symmetries import point_group_info from qpms.symmetries import point_group_info
from pathlib import Path from pathlib import Path
import numpy as np import numpy as np
@ -8,6 +8,11 @@ import os
import sys import sys
nm = 1e-9 nm = 1e-9
if 'SLURM_CPUS_PER_TASK' in os.environ:
scatsystem_set_nthreads(os.environ['SLURM_CPUS_PER_TASK'])
rewrite_output = '--rewrite-output' in sys.argv rewrite_output = '--rewrite-output' in sys.argv
cyr_part_height = 50*nm cyr_part_height = 50*nm

View File

@ -1,11 +1,15 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# coding: utf-8 # coding: utf-8
from qpms import Particle, CTMatrix, BaseSpec, FinitePointGroup, ScatteringSystem, TMatrixInterpolator, eV, hbar, c, MaterialInterpolator from qpms import Particle, CTMatrix, BaseSpec, FinitePointGroup, ScatteringSystem, TMatrixInterpolator, eV, hbar, c, MaterialInterpolator, scatsystem_set_nthreads
from qpms.symmetries import point_group_info from qpms.symmetries import point_group_info
import numpy as np import numpy as np
import os import os
import sys import sys
from pathlib import Path from pathlib import Path
if 'SLURM_CPUS_PER_TASK' in os.environ:
scatsystem_set_nthreads(os.environ['SLURM_CPUS_PER_TASK'])
nm = 1e-9 nm = 1e-9
rewrite_output = '--rewrite-output' in sys.argv rewrite_output = '--rewrite-output' in sys.argv

View File

@ -1398,6 +1398,10 @@ cdef class Particle:
else: else:
raise ValueError("Position argument has to contain 3 or 2 cartesian coordinates") raise ValueError("Position argument has to contain 3 or 2 cartesian coordinates")
cpdef void scatsystem_set_nthreads(long n):
qpms_scatsystem_set_nthreads(n)
return
cdef class ScatteringSystem: cdef class ScatteringSystem:
''' '''
Wrapper over the C qpms_scatsys_t structure. Wrapper over the C qpms_scatsys_t structure.

View File

@ -290,6 +290,7 @@ cdef extern from "tmatrices.h":
cdef extern from "scatsystem.h": cdef extern from "scatsystem.h":
void qpms_scatsystem_set_nthreads(long n)
struct qpms_particle_t: struct qpms_particle_t:
cart3_t pos cart3_t pos
const qpms_tmatrix_t *tmatrix const qpms_tmatrix_t *tmatrix

View File

@ -22,6 +22,11 @@
#define QPMS_SCATSYS_TMATRIX_RTOL 1e-12 #define QPMS_SCATSYS_TMATRIX_RTOL 1e-12
long qpms_scatsystem_nthreads_default = 4; long qpms_scatsystem_nthreads_default = 4;
long qpms_scatsystem_nthreads_override = 0;
void qpms_scatsystem_set_nthreads(long n) {
qpms_scatsystem_nthreads_override = n;
}
// ------------ Stupid implementation of qpms_scatsys_apply_symmetry() ------------- // ------------ Stupid implementation of qpms_scatsys_apply_symmetry() -------------
@ -1419,13 +1424,20 @@ complex double *qpms_scatsys_build_modeproblem_matrix_irrep_packed_parallelR(
arg = {ss, &opistartR, &opistartR_mutex, iri, target_packed, k}; arg = {ss, &opistartR, &opistartR_mutex, iri, target_packed, k};
// FIXME THIS IS NOT PORTABLE: // FIXME THIS IS NOT PORTABLE:
long nthreads = sysconf(_SC_NPROCESSORS_ONLN); long nthreads;
if (nthreads < 1) { if (qpms_scatsystem_nthreads_override > 0) {
QPMS_WARN("_SC_NPROCESSORS_ONLN returned %ld, using %ld thread(s) instead.", nthreads = qpms_scatsystem_nthreads_override;
nthreads, qpms_scatsystem_nthreads_default); QPMS_WARN("Using overriding value of %ld thread(s).",
nthreads = qpms_scatsystem_nthreads_default; nthreads);
} else { } else {
QPMS_DEBUG("_SC_NRPOCESSORS_ONLN returned %ld.", nthreads); nthreads = sysconf(_SC_NPROCESSORS_ONLN);
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]; pthread_t thread_ids[nthreads];
for(long thi = 0; thi < nthreads; ++thi) for(long thi = 0; thi < nthreads; ++thi)

View File

@ -13,6 +13,11 @@
#include "qpms_types.h" #include "qpms_types.h"
#include <stdbool.h> #include <stdbool.h>
/// Overrides the number of threads spawned by the paralellized functions.
/** TODO MORE DOC which are those? */
void qpms_scatsystem_set_nthreads(long n);
/// A particle, defined by its T-matrix and position. /// A particle, defined by its T-matrix and position.
typedef struct qpms_particle_t { typedef struct qpms_particle_t {
// Does it make sense to ever use other than cartesian coords for this? // Does it make sense to ever use other than cartesian coords for this?