[petsc-dev] new work on to start on threading and PETSc

Jed Brown jed at jedbrown.org
Sun May 25 21:10:31 CDT 2014


Barry Smith <bsmith at mcs.anl.gov> writes:

>    So the user code needs to explicitly call first the pragma and then
>    do a series of PETSc calls? Essentially they could often have
>    PetscInitialize() and then have this code fragment that contains
>    essentially all of main inside the else case?

It is always easy for PETSc to "automatically" create its own thread
pool, either in PetscInitialize or on demand.  (But if you start it
on-demand, when do you end it?)  But I want the programming model to be
able to precisely manage resources, and that means the caller needs to
be able to decide exactly which threads PETSc is using and when to
return them.  It's possible that all but one PETSc example will use the
automatic mode.


Now many users will soon realize that threading the solver provides only
limited benefit if the discretization (residual, Jacobian) are not also
threaded.  So how does the user get a hold of the threads.  It's selfish
for PETSc to insist on hiding them because that means other libraries
can't use them.  Some people will say "everything must use OpenMP in a
simplistic manner", but that's not very satisfying or portable
(especially when vendors replace an OpenMP-supporting compiler with a
different compiler that does not support OpenMP and don't even change
the executable name, but I digress).

So if different libraries mix threading models and there is no One
Thread Pool to Rule Them All, we have to be able to hand off threads.
The only way to get access to threads in OpenMP is to use the pragma.
So someone needs to get access to the threads and hand them off (that
somewhat ugly snippet of code), at least to whichever libraries don't
simply use OpenMP in a conventional way.

(I keep saying "in a conventional way", because it's perfectly valid to
create some context and open a parallel region first thing in main.
There are some good reasons to do this, but OpenMP's One Thread Pool
cannot deal with thread assignment in this case.)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20140525/9aa238ef/attachment.sig>


More information about the petsc-dev mailing list