@@ -163,7 +163,7 @@ void Monitor_nD_Init(MonitornD_Defines_type *DEFS,
163
163
Vars -> Coord_NumberNoPixel = 0 ; /* same but without counting PixelID */
164
164
165
165
Vars -> Buffer_Block = MONND_BUFSIZ ; /* Buffer size for list or auto limits */
166
- Vars -> Neutron_Counter = -1 ; /* event counter, simulation total counts is mcget_ncount() */
166
+ Vars -> Neutron_Counter = 0 ; /* event counter, simulation total counts is mcget_ncount() */
167
167
Vars -> Buffer_Counter = 0 ; /* index in Buffer size (for realloc) */
168
168
Vars -> Buffer_Size = 0 ;
169
169
Vars -> He3_pressure = 0 ;
@@ -992,6 +992,15 @@ int Monitor_nD_Trace(MonitornD_Defines_type *DEFS, MonitornD_Variables_type *Var
992
992
long While_Buffer = 0 ;
993
993
char Set_Vars_Coord_Type = DEFS -> COORD_NONE ;
994
994
995
+ #ifdef OPENACC
996
+ /* For the OPENACC list buffer we need a local copy of the
997
+ atomically updated Neutron_counter - captured below under list mode */
998
+ long long ParticleCount = 0 ;
999
+ #else
1000
+ /* On CPU can make do with the global, declared one... */
1001
+ #define ParticleCount Vars->Neutron_Counter
1002
+ #endif
1003
+
995
1004
/* the logic below depends mainly on:
996
1005
Flag_List: 1=store 1 buffer, 2=list all, 3=re-use buffer
997
1006
Flag_Auto_Limits: 0 (no auto limits/list), 1 (store events into Buffer), 2 (re-emit store events)
@@ -1033,15 +1042,15 @@ int Monitor_nD_Trace(MonitornD_Defines_type *DEFS, MonitornD_Variables_type *Var
1033
1042
Vars -> Flag_List = 3 ;
1034
1043
Vars -> Buffer_Block = Vars -> Buffer_Size ;
1035
1044
Vars -> Buffer_Counter = 0 ;
1036
- Vars -> Neutron_Counter = 0 ;
1045
+ ParticleCount = 0 ;
1037
1046
1038
1047
}
1039
1048
else
1040
1049
{
1041
- Vars -> Mon2D_Buffer = (double * )realloc (Vars -> Mon2D_Buffer , (Vars -> Coord_Number + 1 )* (Vars -> Neutron_Counter + Vars -> Buffer_Block )* sizeof (double ));
1050
+ Vars -> Mon2D_Buffer = (double * )realloc (Vars -> Mon2D_Buffer , (Vars -> Coord_Number + 1 )* (ParticleCount + Vars -> Buffer_Block )* sizeof (double ));
1042
1051
if (Vars -> Mon2D_Buffer == NULL )
1043
- { printf ("Monitor_nD: %s cannot reallocate Vars->Mon2D_Buffer[%li] (%li). Skipping.\n" , Vars -> compcurname , i , (long int )(Vars -> Neutron_Counter + Vars -> Buffer_Block )* sizeof (double )); Vars -> Flag_List = 1 ; }
1044
- else { Vars -> Buffer_Counter = 0 ; Vars -> Buffer_Size = Vars -> Neutron_Counter + Vars -> Buffer_Block ; }
1052
+ { printf ("Monitor_nD: %s cannot reallocate Vars->Mon2D_Buffer[%li] (%li). Skipping.\n" , Vars -> compcurname , i , (long int )(ParticleCount + Vars -> Buffer_Block )* sizeof (double )); Vars -> Flag_List = 1 ; }
1053
+ else { Vars -> Buffer_Counter = 0 ; Vars -> Buffer_Size = ParticleCount + Vars -> Buffer_Block ; }
1045
1054
}
1046
1055
} /* end if Buffer realloc */
1047
1056
#endif
@@ -1246,7 +1255,7 @@ int Monitor_nD_Trace(MonitornD_Defines_type *DEFS, MonitornD_Variables_type *Var
1246
1255
else
1247
1256
if (Set_Vars_Coord_Type == DEFS -> COORD_LAMBDA ) { XY = sqrt (_particle -> vx * _particle -> vx + _particle -> vy * _particle -> vy + _particle -> vz * _particle -> vz ); XY *= V2K ; if (XY != 0 ) XY = 2 * PI /XY ; }
1248
1257
else
1249
- if (Set_Vars_Coord_Type == DEFS -> COORD_NCOUNT ) XY = Vars -> Neutron_Counter ;
1258
+ if (Set_Vars_Coord_Type == DEFS -> COORD_NCOUNT ) XY = ParticleCount ;
1250
1259
else
1251
1260
if (Set_Vars_Coord_Type == DEFS -> COORD_ANGLE )
1252
1261
{ XY = sqrt (_particle -> vx * _particle -> vx + _particle -> vy * _particle -> vy );
@@ -1373,13 +1382,19 @@ int Monitor_nD_Trace(MonitornD_Defines_type *DEFS, MonitornD_Variables_type *Var
1373
1382
{ /* now store Coord into Buffer (no index needed) if necessary (list or auto limits) */
1374
1383
if ((Vars -> Buffer_Counter < Vars -> Buffer_Block ) && ((Vars -> Flag_List ) || (Vars -> Flag_Auto_Limits == 1 )))
1375
1384
{
1376
- #pragma acc atomic
1377
- Vars -> Neutron_Counter = Vars -> Neutron_Counter + 1 ;
1385
+ #ifdef OPENACC
1386
+ #pragma acc atomic capture
1387
+ {
1388
+ ParticleCount = Vars -> Neutron_Counter ++ ;
1389
+ }
1390
+ #else
1391
+ ParticleCount ++ ;
1392
+ #endif
1378
1393
for (i = 0 ; i <= Vars -> Coord_Number ; i ++ )
1379
1394
{
1380
1395
// This is is where the list is appended. How to make this "atomic"?
1381
1396
#pragma acc atomic write
1382
- Vars -> Mon2D_Buffer [i + Vars -> Neutron_Counter * (Vars -> Coord_Number + 1 )] = Coord [i ];
1397
+ Vars -> Mon2D_Buffer [i + ParticleCount * (Vars -> Coord_Number + 1 )] = Coord [i ];
1383
1398
}
1384
1399
#pragma acc atomic
1385
1400
Vars -> Buffer_Counter = Vars -> Buffer_Counter + 1 ;
0 commit comments