Deutsch English Français Italiano |
<v5srnj$o2j1$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Lawrence D'Oliveiro <ldo@nz.invalid> Newsgroups: comp.lang.ada Subject: Re: Parallel Sieve Of Eratosthenes Date: Mon, 1 Jul 2024 00:02:59 -0000 (UTC) Organization: A noiseless patient Spider Lines: 67 Message-ID: <v5srnj$o2j1$1@dont-email.me> References: <v5r3ma$e60t$1@dont-email.me> <v5r3su$e60t$2@dont-email.me> <v5s1it$jldp$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Mon, 01 Jul 2024 02:02:59 +0200 (CEST) Injection-Info: dont-email.me; posting-host="35befde2f32fa6750471555e4cd92fa9"; logging-data="789089"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18t3jWVlgNCV+SsflyUBHfI" User-Agent: Pan/0.158 (Avdiivka; ) Cancel-Lock: sha1:2u5oBPLB5iuBJZrwGAgPuSj0RmQ= Bytes: 2822 On Sun, 30 Jun 2024 18:36:45 +0200, J-P. Rosen wrote: > That's because in your first version, you call the child within the > accept statement. Therefore you wait for the value to go to the end of > the pipeline before processing the next value. > Try to copy the number to a variable, and call the child after the end > of the accept. This will give you 100% CPU time usage. > > BTW, you don't need an access type. Just use a declare block to create > the child after the first accept. Thanks for the comments, how about this slight rework of the first version. It does seem faster, but I’m not sure it’s as fast as the second version. ---- with Ada.Text_IO; use Ada; procedure parasieve1b is task type child is entry next_int(i : integer); end child; subtype offspring is child; -- need another name because "child" within child refers to -- current task, not to the type task body child is my_prime : integer; begin accept next_int(i : integer) do my_prime := i; Text_IO.Put_line(integer'image(my_prime)); end next_int; declare subchild : offspring; ii : integer; begin loop accept next_int(i : integer) do if i mod my_prime /= 0 then ii := i; else ii := 0; end if; end next_int; if ii /= 0 then subchild.next_int(ii); end if; end loop; end; end child; first_child : child; i : integer; begin -- parasieve1b i := 1; loop i := i + 1; first_child.next_int(i); end loop; end parasieve1b;