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