@@ -107,11 +107,12 @@ char err_buffer[MPI_MAX_ERROR_STRING];
107
107
MPI_Comm CAF_COMM_WORLD ;
108
108
109
109
/* Failed Images */
110
- /* MPI_Comm *communicators; */
110
+ MPI_Comm lock_comm ;
111
+ MPI_Request lock_req ;
111
112
int used_comm = -1 , n_failed_imgs = 0 , error_called = 0 ;
112
113
int * ranks_gc ,* ranks_gf ; //to be returned by failed images
113
114
MPI_Errhandler errh ,errh_w ;
114
- int completed = 0 ;
115
+ int completed = 0 , tmp_lock ;
115
116
116
117
static void verbose_win_errhandler (MPI_Win * win , int * err , ...) {
117
118
/* printf("in win err handler\n"); */
@@ -251,11 +252,12 @@ caf_runtime_error (const char *message, ...)
251
252
/* inline */ void locking_atomic_op (MPI_Win win , int * value , int newval ,
252
253
int compare , int image_index , int index )
253
254
{
255
+ int ret ;
254
256
# ifdef CAF_MPI_LOCK_UNLOCK
255
257
MPI_Win_lock (MPI_LOCK_EXCLUSIVE , image_index - 1 , 0 , win );
256
258
# endif // CAF_MPI_LOCK_UNLOCK
257
- MPI_Compare_and_swap (& newval ,& compare ,value , MPI_INT ,image_index - 1 ,
258
- index * sizeof (int ), win );
259
+ ret = MPI_Compare_and_swap (& newval ,& compare ,value , MPI_INT ,image_index - 1 ,
260
+ index * sizeof (int ), win );
259
261
# ifdef CAF_MPI_LOCK_UNLOCK
260
262
MPI_Win_unlock (image_index - 1 , win );
261
263
# else // CAF_MPI_LOCK_UNLOCK
@@ -268,11 +270,29 @@ void mutex_lock(MPI_Win win, int image_index, int index, int *stat,
268
270
{
269
271
const char msg [] = "Already locked" ;
270
272
#if MPI_VERSION >= 3
271
- int value = 1 , compare = 0 , newval = caf_this_image , i = 1 ,zero = 0 ;
273
+ int value = 1 , compare = 0 , newval = caf_this_image , i = 1 ,zero = 0 ,ret = 0 ;
274
+ int flag , it = 0 , check_failure = 100 ;
272
275
273
276
if (stat != NULL )
274
277
* stat = 0 ;
275
278
279
+ MPI_Test (& lock_req ,& flag ,MPI_STATUS_IGNORE );
280
+
281
+ /* if(error_called == 1) */
282
+ /* { */
283
+ /* /\* MPIX_Comm_agree( CAF_COMM_WORLD, &completed ); *\/ */
284
+ /* communicator_shrink(&CAF_COMM_WORLD); */
285
+ /* error_called = 0; */
286
+ /* } */
287
+
288
+ if (error_called == 1 )
289
+ {
290
+ /* MPIX_Comm_agree( CAF_COMM_WORLD, &completed ); */
291
+ communicator_shrink (& lock_comm );
292
+ communicator_shrink (& CAF_COMM_WORLD );
293
+ error_called = 0 ;
294
+ }
295
+
276
296
locking_atomic_op (win , & value , newval , compare , image_index , index );
277
297
278
298
if (value == caf_this_image && image_index == caf_this_image )
@@ -289,11 +309,26 @@ void mutex_lock(MPI_Win win, int image_index, int index, int *stat,
289
309
290
310
while (value != 0 )
291
311
{
312
+ it ++ ;
313
+
314
+ if (it == check_failure )
315
+ {
316
+ it = 1 ;
317
+ MPI_Test (& lock_req ,& flag ,MPI_STATUS_IGNORE );
318
+ }
319
+
320
+ if (error_called == 1 )
321
+ {
322
+ /* MPIX_Comm_agree( CAF_COMM_WORLD, &completed ); */
323
+ communicator_shrink (& lock_comm );
324
+ communicator_shrink (& CAF_COMM_WORLD );
325
+ error_called = 0 ;
326
+ }
327
+
292
328
locking_atomic_op (win , & value , newval , compare , image_index , index );
293
- printf ( "n_failed_images: %d\n" , n_failed_imgs );
329
+
294
330
for (i = 0 ;i < n_failed_imgs ;i ++ )
295
- {
296
- printf ("value: %d\n" ,value );
331
+ {
297
332
if (ranks_gc [i ] == value )
298
333
{
299
334
# ifdef CAF_MPI_LOCK_UNLOCK
@@ -308,8 +343,6 @@ void mutex_lock(MPI_Win win, int image_index, int index, int *stat,
308
343
break ;
309
344
}
310
345
}
311
- // usleep(caf_this_image*i);
312
- //i++;
313
346
}
314
347
315
348
return ;
@@ -441,18 +474,14 @@ PREFIX (init) (int *argc, char ***argv)
441
474
442
475
stat_tok = malloc (sizeof (MPI_Win ));
443
476
444
- /* communicators = (MPI_Comm *)calloc(caf_num_images,sizeof(MPI_Comm)); */
445
-
446
477
MPI_Comm_create_errhandler (verbose_comm_errhandler , & errh );
447
478
MPI_Comm_set_errhandler (CAF_COMM_WORLD , errh );
479
+
480
+ MPI_Comm_dup (CAF_COMM_WORLD , & lock_comm );
481
+ MPI_Comm_set_errhandler (lock_comm , errh );
482
+ MPI_Irecv (& tmp_lock ,1 ,MPI_INT ,MPI_ANY_SOURCE ,MPI_ANY_TAG ,lock_comm ,& lock_req );
448
483
449
484
MPI_Win_create_errhandler (verbose_win_errhandler , & errh_w );
450
-
451
- /* for(i=0;i<caf_num_images;i++) */
452
- /* { */
453
- /* MPI_Comm_dup(CAF_COMM_WORLD,&communicators[i]); */
454
- /* MPI_Comm_set_errhandler(communicators[i], errh); */
455
- /* } */
456
485
457
486
ranks_gf = (int * )malloc (caf_num_images * sizeof (int ));
458
487
ranks_gc = (int * )malloc (caf_num_images * sizeof (int ));
@@ -544,7 +573,7 @@ PREFIX (num_images)(int distance __attribute__ ((unused)),
544
573
return caf_num_images ;
545
574
}
546
575
547
- static int communicator_shrink ()
576
+ int communicator_shrink (MPI_Comm * comm )
548
577
{
549
578
int ns ,srank ,crank ,rc ,flag ,i ,drank ,nc ,nd ;
550
579
MPI_Comm shrunk , * newcomm ;
@@ -553,40 +582,11 @@ static int communicator_shrink()
553
582
redo :
554
583
newcomm = (MPI_Comm * )calloc (1 ,sizeof (MPI_Comm ));
555
584
556
- MPIX_Comm_shrink (CAF_COMM_WORLD , & shrunk );
585
+ MPIX_Comm_shrink (* comm , & shrunk );
557
586
MPI_Comm_set_errhandler ( shrunk , errh );
558
587
MPI_Comm_size (shrunk , & ns ); MPI_Comm_rank (shrunk , & srank );
559
588
560
- MPI_Comm_rank (CAF_COMM_WORLD , & crank );
561
-
562
- /* if(MPI_COMM_NULL != CAF_COMM_WORLD) { /\* I was not a spare before... *\/ */
563
- /* /\* not enough processes to continue, aborting. *\/ */
564
- /* MPI_Comm_size(CAF_COMM_WORLD, &nc); */
565
- /* if( nc > ns ) MPI_Abort(CAF_COMM_WORLD, MPI_ERR_PROC_FAILED); */
566
-
567
- /* /\* remembering the former rank: we will reassign the same */
568
- /* * ranks in the new world. *\/ */
569
- /* MPI_Comm_rank(CAF_COMM_WORLD, &crank); */
570
-
571
- /* /\* the rank 0 in the shrinked comm is going to determine the */
572
- /* * ranks at which the spares need to be inserted. *\/ */
573
- /* if(0 == srank) { */
574
- /* /\* getting the group of dead processes: */
575
- /* * those in comm, but not in shrinked are the deads *\/ */
576
- /* MPI_Comm_group(CAF_COMM_WORLD, &cgrp); MPI_Comm_group(shrunk, &sgrp); */
577
- /* MPI_Group_difference(cgrp, sgrp, &dgrp); MPI_Group_size(dgrp, &nd); */
578
- /* /\* Computing the rank assignment for the newly inserted spares *\/ */
579
- /* for(i=0; i<ns-(nc-nd); i++) { */
580
- /* if( i < nd ) MPI_Group_translate_ranks(dgrp, 1, &i, cgrp, &drank); */
581
- /* else drank=-1; /\* still a spare *\/ */
582
- /* /\* sending their new assignment to all spares *\/ */
583
- /* MPI_Send(&drank, 1, MPI_INT, i+nc-nd, 1, shrunk); */
584
- /* } */
585
- /* MPI_Group_free(&cgrp); MPI_Group_free(&sgrp); MPI_Group_free(&dgrp); */
586
- /* } */
587
- /* else { /\* I was a spare, waiting for my new assignment *\/ */
588
- /* MPI_Recv(&crank, 1, MPI_INT, 0, 1, shrunk, MPI_STATUS_IGNORE); */
589
- /* } */
589
+ MPI_Comm_rank (* comm , & crank );
590
590
591
591
/* Split does the magic: removing spare processes and reordering ranks
592
592
* so that all surviving processes remain at their former place */
@@ -598,10 +598,10 @@ static int communicator_shrink()
598
598
flag = MPIX_Comm_agree (shrunk , & flag );
599
599
MPI_Comm_free (& shrunk );
600
600
if ( MPI_SUCCESS != flag ) {
601
- if ( MPI_SUCCESS == rc ) MPI_Comm_free (newcomm );
601
+ if ( MPI_SUCCESS == rc ) MPI_Comm_free (* newcomm );
602
602
goto redo ;
603
603
}
604
- CAF_COMM_WORLD = * newcomm ;
604
+ * comm = * newcomm ;
605
605
return MPI_SUCCESS ;
606
606
}
607
607
@@ -650,7 +650,8 @@ void *
650
650
if (error_called == 1 )
651
651
{
652
652
/* MPIX_Comm_agree( CAF_COMM_WORLD, &completed ); */
653
- communicator_shrink ();
653
+ communicator_shrink (& CAF_COMM_WORLD );
654
+ communicator_shrink (& lock_comm );
654
655
error_called = 0 ;
655
656
}
656
657
@@ -818,7 +819,8 @@ PREFIX (sync_all) (int *stat, char *errmsg, int errmsg_len)
818
819
if (error_called == 1 )
819
820
{
820
821
/* MPIX_Comm_agree( CAF_COMM_WORLD, &completed ); */
821
- communicator_shrink ();
822
+ communicator_shrink (& CAF_COMM_WORLD );
823
+ communicator_shrink (& lock_comm );
822
824
error_called = 0 ;
823
825
}
824
826
0 commit comments