---
title: "Integer Factorisation"
canonical: "https://docs.magma-maths.org/v2.30-1/MagmaLanguage/Parallelism/integer-factorisation.html"
source: "https://docs.magma-maths.org/v2.30-1/MagmaLanguage/Parallelism/integer-factorisation.md"
part: "The Magma Language"
chapter: "Parallelism"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "The Magma Language", "source": "https://docs.magma-maths.org/v2.30-1/MagmaLanguage/index-magma-language.md"}
  - {"title": "Parallelism", "source": "https://docs.magma-maths.org/v2.30-1/MagmaLanguage/Parallelism/index-parallelism.md"}
prev: {"title": "Distributed Computation for Internal Algorithms", "source": "https://docs.magma-maths.org/v2.30-1/MagmaLanguage/Parallelism/distributed.md"}
next: {"title": "Ideal Class Group of Algebraic Number Fields", "source": "https://docs.magma-maths.org/v2.30-1/MagmaLanguage/Parallelism/classgroup.md"}
examples:
  - "ex-1169a4"
---

<a id="par-integer"></a>
<a id="id1"></a>
# Integer Factorisation

Parallel versions of the ECM and MPQS integer factorisation algorithm are available since V2.27. One can simply use `SetNthreads(t);` to select $t$ threads on the local node, and optionally use `StartWorkers` to include workers on other nodes. Then integer factorisation will automatically use the parallel versions when the integers are large enough for the ECM or MPQS algorithms to be selected.

<a id="example-ex-1169a4"></a>
## `Example: Distributed Integer Factorisation (ex-1169a4)`

The following code factors 10 random 80-digit integers using 32 threads on the local manager node, and 32 threads on the worker node2.

```magma
> SetNthreads(32);
> StartWorkers("node2", 32); // start worker with 32 threads on node2
> SetVerbose("Factorization", 1);
> SetVerbose("MPQS",1);
> for i := 1 to 10 do
>     n := Random(10^80);
>     time Factorisation(n);
> end for;
```
