@@ -637,7 +637,34 @@ void stepsystem(long ProcessId)
637637
638638
639639 /* start at same time */
640- BARRIER (Global -> Barrier ,NPROC );
640+
641+ {
642+ unsigned long Error , Cycle ;
643+ long Cancel , Temp ;
644+
645+ Error = pthread_mutex_lock (& (Global -> Barrier ).mutex );
646+ if (Error != 0 ) {
647+ printf ("Error while trying to get lock in barrier.\n" );
648+ exit (-1 );
649+ }
650+
651+ Cycle = (Global -> Barrier ).cycle ;
652+ if (++ (Global -> Barrier ).counter != (NPROC )) {
653+ pthread_setcancelstate (PTHREAD_CANCEL_DISABLE , (int * ) & Cancel );
654+ while (Cycle == (Global -> Barrier ).cycle ) {
655+ Error = pthread_cond_wait (& (Global -> Barrier ).cv , & (Global -> Barrier ).mutex );
656+ if (Error != 0 ) {
657+ break ;
658+ }
659+ }
660+ pthread_setcancelstate (Cancel , (int * ) & Temp );
661+ } else {
662+ (Global -> Barrier ).cycle = !(Global -> Barrier ).cycle ;
663+ (Global -> Barrier ).counter = 0 ;
664+ Error = pthread_cond_broadcast (& (Global -> Barrier ).cv );
665+ }
666+ pthread_mutex_unlock (& (Global -> Barrier ).mutex );
667+ }
641668
642669 if ((ProcessId == 0 ) && (Local [ProcessId ].nstep >= 2 )) {
643670 CLOCK (treebuildstart );
@@ -662,7 +689,7 @@ void stepsystem(long ProcessId)
662689 }
663690
664691 Local [ProcessId ].mynbody = 0 ;
665- find_my_bodies (Global -> G_root , 0 , BRC_FUC , ProcessId );
692+ find_my_bodies (reinterpret_cast < nodeptr > ( Global -> G_root ) , 0 , BRC_FUC , ProcessId );
666693
667694/* B*RRIER(Global->Barcom,NPROC); */
668695 if ((ProcessId == 0 ) && (Local [ProcessId ].nstep >= 2 )) {
@@ -714,7 +741,34 @@ void stepsystem(long ProcessId)
714741 /* bar needed to make sure that every process has computed its min */
715742 /* and max coordinates, and has accumulated them into the global */
716743 /* min and max, before the new dimensions are computed */
717- BARRIER (Global -> Barrier ,NPROC );
744+
745+ {
746+ unsigned long Error , Cycle ;
747+ long Cancel , Temp ;
748+
749+ Error = pthread_mutex_lock (& (Global -> Barrier ).mutex );
750+ if (Error != 0 ) {
751+ printf ("Error while trying to get lock in barrier.\n" );
752+ exit (-1 );
753+ }
754+
755+ Cycle = (Global -> Barrier ).cycle ;
756+ if (++ (Global -> Barrier ).counter != (NPROC )) {
757+ pthread_setcancelstate (PTHREAD_CANCEL_DISABLE , (int * ) & Cancel );
758+ while (Cycle == (Global -> Barrier ).cycle ) {
759+ Error = pthread_cond_wait (& (Global -> Barrier ).cv , & (Global -> Barrier ).mutex );
760+ if (Error != 0 ) {
761+ break ;
762+ }
763+ }
764+ pthread_setcancelstate (Cancel , (int * ) & Temp );
765+ } else {
766+ (Global -> Barrier ).cycle = !(Global -> Barrier ).cycle ;
767+ (Global -> Barrier ).counter = 0 ;
768+ Error = pthread_cond_broadcast (& (Global -> Barrier ).cv );
769+ }
770+ pthread_mutex_unlock (& (Global -> Barrier ).mutex );
771+ }
718772
719773 if ((ProcessId == 0 ) && (Local [ProcessId ].nstep >= 2 )) {
720774 CLOCK (trackend );
@@ -786,7 +840,35 @@ void find_my_initial_bodies(bodyptr btab, long nbody, long ProcessId)
786840 for (i = 0 ; i < Local [ProcessId ].mynbody ; i ++ ) {
787841 Local [ProcessId ].mybodytab [i ] = & (btab [offset + i ]);
788842 }
789- BARRIER (Global -> Barrier ,NPROC );
843+
844+ {
845+ unsigned long Error , Cycle ;
846+ long Cancel , Temp ;
847+
848+ Error = pthread_mutex_lock (& (Global -> Barrier ).mutex );
849+ if (Error != 0 ) {
850+ printf ("Error while trying to get lock in barrier.\n" );
851+ exit (-1 );
852+ }
853+
854+ Cycle = (Global -> Barrier ).cycle ;
855+ if (++ (Global -> Barrier ).counter != (NPROC )) {
856+ pthread_setcancelstate (PTHREAD_CANCEL_DISABLE , (int * ) & Cancel );
857+ while (Cycle == (Global -> Barrier ).cycle ) {
858+ Error = pthread_cond_wait (& (Global -> Barrier ).cv , & (Global -> Barrier ).mutex );
859+ if (Error != 0 ) {
860+ break ;
861+ }
862+ }
863+ pthread_setcancelstate (Cancel , (int * ) & Temp );
864+ } else {
865+ (Global -> Barrier ).cycle = !(Global -> Barrier ).cycle ;
866+ (Global -> Barrier ).counter = 0 ;
867+ Error = pthread_cond_broadcast (& (Global -> Barrier ).cv );
868+ }
869+ pthread_mutex_unlock (& (Global -> Barrier ).mutex );
870+ }
871+
790872}
791873
792874
0 commit comments