Skip to content

Commit

Permalink
Merge pull request qulacs#228 from m-ymzk/refactoring_omputil
Browse files Browse the repository at this point in the history
Refactoring omputil
  • Loading branch information
m-ymzk committed Nov 1, 2022
2 parents 810c6f9 + ee9c7ce commit c65a189
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions src/csim/utility_omp.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// #include <stdio.h>
#include <stdlib.h>
#include <errno.h>

#include "utility.h"

Expand All @@ -14,17 +15,13 @@ static void set_qulacs_num_threads(ITYPE dim, UINT para_threshold) {
if (qulacs_force_threshold) threshold = qulacs_force_threshold;
if (dim < (((ITYPE)1) << threshold)) {
omp_set_num_threads(1);
// printf("# set omp_num_thread = 1\n");
} else {
omp_set_num_threads(qulacs_num_thread_max);
// printf("# set omp_num_thread = %d\n", qulacs_num_thread_max);
// printf("# omp_max_thread = %d\n", omp_get_max_threads());
}
}

static void reset_qulacs_num_threads() {
omp_set_num_threads(qulacs_num_default_thread_max);
// printf("# reset omp_num_thread = %d\n", qulacs_num_default_thread_max);
}

#define REGISTER_METHOD_POINTER(M) omputil->M = M;
Expand All @@ -35,31 +32,24 @@ OMPutil get_omputil() {
}

omputil = malloc(sizeof(*omputil));
// printf("# set omputil initializer entry, %d\n", qulacs_num_thread_max);

errno = 0;
qulacs_num_thread_max = omp_get_max_threads();
{
const char *tmp = getenv("QULACS_NUM_THREADS");
if (tmp) {
const UINT tmp_val = atoi(tmp);
if (0 < tmp_val && tmp_val < 1025) qulacs_num_thread_max = tmp_val;
}
// printf("# set qulacs_num_thread_max = %d\n", qulacs_num_thread_max);
char* endp;
char* tmp = getenv("QULACS_NUM_THREADS");
if (tmp) {
const UINT tmp_val = strtol(tmp, &endp, 0);
if (0 < tmp_val && tmp_val < 1025) qulacs_num_thread_max = tmp_val;
}

qulacs_force_threshold = 0;
{
const char *tmp = getenv("QULACS_FORCE_THRESHOLD");
if (tmp) {
const UINT tmp_val = atoi(tmp);
if (0 < tmp_val && tmp_val < 65) qulacs_force_threshold = tmp_val;
}
// printf("# set qulacs_force_threshold = %d\n", qulacs_force_threshold);
tmp = getenv("QULACS_FORCE_THRESHOLD");
if (tmp) {
const UINT tmp_val = strtol(tmp, &endp, 0);
if (0 < tmp_val && tmp_val < 65) qulacs_force_threshold = tmp_val;
}

qulacs_num_default_thread_max = omp_get_max_threads();
// printf("# set qulacs_num_default_thread_max = %d\n",
// qulacs_num_default_thread_max);

REGISTER_METHOD_POINTER(set_qulacs_num_threads)
REGISTER_METHOD_POINTER(reset_qulacs_num_threads)
Expand Down

0 comments on commit c65a189

Please sign in to comment.