Move the threads overflow flag under the protection of the local blas lock (#3476)

* Move accesses to the overflow flag into the scope of the blas lock
This commit is contained in:
Martin Kroeker 2021-12-13 08:34:52 +01:00 committed by GitHub
parent b0a590f4fe
commit c8d05aa7a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 17 deletions

View File

@ -2871,13 +2871,9 @@ void *blas_memory_alloc(int procpos){
position ++; position ++;
} while (position < NUM_BUFFERS); } while (position < NUM_BUFFERS);
#if (defined(SMP) || defined(USE_LOCKING)) && !defined(USE_OPENMP)
UNLOCK_COMMAND(&alloc_lock);
#endif
if (memory_overflowed) { if (memory_overflowed) {
#if (defined(SMP) || defined(USE_LOCKING)) && !defined(USE_OPENMP)
LOCK_COMMAND(&alloc_lock);
#endif
do { do {
RMB; RMB;
#if defined(USE_OPENMP) #if defined(USE_OPENMP)
@ -2893,10 +2889,10 @@ void *blas_memory_alloc(int procpos){
position ++; position ++;
} while (position < 512+NUM_BUFFERS); } while (position < 512+NUM_BUFFERS);
}
#if (defined(SMP) || defined(USE_LOCKING)) && !defined(USE_OPENMP) #if (defined(SMP) || defined(USE_LOCKING)) && !defined(USE_OPENMP)
UNLOCK_COMMAND(&alloc_lock); UNLOCK_COMMAND(&alloc_lock);
#endif #endif
}
goto error; goto error;
allocation : allocation :
@ -3001,6 +2997,9 @@ void *blas_memory_alloc(int procpos){
return (void *)memory[position].addr; return (void *)memory[position].addr;
error: error:
#if (defined(SMP) || defined(USE_LOCKING)) && !defined(USE_OPENMP)
LOCK_COMMAND(&alloc_lock);
#endif
if (memory_overflowed) goto terminate; if (memory_overflowed) goto terminate;
fprintf(stderr,"OpenBLAS warning: precompiled NUM_THREADS exceeded, adding auxiliary array for thread metadata.\n"); fprintf(stderr,"OpenBLAS warning: precompiled NUM_THREADS exceeded, adding auxiliary array for thread metadata.\n");
memory_overflowed=1; memory_overflowed=1;
@ -3014,7 +3013,6 @@ void *blas_memory_alloc(int procpos){
newmemory[i].used = 0; newmemory[i].used = 0;
newmemory[i].lock = 0; newmemory[i].lock = 0;
} }
newmemory[position-NUM_BUFFERS].used = 1;
allocation2: allocation2:
newmemory[position-NUM_BUFFERS].used = 1; newmemory[position-NUM_BUFFERS].used = 1;
@ -3086,6 +3084,9 @@ allocation2:
return (void *)newmemory[position-NUM_BUFFERS].addr; return (void *)newmemory[position-NUM_BUFFERS].addr;
terminate: terminate:
#if (defined(SMP) || defined(USE_LOCKING)) && !defined(USE_OPENMP)
UNLOCK_COMMAND(&alloc_lock);
#endif
printf("OpenBLAS : Program is Terminated. Because you tried to allocate too many memory regions.\n"); printf("OpenBLAS : Program is Terminated. Because you tried to allocate too many memory regions.\n");
printf("This library was built to support a maximum of %d threads - either rebuild OpenBLAS\n", NUM_BUFFERS); printf("This library was built to support a maximum of %d threads - either rebuild OpenBLAS\n", NUM_BUFFERS);
printf("with a larger NUM_THREADS value or set the environment variable OPENBLAS_NUM_THREADS to\n"); printf("with a larger NUM_THREADS value or set the environment variable OPENBLAS_NUM_THREADS to\n");