Skip to content

Commit 4dfafd6

Browse files
Merge pull request #1881 from arcaneframework/dev/gg-auto-compute-nb-block-in-multi-thread
Compute automatically the grain size for multi-thread loop
2 parents 53c165a + c68c7b7 commit 4dfafd6

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

arcane/src/arcane/accelerator/core/RunCommandLaunchInfo.cc

+9-6
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ _internalNativeStream()
113113

114114
/*---------------------------------------------------------------------------*/
115115
/*---------------------------------------------------------------------------*/
116-
117-
//! Calcule le nombre de block/thread/grille du noyau en fonction de \a full_size
116+
/*!
117+
* \brief Calcule le nombre de block/thread/grille du noyau en fonction de \a full_size.
118+
*/
118119
KernelLaunchArgs RunCommandLaunchInfo::
119120
_computeKernelLaunchArgs() const
120121
{
@@ -133,16 +134,17 @@ ParallelLoopOptions RunCommandLaunchInfo::
133134
computeParallelLoopOptions() const
134135
{
135136
ParallelLoopOptions opt = m_command.parallelLoopOptions();
136-
const bool use_dynamic_compute = false;
137+
const bool use_dynamic_compute = true;
137138
// Calcule une taille de grain par défaut si cela n'est pas renseigné dans
138-
// les options
139+
// les options. Par défaut on fait en sorte de faire un nombre d'itérations
140+
// égale à 2 fois le nombre de threads utilisés.
139141
if (use_dynamic_compute && opt.grainSize() == 0) {
140142
Int32 nb_thread = opt.maxThread();
141143
if (nb_thread <= 0)
142144
nb_thread = TaskFactory::nbAllowedThread();
143145
if (nb_thread <= 0)
144146
nb_thread = 1;
145-
Int32 grain_size = static_cast<Int32>((double)m_total_loop_size / (nb_thread * 10.0));
147+
Int32 grain_size = static_cast<Int32>((double)m_total_loop_size / (nb_thread * 2.0));
146148
opt.setGrainSize(grain_size);
147149
}
148150
return opt;
@@ -151,8 +153,9 @@ computeParallelLoopOptions() const
151153
/*---------------------------------------------------------------------------*/
152154
/*---------------------------------------------------------------------------*/
153155
/*!
154-
* \brief Calcule la valeur de loopRunInfo()
156+
* \brief Calcule la valeur de m_loop_run_info.
155157
*
158+
* Cela n'est utile qu'en mode multi-thread.
156159
*/
157160
void RunCommandLaunchInfo::
158161
_computeLoopRunInfo()

arcane/src/arcane/parallel/thread/TBBTaskImplementation.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,10 @@ class TBBTaskImplementation::MDParallelForExecute
974974
// Il faut donc en reconstruire une complètement.
975975

976976
Integer gsize = m_options.grainSize();
977-
if (gsize>0){
977+
if (gsize>0 && RankValue==1){
978+
Int32 max_range0 = range.template upperBound<0>() - range.template lowerBound<0>();
979+
if (gsize > max_range0)
980+
gsize = max_range0;
978981
// Modifie la taille du grain pour la première dimension.
979982
// TODO: pouvoir aussi modifier la valeur de 'grain_size' pour les autres dimensions.
980983
m_tbb_range = _toTBBRangeWithGrain(m_tbb_range,gsize);

0 commit comments

Comments
 (0)