// Test des operations de tirages aleatoires thread safe/nosafe #include "sopnamsp.h" #include "zthread.h" #include #include #include #include #include #include "tvector.h" #include "matharr.h" #include "fioarr.h" #include "tarrinit.h" #include "srandgen.h" #include "nbtri.h" #include "timing.h" #include "randr48.h" long Check_Redondances(TVector& v); //--------------------------------------------------------------------- // Classe heritant de ZThread, pour remplir un vecteur avec des aleatoires class MTRndTest : public ZThread { public: MTRndTest(TVector& v,bool thsafe=true,int nbuff=1024); virtual void run(); protected: string nom_; int inum_; TVector vv_; bool thsafe_; int nbuff_; }; static int mtrandId = 0; // Pour donner un identificateur a chaque thread MTRndTest::MTRndTest(Vector& v,bool thsafe,int nbuff) : vv_(v,true) , thsafe_(thsafe), nbuff_(nbuff) { if(nbuff_<=0) nbuff_ = 1024; char buff[32]; inum_ = mtrandId; sprintf(buff,"MTRndTest-Id=%d",mtrandId); mtrandId++; nom_ = buff; cout<<"Thread MTRndTest("<3) ? atoi(arg[3]): 64; if(NTH<=0) NTH = 1; cout<<"tmtrnd/arguments, VSZ= "< changed VSZ= "<>>>>>> Init de l'aleatoire"< DATA0(VSZ); { cout<<"\n>>>>>>> Remplissage en mono-thread avec drand48()"< DATA1(VSZ); { cout<<"\n>>>>>>> Remplissage par threads avec ThSDR48RandGen thread safe"< vth1; cout<<"...tmtrnd/creating threads "< sv = DATA1(Range(first, last)); vth1.push_back(new MTRndTest(sv,true,NBUFF) ); } cout<<"...tmtrnd/starting threads"<start(); cout<<"...tmtrnd/waiting for all threads to finish"<join(); cout<<"...tmtrnd/deleting thread objects"< DATA2(VSZ); { cout<<"\n>>>>>>> Remplissage par threads avec ThSDR48RandGen SANS thread safe"< vth2; cout << "......tmtrnd/creating threads " << endl; for(int kt=0; kt sv = DATA2(Range(first, last)); vth2.push_back(new MTRndTest(sv,false) ); } cout<<"......tmtrnd/starting threads"<start(); cout<<"......tmtrnd/waiting for all threads to finish"<join(); cout<<"......tmtrnd/deleting thread objects "< DATA0R(VSZ); { cout<<"\n>>>>>>> Remplissage en mono-thread avec ThSDR48RandGen"<>>>>>> Sorting"<>>>>>> Checking differences"<vmax00) vmax00 = v; v = fabs(DATA1(i)-DATA0(i)); if(v>vmax01) vmax01 = v; v = fabs(DATA2(i)-DATA0(i)); if(v>vmax02) vmax02 = v; v = fabs(DATA2(i)-DATA1(i)); if(v>vmax12) vmax12 = v; } cout<<"vmax00 = "<>>>>>> Checking redondances"<>>>>>> Writing to ppf"<eps || vmax01>eps) rc = 1; } catch (PThrowable exc) { cerr<<"zthr: catched Exception "<>>>>>> tmtrnd3/END"<& v) // Recherche des aleatoire tires 2 fois // Le vecteur "v" doit deja etre trie par valeurs CROISSANTES { int k=0; double eps=1.e-25; TVector dd(v,false); for(int i=dd.Size()-1;i>=1;i--) dd(i) -= dd(i-1); dd(0) = 0.; qsort(dd.Data(),(size_t)dd.Size(),sizeof(double),qSort_Dble); for(int i=1;i d00(d0r,false); d00 -= d0; \ TVector d10(d1,false); d10 -= d0; \ TVector d20(d2,false); d20 -= d0; \ TVector d21(d2,false); d21 -= d1; \ KeepObj(d00); KeepObj(d10); KeepObj(d20); KeepObj(d21); \ cout<<"-- Fin"< dd1(d1,false); \ for(int i=dd1.Size()-1;i>=1;i--) dd1(i) -= dd1(i-1); dd1(0) = 0.; \ TVector dd2(d2,false); \ for(int i=dd2.Size()-1;i>=1;i--) dd2(i) -= dd2(i-1); dd2(0) = 0.; \ qsort(dd1.Data(),(size_t)dd1.Size(),sizeof(double),qSort_Dble); \ qsort(dd2.Data(),(size_t)dd2.Size(),sizeof(double),qSort_Dble); \ double eps=1.e-25; \ int k1=0; for(int i=1;i