Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* [Caml-list] Parallel for with exception
@ 2022-10-13  4:00 Christophe Raffalli
  2022-10-14 20:49 ` Gabriel Scherer
  0 siblings, 1 reply; 3+ messages in thread
From: Christophe Raffalli @ 2022-10-13  4:00 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 169 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.


[-- Attachment #2: Type: message/rfc822, Size: 14753 bytes --]

[-- Attachment #2.1.1: Type: text/plain, Size: 411 bytes --]


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.1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 499 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Parallel for with exception
  2022-10-13  4:00 [Caml-list] Parallel for with exception Christophe Raffalli
@ 2022-10-14 20:49 ` Gabriel Scherer
  2022-10-15  2:34   ` Christophe Raffalli
  0 siblings, 1 reply; 3+ messages in thread
From: Gabriel Scherer @ 2022-10-14 20:49 UTC (permalink / raw)
  To: Christophe Raffalli; +Cc: caml-list

[-- 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 --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Parallel for with exception
  2022-10-14 20:49 ` Gabriel Scherer
@ 2022-10-15  2:34   ` Christophe Raffalli
  0 siblings, 0 replies; 3+ messages in thread
From: Christophe Raffalli @ 2022-10-15  2:34 UTC (permalink / raw)
  To: Gabriel Scherer; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 169 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.


[-- Attachment #2: Type: message/rfc822, Size: 15785 bytes --]

[-- Attachment #2.1.1: Type: text/plain, Size: 725 bytes --]

On 22-10-14 22:49:46, Gabriel Scherer wrote:
> If I understand correctly, you are asking about cancellation for Domainslib
> tasks, specifically for Task.parallel_for.

Hello,

Not only, parallel_for does not seem to even transmit the exception.
But yes, it should also cancel the useless computation.

In fact, what I really need are parallel exists and for_all.

> (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 added an issue...

Cheers,
Christophe



--
Christophe Raffalli
tél: +689 87 23 11 48
web: http://raffalli.eu

[-- Attachment #2.1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 499 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-10-15  2:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-13  4:00 [Caml-list] Parallel for with exception Christophe Raffalli
2022-10-14 20:49 ` Gabriel Scherer
2022-10-15  2:34   ` Christophe Raffalli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox