From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Christophe Raffalli <christophe@raffalli.eu>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Parallel for with exception
Date: Fri, 14 Oct 2022 22:49:46 +0200 [thread overview]
Message-ID: <CAPFanBEzzVLv3Zo6dEmdX3G-F2Wcki9EgbGDN3DH1Egfrw16ew@mail.gmail.com> (raw)
In-Reply-To: <20221013040040.sfcmxo3h6ao63fiw@oulala>
[-- Attachment #1: Type: text/plain, Size: 1871 bytes --]
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
If I understand correctly, you are asking about cancellation for Domainslib tasks, specifically for Task.parallel_for.
(I would have created an issue against Domainslib to ask. Interestingly, I can find only one vague mention of cancellation there,
https://github.com/ocaml-multicore/domainslib/pull/51#discussion_r729296762
)
I haven't tried it, but I would think that the simple approach is to turn
Task.parallel_for ~start ~finish pool ~body:(fun i ->
... raise Exit ...
)
into
let stop : exn option Atomic.t = Atomic.make None
Task.parallel_for ~start ~finish pool ~body:(fun i ->
Option.iter raise (Atomic.get stop);
.. (Atomic.set stop Exit; raise Exit) ...
)
which guarantees prompt termination by checking a shared failure value at each iteration of the loop. But of course this adds a small amount of overhead, which may be undesirable if each loop iteration is supposed to be very fast. (Then the simple approach is to change "Option.iter" into "if i mod 100 = 0 then Option.iter ...".)
This is an instance of the general approach of letting users do cancellation explicitly on their side, if they want to.
On Thu, Oct 13, 2022 at 6:01 AM Christophe Raffalli <christophe@raffalli.eu<mailto:christophe@raffalli.eu>> wrote:
Hello,
I am trying ocaml 5.0 and Task.parralel_for in
domainlib is not compatible with exception to interrupt the loop.
When an exception is raised by a task, we need to interrupt or wait for the
other tasks to finish before raising the exception.
What is the recommanded solution for that pattern ?
Cheers,
Christophe
--
Christophe Raffalli
tél: +689 87 23 11 48
web: http://raffalli.eu
[-- Attachment #2: Type: text/html, Size: 3195 bytes --]
next prev parent reply other threads:[~2022-10-14 20:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-13 4:00 Christophe Raffalli
2022-10-14 20:49 ` Gabriel Scherer [this message]
2022-10-15 2:34 ` Christophe Raffalli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAPFanBEzzVLv3Zo6dEmdX3G-F2Wcki9EgbGDN3DH1Egfrw16ew@mail.gmail.com \
--to=gabriel.scherer@gmail.com \
--cc=caml-list@inria.fr \
--cc=christophe@raffalli.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox