[m-rev.] Parallel runtime thread pinning.

Paul Bone pbone at csse.unimelb.edu.au
Mon Aug 24 10:45:12 AEST 2009


On Mon, Aug 24, 2009 at 09:33:27AM +1000, Peter Wang wrote:
> On 2009-08-24, Paul Bone <pbone at csse.unimelb.edu.au> wrote:
> > 
> > For post-commit review.
> > 
> > A later changeset will address Julien's review comments on my other
> > recent changes to the parallel runtime.
> > 
> > 
> > Parallel runtime thread pinning.
> > 
> > This change introduces two new features in the mercury runtime;
> > pinning of threads to CPU cores/threads and runtime detection of the number of
> > CPU cores/threads available.
> > 
> > If MR_num_threads has not been specified in the runtime options with the -P
> > flag we use the sysconf(_SC_NPROCESSORS_ONLN) call if available to detect the
> > number of CPUs online and set MR_num_threads available.  As before this
> > defaults to 1.
> 
> Excellent.

Thanks for the quick review!

> > Index: configure.in
> > ===================================================================
> > RCS file: /home/mercury1/repository/mercury/configure.in,v
> > retrieving revision 1.541
> > diff -u -p -b -r1.541 configure.in
> > --- configure.in	18 Aug 2009 05:10:39 -0000	1.541
> > +++ configure.in	19 Aug 2009 06:43:37 -0000
> 
> > @@ -1138,6 +1139,24 @@ MERCURY_CHECK_FOR_FENV_FUNC([fesetround]
> >  
> >  #-----------------------------------------------------------------------------#
> >  #
> > +# Check for declarations. 
> > +#
> > +
> > +mercury_check_for_declarations () {
> > +    for mercury_cv_decl in "$@"
> > +    do
> > +        mercury_cv_decl_define="MR_HAVE_`echo $mercury_cv_decl | \
> > +            tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`"
> > +        AC_CHECK_DECL($mercury_cv_decl, [
> > +            AC_DEFINE_UNQUOTED($mercury_cv_decl_define)
> > +        ])
> > +    done
> > +}
> > +
> > +mercury_check_for_declarations "_SC_NPROCESSORS_ONLN"
> 
> Can't you just use #ifdef _SC_NPROCESSORS_ONLN in the source code?

It's not clear if this will be defined as a macro or as an enum or other
constant.  Using an #ifdef in the source code won't work for emums.  I'll add a
comment describing this rationale.

I'd be surprised if these weren't macros.  If anyone knows for sure if such an
assumption is safe please let me know.

> > Index: doc/user_guide.texi
> > ===================================================================
> > RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
> > retrieving revision 1.590
> > diff -u -p -b -r1.590 user_guide.texi
> > --- doc/user_guide.texi	19 Aug 2009 07:45:11 -0000	1.590
> > +++ doc/user_guide.texi	23 Aug 2009 22:27:28 -0000
> > @@ -9608,6 +9611,17 @@ grade.
> >  @c and the @samp{MR_PROFILE_PARALLEL_EXECUTION_SUPPORT} C macro was
> >  @c defined when the runtime system was compiled.
> >  
> > + at sp 1
> > + at item --thread-pinning
> > + at findex --thread-pinning
> > +Request that the runtime system attempts to pin mercury engines (POSIX threads)
> > +to CPU cores/hardware threads.
> 
> Mercury

Fixed,

> > +This only has an effect if the executable was build in a parallel low-level C 
> > +grade.
> 
> built

Fixed,

> > +It is disabled by default unless @samp{-P @var{num}} is not specified and the
> > +runtime system is able to detect the number of processors enabled by the
> > +operating system.
> 
> I think it should just be disabled unless explicitly enabled.  You can't assume
> that the machine is dedicated to your process.

That's up to the operating system's scheduler.  Pinning doesn't ask for
exclusive access to a CPU, just that the thread can only be ran on that
particular CPU.

I'll disable this for now, at least until we know that it is a net benefit in
most situations.  I'm concerned that if two parallel Mercury programs are
scheduled and both pin their main thread to the same CPU (very probable) and
the programs don't parallelize well the operating system could run them more
optimally if it migrated one of their master threads to an otherwise idle CPU. 

Thanks.

> > Index: runtime/mercury_conf.h.in
> > ===================================================================
> > RCS file: /home/mercury1/repository/mercury/runtime/mercury_conf.h.in,v
> > retrieving revision 1.64
> > diff -u -p -b -r1.64 mercury_conf.h.in
> > --- runtime/mercury_conf.h.in	30 Jul 2009 04:02:56 -0000	1.64
> > +++ runtime/mercury_conf.h.in	19 Aug 2009 07:13:41 -0000
> > @@ -136,6 +136,7 @@
> >  **	MR_HAVE_FENV_H		we have <fenv.h>
> >  **	MR_HAVE_SYS_MMAN_H	we have <sys/mman.h>
> >  **	MR_HAVE_SYS_SEM_H 	we have <sys/sem.h>
> > +**	MR_HAVE_SCHED_H     we have <sched.h>
> 
> Indentation.

I've added a editor hint to the top of the file for vim.  With the settings
sw=8 ts=8 noexpandtab

I've made the other corrections you recommended.  Thanks again.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 489 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20090824/25cbd541/attachment.sig>


More information about the reviews mailing list