Re: Parallel Sieve Of Eratosthenes

Liste des GroupesRevenir à cl ada 
Sujet : Re: Parallel Sieve Of Eratosthenes
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.lang.ada
Date : 30. Jun 2024, 10:10:06
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v5r3su$e60t$2@dont-email.me>
References : 1
User-Agent : Pan/0.158 (Avdiivka; )
This version uses a protected type to pass the stream of integers from
one task to the next. It seems to be much faster.
----
with Ada.Text_IO;
use Ada;
procedure parasieve2 is

    protected type int_buffer is

        entry put(i : in integer);
        entry get(i : out integer);

    private
        last_i : integer;
        got_i : boolean := false;
    end int_buffer;

    protected body int_buffer is

        entry put(i : in integer) when not got_i is
        begin
            last_i := i;
            got_i := true;
        end put;

        entry get(i : out integer) when got_i is
        begin
            i := last_i;
            got_i := false;
        end get;

    end int_buffer;

    type int_buffer_ptr is access int_buffer;

    task type child(from_parent : int_buffer_ptr) is
    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, i : integer;
        subchild : access offspring;
        to_child : int_buffer_ptr;

    begin
        from_parent.get(my_prime);
        Text_IO.Put_line(integer'image(my_prime));
        to_child := new int_buffer;
        subchild := new offspring(to_child);
        loop
            from_parent.get(i);
            if i mod my_prime /= 0 then
                to_child.put(i);
            end if;
        end loop;
    end child;

    to_first_child : int_buffer_ptr;
    first_child : access child;
    i : integer;

begin -- parasieve2
    i := 1;
    to_first_child := new int_buffer;
    first_child := new child(to_first_child);
    loop
        i := i + 1;
        to_first_child.put(i);
    end loop;
end parasieve2;

Date Sujet#  Auteur
30 Jun 24 * Parallel Sieve Of Eratosthenes6Lawrence D'Oliveiro
30 Jun 24 `* Re: Parallel Sieve Of Eratosthenes5Lawrence D'Oliveiro
30 Jun 24  `* Re: Parallel Sieve Of Eratosthenes4J-P. Rosen
1 Jul 24   `* Re: Parallel Sieve Of Eratosthenes3Lawrence D'Oliveiro
1 Jul 24    `* Re: Parallel Sieve Of Eratosthenes2J-P. Rosen
1 Jul 24     `- Re: Parallel Sieve Of Eratosthenes1Lawrence D'Oliveiro

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal