48
48
#endif
49
49
#endif
50
50
51
+ #ifdef SMP_DEBUG
52
+ # define MT_TRACE (...) fprintf(stderr, __VA_ARGS__)
53
+ #else
54
+ # define MT_TRACE (...)
55
+ #endif
56
+
51
57
/* This is a thread implementation for Win32 lazy implementation */
52
58
53
59
/* Thread server common information */
@@ -213,29 +219,24 @@ static DWORD WINAPI blas_thread_server(void *arg){
213
219
/* Each server needs each buffer */
214
220
buffer = blas_memory_alloc (2 );
215
221
216
- #ifdef SMP_DEBUG
217
- fprintf (STDERR , "Server[%2ld] Thread is started!\n" , cpu );
218
- #endif
222
+ MT_TRACE ("Server[%2ld] Thread is started!\n" , cpu );
219
223
220
224
while (1 ){
221
225
222
226
/* Waiting for Queue */
223
227
224
- #ifdef SMP_DEBUG
225
- fprintf (STDERR , "Server[%2ld] Waiting for Queue.\n" , cpu );
226
- #endif
228
+ MT_TRACE ("Server[%2ld] Waiting for Queue.\n" , cpu );
229
+
227
230
// event raised when work is added to the queue
228
231
WaitForSingleObject (kickoff_event , INFINITE );
229
232
230
233
if (cpu > thread_target - 2 )
231
234
{
232
- //printf ("thread [%d] exiting.\n", cpu);
235
+ //MT_TRACE ("thread [%d] exiting.\n", cpu);
233
236
break ; // excess thread, so worker thread exits
234
237
}
235
238
236
- #ifdef SMP_DEBUG
237
- fprintf (STDERR , "Server[%2ld] Got it.\n" , cpu );
238
- #endif
239
+ MT_TRACE ("Server[%2ld] Got it.\n" , cpu );
239
240
240
241
#if 1
241
242
EnterCriticalSection (& queue_lock );
@@ -270,10 +271,8 @@ static DWORD WINAPI blas_thread_server(void *arg){
270
271
__asm__ __volatile__ ("fldcw %0" : : "m" (queue -> x87_mode ));
271
272
#endif
272
273
273
- #ifdef SMP_DEBUG
274
- fprintf (STDERR , "Server[%2ld] Started. Mode = 0x%03x M = %3ld N=%3ld K=%3ld\n" ,
274
+ MT_TRACE ("Server[%2ld] Started. Mode = 0x%03x M = %3ld N=%3ld K=%3ld\n" ,
275
275
cpu , queue -> mode , queue -> args -> m , queue -> args -> n , queue -> args -> k );
276
- #endif
277
276
278
277
// fprintf(stderr, "queue start[%ld]!!!\n", cpu);
279
278
@@ -342,19 +341,14 @@ static DWORD WINAPI blas_thread_server(void *arg){
342
341
continue ; //if queue == NULL
343
342
}
344
343
345
- #ifdef SMP_DEBUG
346
- fprintf (STDERR , "Server[%2ld] Finished!\n" , cpu );
347
- #endif
344
+ MT_TRACE ("Server[%2ld] Finished!\n" , cpu );
348
345
349
346
queue -> finished = 1 ;
350
-
351
347
}
352
348
353
349
/* Shutdown procedure */
354
350
355
- #ifdef SMP_DEBUG
356
- fprintf (STDERR , "Server[%2ld] Shutdown!\n" , cpu );
357
- #endif
351
+ MT_TRACE ("Server[%2ld] Shutdown!\n" , cpu );
358
352
359
353
blas_memory_free (buffer );
360
354
@@ -369,10 +363,7 @@ int blas_thread_init(void){
369
363
370
364
LOCK_COMMAND (& server_lock );
371
365
372
- #ifdef SMP_DEBUG
373
- fprintf (STDERR , "Initializing Thread(Num. threads = %d)\n" ,
374
- blas_cpu_number );
375
- #endif
366
+ MT_TRACE ("Initializing Thread(Num. threads = %d)\n" , blas_cpu_number );
376
367
377
368
if (!blas_server_avail ){
378
369
// create the kickoff Event
@@ -383,7 +374,7 @@ int blas_thread_init(void){
383
374
InitializeCriticalSection (& queue_lock );
384
375
385
376
for (i = 0 ; i < blas_cpu_number - 1 ; i ++ ){
386
- //printf ("thread_init: creating thread [%d]\n", i);
377
+ //MT_TRACE ("thread_init: creating thread [%d]\n", i);
387
378
388
379
blas_threads [i ] = CreateThread (NULL , 0 ,
389
380
blas_thread_server , (void * )i ,
@@ -458,24 +449,19 @@ int exec_blas_async(BLASLONG pos, blas_queue_t *queue){
458
449
459
450
int exec_blas_async_wait (BLASLONG num , blas_queue_t * queue ){
460
451
461
- #ifdef SMP_DEBUG
462
- fprintf (STDERR , "Synchronization Waiting.\n" );
463
- #endif
452
+ MT_TRACE ("Synchronization Waiting.\n" );
464
453
465
454
while (num ){
466
- #ifdef SMP_DEBUG
467
- fprintf (STDERR , "Waiting Queue ..\n" );
468
- #endif
455
+ MT_TRACE ("Waiting Queue ..\n" );
469
456
while (!queue -> finished )
470
457
YIELDING ;
471
458
472
459
queue = queue -> next ;
473
460
num -- ;
474
461
}
475
462
476
- #ifdef SMP_DEBUG
477
- fprintf (STDERR , "Completely Done.\n\n" );
478
- #endif
463
+ MT_TRACE ("Completely Done.\n\n" );
464
+
479
465
// if work was added to the queue after this batch we can't sleep the worker threads
480
466
// by resetting the event
481
467
EnterCriticalSection (& queue_lock );
@@ -577,11 +563,11 @@ void goto_set_num_threads(int num_threads)
577
563
SetEvent (kickoff_event );
578
564
579
565
for (i = num_threads - 1 ; i < blas_num_threads - 1 ; i ++ ) {
580
- //printf ("set_num_threads: waiting on thread [%d] to quit.\n", i);
566
+ //MT_TRACE ("set_num_threads: waiting on thread [%d] to quit.\n", i);
581
567
582
568
WaitForSingleObject (blas_threads [i ], INFINITE );
583
569
584
- //printf ("set_num_threads: thread [%d] has quit.\n", i);
570
+ //MT_TRACE ("set_num_threads: thread [%d] has quit.\n", i);
585
571
586
572
CloseHandle (blas_threads [i ]);
587
573
}
@@ -610,7 +596,7 @@ void goto_set_num_threads(int num_threads)
610
596
}
611
597
612
598
for (i = (blas_num_threads > 0 ) ? blas_num_threads - 1 : 0 ; i < num_threads - 1 ; i ++ ){
613
- //printf ("set_num_threads: creating thread [%d]\n", i);
599
+ //MT_TRACE ("set_num_threads: creating thread [%d]\n", i);
614
600
615
601
blas_threads [i ] = CreateThread (NULL , 0 ,
616
602
blas_thread_server , (void * )i ,
0 commit comments