Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Testing latest pari + WASM + node.js... and it works?! Wow.

28495 views
License: GPL3
ubuntu2004
1
#include <pari/pari.h> /* Include PARI headers */
2
3
#include <omp.h> /* Include OpenMP headers */
4
5
#define MAXTHREADS 3 /* Max number of parallel threads */
6
7
int
8
main(void)
9
{
10
GEN M,N1,N2, F1,F2,D;
11
struct pari_thread pth[MAXTHREADS];
12
int numth = omp_get_max_threads(), i;
13
/* Initialise the main PARI stack and global objects (gen_0, etc.) */
14
pari_init(8000000,500000);
15
if (numth > MAXTHREADS)
16
{
17
numth = MAXTHREADS;
18
omp_set_num_threads(numth);
19
}
20
/* Compute in the main PARI stack */
21
N1 = addis(int2n(256), 1); /* 2^256 + 1 */
22
N2 = subis(int2n(193), 1); /* 2^193 - 1 */
23
M = mathilbert(80);
24
/*Allocate pari thread structures */
25
for (i = 1; i < numth; i++) pari_thread_alloc(&pth[i],8000000,NULL);
26
#pragma omp parallel
27
{
28
int this_th = omp_get_thread_num();
29
if (this_th) (void)pari_thread_start(&pth[this_th]);
30
#pragma omp sections
31
{
32
#pragma omp section
33
{
34
F1 = factor(N1);
35
}
36
#pragma omp section
37
{
38
F2 = factor(N2);
39
}
40
#pragma omp section
41
{
42
D = det(M);
43
}
44
} /* omp sections */
45
if (this_th) pari_thread_close();
46
} /* omp parallel */
47
pari_printf("F1=%Ps\nF2=%Ps\nlog(D)=%Ps\n", F1, F2, glog(D,3));
48
for (i = 1; i < numth; i++) pari_thread_free(&pth[i]);
49
return 0;
50
}
51
52