/* Example program to illustrate MIRACL multi-threading with Unix tested with RedHat Linux 6.0 GCC compiler 1. Make sure MR_UNIX_MT is defined in mirdef.h 2. Compile all MIRACL modules with -D_REENTRANT flag 3. g++ -I. -D_REENTRANT -O2 threadux.cpp big.o zzn.o miracl.a -lpthread Don't forget the -lpthread flag to the linker Runs from the command prompt First thread factors one number, while second thread factors a second Each thread is initialised differently One outputs factors in decimal, the other in Hex The work of the threads are inter-leaved. */ #include #include #include #include "big.h" #include "zzn.h" using namespace std; // Brents factoring algorithm #define mr_min(a,b) ((a) < (b)? (a) : (b)) int brent(int id,char * fred,int base) { /* factoring program using Brents method */ long k,r,i,m,iter; Big n,z; ZZn x,y,q,ys; n=fred; cout << "thread "<< id << " factoring " << n << endl; get_mip()->IOBASE=base; m=10L; r=1L; iter=0L; z=0; do { modulo(n); // ZZn arithmetic done mod n y=z; // convert back to ZZn (n has changed!) cout << "thread " << id << " iteration " << iter << endl; q=1; do { x=y; for (i=1L;i<=r;i++) y=(y*y+3); k=0; do { iter++; if (iter%10==0) cout << "thread " << id << " iteration " << iter << endl; ys=y; for (i=1L;i<=mr_min(m,r-k);i++) { y=(y*y+3); q=((y-x)*q); } z=gcd(q,n); k+=m; } while (k