Maybe it is callgrind that is playing tricks on me.
Here is the code :

for (auto particle = particle_handler.begin();
particle != particle_handler.end();
++particle)
{
// Getting properties of particle as local variable
auto particle_properties = particle->get_properties();

// Reinitializing forces and momentums of particles in the system
particle_properties[DEM::PropertiesIndex::force_x] = 0;
particle_properties[DEM::PropertiesIndex::force_y] = 0;

particle_properties[DEM::PropertiesIndex::M_x] = 0;
particle_properties[DEM::PropertiesIndex::M_y] = 0;

if (dim == 3)
{
particle_properties[DEM::PropertiesIndex::force_z] = 0;
particle_properties[DEM::PropertiesIndex::M_z] = 0;
}
}  

With dim a template parameter of the class.
The index for the particle properties are part of an enum:
enum PropertiesIndex : int
{
type = 0,
dp = 1,
rho = 2,
v_x = 3,
v_y = 4,
v_z = 5,
acc_x = 6,
acc_y = 7,
acc_z = 8,
force_x = 9,
force_y = 10,
force_z = 11,
omega_x = 12,
omega_y = 13,
omega_z = 14,
mass = 15,
mom_inertia = 16,
M_x = 17,
M_y = 18,
M_z = 19,
displacement_x = 20,
displacement_y = 21,
displacement_z = 22,
n_properties = 23,
};  


I was not sure on what would be the best data structure to identify the 
data in the particle properties, hence this type of enum (which I know is 
maybe not ideal but...)

Do you have any suggestions? Could it just be the cost of iterating through 
the map that callgrinds wrongly affects to the zeroing of the variables?
On Saturday, October 17, 2020 at 2:30:40 p.m. UTC-4 Wolfgang Bangerth wrote:

>
> > I was wondering if there was a more optimal way to do this? I have 
> profiled it 
> > with callgrind and it seems that getting the properties array view from 
> the 
> > particle can be really expensive.
> > Since what we want to achieve is just to set one of these properties to 
> zero, 
> > I was wondering if there was not a possible optimisation? For example, 
> could 
> > we just get the array view once and assuming its continuity, set all of 
> the 
> > same property to zero?
>
> That seems strange to me. The get_properties() function is in essence a 
> one-liner with a few indirections. Can you show the code in which you set 
> properties to zero?
>
> Best
> W.
>
> -- 
> ------------------------------------------------------------------------
> Wolfgang Bangerth email: bang...@colostate.edu
> www: http://www.math.colostate.edu/~bangerth/
>
>

-- 
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see 
https://groups.google.com/d/forum/dealii?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to dealii+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/674e23f3-3a66-48bb-8971-c68280eeb0d5n%40googlegroups.com.

Reply via email to