#endif
#else
+/* USE_TLS / COMPILE_TLS not set */
+
#include <errno.h>
-#ifdef OS_WINDOWS
+#if defined(OS_WINDOWS) && !defined(OS_CYGWIN_NT)
#define ALLOC_WINDOWS
#ifndef MEM_LARGE_PAGES
#define MEM_LARGE_PAGES 0x20000000
#include <stdio.h>
#include <fcntl.h>
-#ifndef OS_WINDOWS
+#if !defined(OS_WINDOWS) || defined(OS_CYGWIN_NT)
#include <sys/mman.h>
#ifndef NO_SYSV_IPC
#include <sys/shm.h>
#include <sys/resource.h>
#endif
-#if defined(OS_FREEBSD) || defined(OS_DARWIN)
+#if defined(OS_FREEBSD) || defined(OS_OPENBSD) || defined(OS_DRAGONFLY) || defined(OS_DARWIN)
#include <sys/sysctl.h>
#include <sys/resource.h>
#endif
#elif (defined(OS_DARWIN) || defined(OS_SUNOS)) && defined(C_GCC)
#define CONSTRUCTOR __attribute__ ((constructor))
#define DESTRUCTOR __attribute__ ((destructor))
-#else
+#elif __GNUC__ && INIT_PRIORITY && ((GCC_VERSION >= 40300) || (CLANG_VERSION >= 20900))
#define CONSTRUCTOR __attribute__ ((constructor(101)))
#define DESTRUCTOR __attribute__ ((destructor(101)))
+#else
+#define CONSTRUCTOR __attribute__ ((constructor))
+#define DESTRUCTOR __attribute__ ((destructor))
#endif
#ifdef DYNAMIC_ARCH
size = CPU_ALLOC_SIZE(nums);
ret = sched_getaffinity(0,size,cpusetp);
if (ret!=0) return nums;
- nums = CPU_COUNT_S(size,cpusetp);
+ ret = CPU_COUNT_S(size,cpusetp);
+ if (ret > 0 && ret < nums) nums = ret;
CPU_FREE(cpusetp);
return nums;
#endif
return nums;
}
#endif
-
+
#ifdef OS_HAIKU
int get_num_procs(void) {
static int nums = 0;
#endif
-#if defined(OS_FREEBSD)
+#if defined(OS_FREEBSD) || defined(OS_OPENBSD) || defined(OS_DRAGONFLY)
int get_num_procs(void) {
// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60035
// In the mean time build with USE_OPENMP=0 or link against another
// implementation of OpenMP.
-#if !(defined(OS_WINDOWS) || defined(OS_ANDROID)) && defined(SMP_SERVER)
+#if !((defined(OS_WINDOWS) && !defined(OS_CYGWIN_NT)) || defined(OS_ANDROID)) && defined(SMP_SERVER)
int err;
err = pthread_atfork ((void (*)(void)) BLASFUNC(blas_thread_shutdown), NULL, NULL);
if(err != 0)
extern int openblas_omp_num_threads_env();
int blas_get_cpu_number(void){
-#if defined(OS_LINUX) || defined(OS_WINDOWS) || defined(OS_FREEBSD) || defined(OS_DARWIN) || defined(OS_ANDROID)
+#if defined(OS_LINUX) || defined(OS_WINDOWS) || defined(OS_FREEBSD) || defined(OS_OPENBSD) || defined(OS_DRAGONFLY) || defined(OS_DARWIN) || defined(OS_ANDROID)
int max_num;
#endif
int blas_goto_num = 0;
if (blas_num_threads) return blas_num_threads;
-#if defined(OS_LINUX) || defined(OS_WINDOWS) || defined(OS_FREEBSD) || defined(OS_DARWIN) || defined(OS_ANDROID)
+#if defined(OS_LINUX) || defined(OS_WINDOWS) || defined(OS_FREEBSD) || defined(OS_OPENBSD) || defined(OS_DRAGONFLY) || defined(OS_DARWIN) || defined(OS_ANDROID)
max_num = get_num_procs();
#endif
- blas_goto_num = 0;
+ // blas_goto_num = 0;
#ifndef USE_OPENMP
blas_goto_num=openblas_num_threads_env();
if (blas_goto_num < 0) blas_goto_num = 0;
#endif
- blas_omp_num = 0;
+ // blas_omp_num = 0;
blas_omp_num=openblas_omp_num_threads_env();
if (blas_omp_num < 0) blas_omp_num = 0;
else if (blas_omp_num > 0) blas_num_threads = blas_omp_num;
else blas_num_threads = MAX_CPU_NUMBER;
-#if defined(OS_LINUX) || defined(OS_WINDOWS) || defined(OS_FREEBSD) || defined(OS_DARWIN) || defined(OS_ANDROID)
+#if defined(OS_LINUX) || defined(OS_WINDOWS) || defined(OS_FREEBSD) || defined(OS_OPENBSD) || defined(OS_DRAGONFLY) || defined(OS_DARWIN) || defined(OS_ANDROID)
if (blas_num_threads > max_num) blas_num_threads = max_num;
#endif
}
if (map_address != (void *)-1) {
+#if defined(SMP) && !defined(USE_OPENMP)
LOCK_COMMAND(&alloc_lock);
+#endif
release_info[release_pos].address = map_address;
release_info[release_pos].func = alloc_mmap_free;
release_pos ++;
+#if defined(SMP) && !defined(USE_OPENMP)
UNLOCK_COMMAND(&alloc_lock);
+#endif
}
#ifdef OS_LINUX
#if defined(OS_LINUX) && !defined(NO_WARMUP)
}
#endif
- LOCK_COMMAND(&alloc_lock);
if (map_address != (void *)-1) {
+#if defined(SMP) && !defined(USE_OPENMP)
+ LOCK_COMMAND(&alloc_lock);
+#endif
release_info[release_pos].address = map_address;
release_info[release_pos].func = alloc_mmap_free;
release_pos ++;
+#if defined(SMP) && !defined(USE_OPENMP)
+ UNLOCK_COMMAND(&alloc_lock);
+#endif
}
- UNLOCK_COMMAND(&alloc_lock);
return map_address;
}
NULL,
};
void *(**func)(void *address);
+
+#if defined(USE_OPENMP)
+ if (!memory_initialized) {
+#endif
+
LOCK_COMMAND(&alloc_lock);
if (!memory_initialized) {
}
UNLOCK_COMMAND(&alloc_lock);
+#if defined(USE_OPENMP)
+ }
+#endif
#ifdef DEBUG
printf("Alloc Start ...\n");
do {
if (!memory[position].used && (memory[position].pos == mypos)) {
+#if defined(SMP) && !defined(USE_OPENMP)
LOCK_COMMAND(&alloc_lock);
-// blas_lock(&memory[position].lock);
-
+#else
+ blas_lock(&memory[position].lock);
+#endif
if (!memory[position].used) goto allocation;
-
+#if defined(SMP) && !defined(USE_OPENMP)
UNLOCK_COMMAND(&alloc_lock);
-// blas_unlock(&memory[position].lock);
+#else
+ blas_unlock(&memory[position].lock);
+#endif
}
position ++;
memory[position].used = 1;
UNLOCK_COMMAND(&alloc_lock);
-/* blas_unlock(&memory[position].lock);*/
if (!memory[position].addr) {
do {
} while ((BLASLONG)map_address == -1);
+#if defined(SMP) && !defined(USE_OPENMP)
LOCK_COMMAND(&alloc_lock);
+#endif
memory[position].addr = map_address;
+#if defined(SMP) && !defined(USE_OPENMP)
UNLOCK_COMMAND(&alloc_lock);
+#endif
#ifdef DEBUG
printf(" Mapping Succeeded. %p(%d)\n", (void *)memory[position].addr, position);
#endif
position = 0;
+#if defined(SMP) && !defined(USE_OPENMP)
LOCK_COMMAND(&alloc_lock);
-
+#endif
while ((position < NUM_BUFFERS) && (memory[position].addr != free_area))
position++;
WMB;
memory[position].used = 0;
+#if defined(SMP) && !defined(USE_OPENMP)
UNLOCK_COMMAND(&alloc_lock);
+#endif
#ifdef DEBUG
printf("Unmap Succeeded.\n\n");
for (position = 0; position < NUM_BUFFERS; position++)
printf("%4ld %p : %d\n", position, memory[position].addr, memory[position].used);
#endif
+#if defined(SMP) && !defined(USE_OPENMP)
UNLOCK_COMMAND(&alloc_lock);
-
+#endif
return;
}