Skip to content

Commit 1fdbc60

Browse files
committed
Current Interpolation: Update Event System
Reorder dependencies in the event system and add a GUARD receive functionality to FieldJ.
1 parent ad710a8 commit 1fdbc60

File tree

4 files changed

+61
-10
lines changed

4 files changed

+61
-10
lines changed

src/picongpu/include/fields/FieldJ.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class FieldJ : public SimulationFieldHelper<MappingDesc>, public ISimulationData
124124
private:
125125

126126
GridBuffer<ValueType, simDim> fieldJ;
127+
GridBuffer<ValueType, simDim>* fieldJrecv;
127128

128129
FieldE *fieldE;
129130
FieldB *fieldB;

src/picongpu/include/fields/FieldJ.tpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ using namespace PMacc;
5353

5454
FieldJ::FieldJ( MappingDesc cellDescription ) :
5555
SimulationFieldHelper<MappingDesc>( cellDescription ),
56-
fieldJ( cellDescription.getGridLayout( ) ), fieldE( NULL ), fieldB( NULL )
56+
fieldJ( cellDescription.getGridLayout( ) ), fieldE( NULL ), fieldB( NULL ), fieldJrecv( NULL )
5757
{
5858
const DataSpace<simDim> coreBorderSize = cellDescription.getGridLayout( ).getDataSpaceWithoutGuarding( );
5959

@@ -115,10 +115,34 @@ fieldJ( cellDescription.getGridLayout( ) ), fieldE( NULL ), fieldB( NULL )
115115
// std::cout << "ex " << i << " x=" << guardingCells[0] << " y=" << guardingCells[1] << " z=" << guardingCells[2] << std::endl;
116116
fieldJ.addExchangeBuffer( i, guardingCells, FIELD_J );
117117
}
118+
119+
/* Receive border values in own guard for "receive" communication pattern - necessary for current interpolation/filter */
120+
const DataSpace<simDim> originRecvGuard( GetMargin<fieldSolver::CurrentInterpolation>::LowerMargin( ).toRT( ) );
121+
const DataSpace<simDim> endRecvGuard( GetMargin<fieldSolver::CurrentInterpolation>::UpperMargin( ).toRT( ) );
122+
if( originRecvGuard != DataSpace<simDim>::create(0) ||
123+
endRecvGuard != DataSpace<simDim>::create(0) )
124+
{
125+
fieldJrecv = new GridBuffer<ValueType, simDim > ( fieldJ.getDeviceBuffer(), cellDescription.getGridLayout( ) );
126+
127+
/*go over all directions*/
128+
for ( uint32_t i = 1; i < NumberOfExchanges<simDim>::value; ++i )
129+
{
130+
DataSpace<simDim> relativMask = Mask::getRelativeDirections<simDim > ( i );
131+
/* guarding cells depend on direction
132+
* for negative direction use originGuard else endGuard (relative direction ZERO is ignored)
133+
* don't switch end and origin because this is a read buffer and no send buffer
134+
*/
135+
DataSpace<simDim> guardingCells;
136+
for ( uint32_t d = 0; d < simDim; ++d )
137+
guardingCells[d] = ( relativMask[d] == -1 ? originRecvGuard[d] : endRecvGuard[d] );
138+
fieldJrecv->addExchange( GUARD, i, guardingCells, FIELD_JRECV );
139+
}
140+
}
118141
}
119142

120143
FieldJ::~FieldJ( )
121144
{
145+
__delete(fieldJrecv);
122146
}
123147

124148
SimulationDataId FieldJ::getUniqueId( )
@@ -146,7 +170,14 @@ EventTask FieldJ::asyncCommunication( EventTask serialEvent )
146170
__startTransaction( serialEvent );
147171
FieldFactory::getInstance( ).createTaskFieldSend( *this );
148172
ret += __endTransaction( );
149-
return ret;
173+
174+
if( fieldJrecv != NULL )
175+
{
176+
EventTask eJ = fieldJrecv->asyncCommunication( ret );
177+
return eJ;
178+
}
179+
else
180+
return ret;
150181
}
151182

152183
void FieldJ::bashField( uint32_t exchangeType )

src/picongpu/include/simulationControl/MySimulation.hpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,33 @@ class MySimulation : public SimulationHelper<simDim>
415415
#endif
416416

417417
#if (ENABLE_CURRENT == 1)
418-
if(bmpl::size<VectorAllSpecies>::type::value>0)
418+
if(bmpl::size<VectorAllSpecies>::type::value > 0)
419419
{
420420
EventTask eRecvCurrent = fieldJ->asyncCommunication(__getTransactionEvent());
421-
fieldJ->addCurrentToEMF<CORE >(*myCurrentInterpolation);
422421

423-
__setTransactionEvent(eRecvCurrent);
424-
fieldJ->addCurrentToEMF<BORDER >(*myCurrentInterpolation);
422+
const DataSpace<simDim> currentRecvLower( GetMargin<fieldSolver::CurrentInterpolation>::LowerMargin( ).toRT( ) );
423+
const DataSpace<simDim> currentRecvUpper( GetMargin<fieldSolver::CurrentInterpolation>::UpperMargin( ).toRT( ) );
424+
425+
/* without interpolation, we do not need to access the FieldJ GUARD
426+
* and can therefor overlap communication of GUARD->(ADD)BORDER & computation of CORE */
427+
if( currentRecvLower == DataSpace<simDim>::create(0) &&
428+
currentRecvUpper == DataSpace<simDim>::create(0) )
429+
{
430+
fieldJ->addCurrentToEMF<CORE >(*myCurrentInterpolation);
431+
__setTransactionEvent(eRecvCurrent);
432+
fieldJ->addCurrentToEMF<BORDER >(*myCurrentInterpolation);
433+
} else
434+
{
435+
/* in case we perform a current interpolation/filter, we need
436+
* to access the BORDER area from the CORE (and the GUARD area
437+
* from the BORDER)
438+
* `fieldJ->asyncCommunication` first adds the neighbors' values
439+
* to BORDER (send) and then updates the GUARD (receive)
440+
* \todo split the last `receive` part in a separate method to
441+
* allow already a computation of CORE */
442+
__setTransactionEvent(eRecvCurrent);
443+
fieldJ->addCurrentToEMF<CORE + BORDER>(*myCurrentInterpolation);
444+
}
425445
}
426446
#endif
427447

src/picongpu/include/simulation_types.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2013 Axel Huebl, Felix Schmitt, Heiko Burau, Rene Widera
2+
* Copyright 2013-2015 Axel Huebl, Felix Schmitt, Heiko Burau, Rene Widera
33
*
44
* This file is part of PIConGPU.
55
*
@@ -19,7 +19,6 @@
1919
*/
2020

2121

22-
2322
#pragma once
2423

2524
#include "version.hpp"
@@ -48,8 +47,8 @@ enum ParticleType
4847

4948
enum CommunicationTag
5049
{
51-
FIELD_B = 0u, FIELD_E = 1u, FIELD_J = 2u, FIELD_TMP = 3u,
52-
PAR_IONS = 4u, PAR_ELECTRONS = 5u,
50+
FIELD_B = 0u, FIELD_E = 1u, FIELD_J = 2u, FIELD_JRECV = 3u, FIELD_TMP = 4u,
51+
PAR_IONS = 5u, PAR_ELECTRONS = 6u,
5352
NO_COMMUNICATION = 16u
5453
};
5554

0 commit comments

Comments
 (0)