Catalogue of GP/PARI Functions: Parallel programming
Author: Nils-Peter Skoruppa
Keywords: PARI, GP, DOC

### Parallel programming

#### parapply(f, x)

Parallel evaluation of `f` on the elements of `x`. The function `f` must not access global variables or variables declared with local(), and must be free of side effects.

      parapply(factor,[2^256 + 1, 2^193 - 1])

factors 2^{256} + 1 and 2^{193} - 1 in parallel.

      {
        my(E = ellinit([1,3]), V = vector(12,i,randomprime(2^200)));
        parapply(p->ellcard(E,p), V)
      }

computes the order of E(F_p) for 12 random primes of 200 bits.

The library syntax is `GEN parapply(GEN f, GEN x)`.

#### pareval(x)

Parallel evaluation of the elements of `x`, where `x` is a vector of closures. The closures must be of arity 0, must not access global variables or variables declared with `local` and must be free of side effects.

The library syntax is `GEN pareval(GEN x)`.

#### parfor(i = a,{b},expr1,{j},{expr2})

Evaluates the sequence `expr2` (dependent on i and j) for i between a and b, in random order, computed in parallel; in this sequence `expr2`, substitute the variable j by the value of `expr1` (dependent on i). If b is omitted, the loop will not stop.

It is allowed for `expr2` to exit the loop using `break`/`next`/`return`; however in that case, `expr2` will still be evaluated for all remaining value of i less than the current one, unless a subsequent `break`/`next`/`return` happens.

#### parforprime(p = a,{b},expr1,{j},{expr2})

Evaluates the sequence `expr2` (dependent on p and j) for p prime between a and b, in random order, computed in parallel. Substitute for j the value of `expr1` (dependent on p). If b is omitted, the loop will not stop.

It is allowed fo `expr2` to exit the loop using `break`/`next`/`return`, however in that case, `expr2` will still be evaluated for all remaining value of p less than the current one, unless a subsequent `break`/`next`/`return` happens.

#### parselect(f, A, {flag = 0})

Selects elements of A according to the selection function f, done in parallel. If flag is 1, return the indices of those elements (indirect selection) The function `f` must not access global variables or variables declared with local(), and must be free of side effects.

The library syntax is `GEN parselect(GEN f, GEN A, long flag )`.

#### parsum(i = a,b,expr,{x})

Sum of expression expr, initialized at x, the formal parameter going from a to b, evaluated in parallel in random order. The expression `expr` must not access global variables or variables declared with `local()`, and must be free of side effects.

      parsum(i=1,1000,ispseudoprime(2^prime(i)-1))

returns the numbers of prime numbers among the first 1000 Mersenne numbers.

#### parvector(N,i,expr)

As `vector(N,i,expr)` but the evaluations of `expr` are done in parallel. The expression `expr` must not access global variables or variables declared with `local()`, and must be free of side effects.

      parvector(10,i,quadclassunit(2^(100+i)+1).no)

computes the class numbers in parallel.