@@ -2871,32 +2871,28 @@ void *blas_memory_alloc(int procpos){
28712871 position ++ ;
28722872
28732873 } while (position < NUM_BUFFERS );
2874- #if (defined(SMP ) || defined(USE_LOCKING )) && !defined(USE_OPENMP )
2875- UNLOCK_COMMAND (& alloc_lock );
2876- #endif
2874+
28772875 if (memory_overflowed ) {
2878- #if (defined(SMP ) || defined(USE_LOCKING )) && !defined(USE_OPENMP )
2879- LOCK_COMMAND (& alloc_lock );
2880- #endif
2881- do {
2882- RMB ;
2876+
2877+ do {
2878+ RMB ;
28832879#if defined(USE_OPENMP )
2884- if (!newmemory [position - NUM_BUFFERS ].used ) {
2885- blas_lock (& newmemory [position - NUM_BUFFERS ].lock );
2880+ if (!newmemory [position - NUM_BUFFERS ].used ) {
2881+ blas_lock (& newmemory [position - NUM_BUFFERS ].lock );
28862882#endif
2887- if (!newmemory [position - NUM_BUFFERS ].used ) goto allocation2 ;
2883+ if (!newmemory [position - NUM_BUFFERS ].used ) goto allocation2 ;
28882884
28892885#if defined(USE_OPENMP )
2890- blas_unlock (& newmemory [position - NUM_BUFFERS ].lock );
2891- }
2886+ blas_unlock (& newmemory [position - NUM_BUFFERS ].lock );
2887+ }
28922888#endif
2893- position ++ ;
2889+ position ++ ;
28942890
2895- } while (position < 512 + NUM_BUFFERS );
2891+ } while (position < 512 + NUM_BUFFERS );
2892+ }
28962893#if (defined(SMP ) || defined(USE_LOCKING )) && !defined(USE_OPENMP )
28972894 UNLOCK_COMMAND (& alloc_lock );
28982895#endif
2899- }
29002896 goto error ;
29012897
29022898 allocation :
@@ -3001,6 +2997,9 @@ void *blas_memory_alloc(int procpos){
30012997 return (void * )memory [position ].addr ;
30022998
30032999 error :
3000+ #if (defined(SMP ) || defined(USE_LOCKING )) && !defined(USE_OPENMP )
3001+ LOCK_COMMAND (& alloc_lock );
3002+ #endif
30043003 if (memory_overflowed ) goto terminate ;
30053004 fprintf (stderr ,"OpenBLAS warning: precompiled NUM_THREADS exceeded, adding auxiliary array for thread metadata.\n" );
30063005 memory_overflowed = 1 ;
@@ -3014,7 +3013,6 @@ void *blas_memory_alloc(int procpos){
30143013 newmemory [i ].used = 0 ;
30153014 newmemory [i ].lock = 0 ;
30163015}
3017- newmemory [position - NUM_BUFFERS ].used = 1 ;
30183016
30193017allocation2 :
30203018 newmemory [position - NUM_BUFFERS ].used = 1 ;
@@ -3086,6 +3084,9 @@ void *blas_memory_alloc(int procpos){
30863084 return (void * )newmemory [position - NUM_BUFFERS ].addr ;
30873085
30883086terminate :
3087+ #if (defined(SMP ) || defined(USE_LOCKING )) && !defined(USE_OPENMP )
3088+ UNLOCK_COMMAND (& alloc_lock );
3089+ #endif
30893090 printf ("OpenBLAS : Program is Terminated. Because you tried to allocate too many memory regions.\n" );
30903091 printf ("This library was built to support a maximum of %d threads - either rebuild OpenBLAS\n" , NUM_BUFFERS );
30913092 printf ("with a larger NUM_THREADS value or set the environment variable OPENBLAS_NUM_THREADS to\n" );
0 commit comments