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