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 <pthread.h> /* Include POSIX threads headers */
4
5
void *
6
mydet(void *arg)
7
{
8
GEN F, M;
9
/* Set up thread stack and get thread parameter */
10
M = pari_thread_start((struct pari_thread*) arg);
11
F = det(M);
12
/* Free memory used by the thread */
13
pari_thread_close();
14
return (void*)F;
15
}
16
17
void *
18
myfactor(void *arg) /* same principle */
19
{
20
GEN F, N;
21
N = pari_thread_start((struct pari_thread*) arg);
22
F = factor(N);
23
pari_thread_close();
24
return (void*)F;
25
}
26
27
int
28
main(void)
29
{
30
GEN M,N1,N2, F1,F2,D;
31
pthread_t th1, th2, th3; /* POSIX-thread variables */
32
struct pari_thread pth1, pth2, pth3; /* pari thread variables */
33
34
/* Initialise the main PARI stack and global objects (gen_0, etc.) */
35
pari_init(8000000,500000);
36
/* Compute in the main PARI stack */
37
N1 = addis(int2n(256), 1); /* 2^256 + 1 */
38
N2 = subis(int2n(193), 1); /* 2^193 - 1 */
39
M = mathilbert(80);
40
/* Allocate pari thread structures */
41
pari_thread_alloc(&pth1,8000000,N1);
42
pari_thread_alloc(&pth2,8000000,N2);
43
pari_thread_alloc(&pth3,8000000,M);
44
/* pthread_create() and pthread_join() are standard POSIX-thread
45
* functions to start and get the result of threads. */
46
pthread_create(&th1,NULL, &myfactor, (void*)&pth1);
47
pthread_create(&th2,NULL, &myfactor, (void*)&pth2);
48
pthread_create(&th3,NULL, &mydet, (void*)&pth3); /* Start 3 threads */
49
pthread_join(th1,(void*)&F1);
50
pthread_join(th2,(void*)&F2);
51
pthread_join(th3,(void*)&D); /* Wait for termination, get the results */
52
pari_printf("F1=%Ps\nF2=%Ps\nlog(D)=%Ps\n", F1, F2, glog(D,3));
53
pari_thread_free(&pth1);
54
pari_thread_free(&pth2);
55
pari_thread_free(&pth3); /* clean up */
56
return 0;
57
}
58
59