Exemple #1
0
int main()
{
   setbuf(stdout, NULL);

   for (long l = 256; l <= 16384; l *= 2) {
      // for (long n = 256; n <= 16384; n *= 2) {
      for (long idx = 0; idx < 13; idx ++) {
         long n  = 256*(1L << idx/2);
         if (idx & 1) n += n/2;
           SetSeed((ZZ(l) << 64) + ZZ(n));

	   ZZX a, b, c;

           a.SetLength(n);
           for (long i = 0; i < n; i++) RandomBits(a[i], l);
           a.normalize();

           b.SetLength(n);
           for (long i = 0; i < n; i++) RandomBits(b[i], l);
           b.normalize();


	   double t;

	   mul(c, a, b);

	   long iter = 1;
	   do {
	      t = GetTime();
	      for (long i = 0; i < iter; i++) mul(c, a, b);
	      t = GetTime() - t;
	      iter *= 2;
	   } while (t < 3);
	   iter /= 2;

	   t = GetTime();
	   for (long i = 0; i < iter; i++) mul(c, a, b);
	   t = GetTime()-t;
	   double NTLTime = t;


	   FlintZZX f_a(a), f_b(b), f_c(c);


	   fmpz_poly_mul(f_c.value, f_a.value, f_b.value);
	   t = GetTime();
	   for (long i = 0; i < iter; i++) fmpz_poly_mul(f_c.value, f_a.value, f_b.value);
	   t = GetTime()-t;
	   double FlintTime = t;

           printf("%8.2f", FlintTime/NTLTime);
      }

      printf("\n");
   }
}
Exemple #2
0
Sivia::Sivia(repere& R, struct sivia_struct *par) : R(R) {

    par->area = 0;

    // Create the function we want to apply SIVIA on.
    Variable x,y;
    double ei = par->ei;
    double xb=par->xb1,yb=par->yb1;
    Interval xbi=Interval(par->xb1-ei,par->xb1+ei),ybi=Interval(par->yb1-ei,par->yb1+ei);

    double arc = par->sonar_arc;

    double r = pow(par->sonar_radius,2);
    double th1 = par->th[0];
    double th2=th1+arc;
    double th21= par->th[1];
    double th22=th21 + arc;
    double th31= par->th[2];
    double th32=th31 + arc;
    double e=1;
    double epsilon = par->epsilon;

    double xin,yin;

    // First SONAR
    Function f(x,y,sqr(x-xbi)+sqr(y-ybi));

    NumConstraint c1(x,y,f(x,y)<=r+e);
    NumConstraint c2(x,y,f(x,y)>=e);
    NumConstraint c3(x,y,f(x,y)>r+e);
    NumConstraint c4(x,y,f(x,y)<e);


    double sign1,sign2;
    if(cos(th1)>0) sign1=1;
    else sign1=-1;
    if(cos(th2)<0) sign2=1;
    else sign2=-1;


    NumConstraint cth11(x,y,sign1*(y-ybi-((sin(th1))/(cos(th1)))*(x-xbi))<0);
    NumConstraint cth12(x,y,sign1*(y-ybi-((sin(th1))/(cos(th1)))*(x-xbi))>0);
    NumConstraint cth21(x,y,sign2*(y-ybi-((sin(th2))/(cos(th2)))*(x-xbi))<0);
    NumConstraint cth22(x,y,sign2*(y-ybi-((sin(th2))/(cos(th2)))*(x-xbi))>0);


//     Create contractors with respect to each
//     of the previous constraints.
    CtcFwdBwd out1(c1);
    CtcFwdBwd out2(c2);
    CtcFwdBwd in1(c3);
    CtcFwdBwd in2(c4);


    CtcFwdBwd outth1(cth12);
    CtcFwdBwd inth1(cth11);
    CtcFwdBwd inth2(cth21);
    CtcFwdBwd outth2(cth22);

//    CtcIn inside(f,Interval(-1,1));
//    CtcNotIn outside(f,Interval(-1,1));
    // Create a contractor that removes all the points
    // that do not satisfy either f(x,y)<=2 or f(x,y)>=0.
    // These points are "outside" of the solution set.
    CtcCompo outside1(out1,out2,outth1,outth2);

    // Create a contractor that removes all the points
    // that do not satisfy both f(x,y)>2 or f(x,y)<0.
    // These points are "inside" the solution set.
    CtcUnion inside11(in1,in2,inth1);
    CtcUnion inside1(inside11,inth2);


    // Second SONAR
    double xb2=par->xb2,yb2=par->yb2;
    Interval xb2i=Interval(par->xb2-ei,par->xb2+ei),yb2i=Interval(par->yb2-ei,par->yb2+ei);

    Function f2(x,y,sqr(x-xb2i)+sqr(y-yb2i));
    NumConstraint c21(x,y,f2(x,y)<=r+e);
    NumConstraint c22(x,y,f2(x,y)>=e);
    NumConstraint c23(x,y,f2(x,y)>r+e);
    NumConstraint c24(x,y,f2(x,y)<e);


    double sign21,sign22;
    if(cos(th21)>0) sign21=-1;
    else sign21=1;
    if(cos(th22)<0) sign22=1;
    else sign22=-1;


    NumConstraint cth211(x,y,sign21*(y-yb2i-((sin(th21))/(cos(th21)))*(x-xb2i))<0);
    NumConstraint cth212(x,y,sign21*(y-yb2i-((sin(th21))/(cos(th21)))*(x-xb2i))>0);
    NumConstraint cth221(x,y,sign22*(y-yb2i-((sin(th22))/(cos(th22)))*(x-xb2i))<0);
    NumConstraint cth222(x,y,sign22*(y-yb2i-((sin(th22))/(cos(th22)))*(x-xb2i))>0);

//     Create contractors with respect to each
//     of the previous constraints.
    CtcFwdBwd out21(c21);
    CtcFwdBwd out22(c22);
    CtcFwdBwd in21(c23);
    CtcFwdBwd in22(c24);


    CtcFwdBwd outth21(cth211);
    CtcFwdBwd inth21(cth212);
    CtcFwdBwd inth22(cth221);
    CtcFwdBwd outth22(cth222);

//    CtcIn inside(f,Interval(-1,1));
//    CtcNotIn outside(f,Interval(-1,1));
    // Create a contractor that removes all the points
    // that do not satisfy either f(x,y)<=2 or f(x,y)>=0.
    // These points are "outside" of the solution set.
    CtcCompo outside2(out21,out22,outth21,outth22);

    // Create a contractor that removes all the points
    // that do not satisfy both f(x,y)>2 or f(x,y)<0.
    // These points are "inside" the solution set.
    CtcUnion inside21(in21,in22,inth21);
    CtcUnion inside2(inside21,inth22);



    //Third SONAR

    double xb3=par->xb3,yb3=par->yb3;
    Interval xb3i=Interval(par->xb3-ei,par->xb3+ei),yb3i=Interval(par->yb3-ei,par->yb3+ei);

    Function f3(x,y,sqr(x-xb3i)+sqr(y-yb3i));
    NumConstraint c31(x,y,f3(x,y)<=r+e);
    NumConstraint c32(x,y,f3(x,y)>=e);
    NumConstraint c33(x,y,f3(x,y)>r+e);
    NumConstraint c34(x,y,f3(x,y)<e);


    double sign31,sign32;
    if(cos(th31)>0) sign31=-1;
    else sign31=1;
    if(cos(th32)<0) sign32=1;
    else sign32=-1;


    NumConstraint cth311(x,y,sign31*(y-yb3i-((sin(th31))/(cos(th31)))*(x-xb3i))<0);
    NumConstraint cth312(x,y,sign31*(y-yb3i-((sin(th31))/(cos(th31)))*(x-xb3i))>0);
    NumConstraint cth321(x,y,sign32*(y-yb3i-((sin(th32))/(cos(th32)))*(x-xb3i))<0);
    NumConstraint cth322(x,y,sign32*(y-yb3i-((sin(th32))/(cos(th32)))*(x-xb3i))>0);

//     Create contractors with respect to each
//     of the previous constraints.
    CtcFwdBwd out31(c31);
    CtcFwdBwd out32(c32);
    CtcFwdBwd in31(c33);
    CtcFwdBwd in32(c34);


    CtcFwdBwd outth31(cth311);
    CtcFwdBwd inth31(cth312);
    CtcFwdBwd inth32(cth321);
    CtcFwdBwd outth32(cth322);

//    CtcIn inside(f,Interval(-1,1));
//    CtcNotIn outside(f,Interval(-1,1));
    // Create a contractor that removes all the points
    // that do not satisfy either f(x,y)<=2 or f(x,y)>=0.
    // These points are "outside" of the solution set.
    CtcCompo outside3(out31,out32,outth31,outth32);

    // Create a contractor that removes all the points
    // that do not satisfy both f(x,y)>2 or f(x,y)<0.
    // These points are "inside" the solution set.
    CtcUnion inside31(in31,in32,inth31);
    CtcUnion inside3(inside31,inth32);

    //CtcQInter inter(inside,1);

    //Artifact MODELISATION

    double xa = par->xa;
    double ya = par->ya;

    double ra = par->ra;

    Function f_a(x,y,sqr(x-xa)+sqr(y-ya));

    NumConstraint ca1(x,y,f_a(x,y)<=sqr(ra));
    NumConstraint ca2(x,y,f_a(x,y)>=sqr(ra)-par->thick);
    NumConstraint ca3(x,y,f_a(x,y)>sqr(ra));
    NumConstraint ca4(x,y,f_a(x,y)<sqr(ra)-par->thick);

    CtcFwdBwd aout1(ca1);
    CtcFwdBwd aout2(ca2);
    CtcFwdBwd ain1(ca3);
    CtcFwdBwd ain2(ca4);

    CtcUnion ain(ain1,ain2);
    CtcCompo aout(aout1,aout2);


    //Robot MODELISATION

    double xr = par->xr; //robot position x
    double yr = par->yr; //robot position y

    double wr = par->wr; //robot width
    double lr = par->lr; //robot length
    double ep = par->thick;

    xr = par->xr - wr/2;
    NumConstraint inrx1(x,y,x>xr+ep);
    NumConstraint outrx1(x,y,x<xr+ep);
    NumConstraint inrx2(x,y,x<xr-ep);
    NumConstraint outrx2(x,y,x>xr-ep);
    NumConstraint inry1(x,y,y<yr-lr/2);
    NumConstraint outry1(x,y,y>yr-lr/2);
    NumConstraint inry2(x,y,y>yr+lr/2);
    NumConstraint outry2(x,y,y<yr+lr/2);

    CtcFwdBwd incrx1(inrx1);
    CtcFwdBwd incrx2(inrx2);
    CtcFwdBwd incry1(inry1);
    CtcFwdBwd incry2(inry2);

    CtcFwdBwd outcrx1(outrx1);
    CtcFwdBwd outcrx2(outrx2);
    CtcFwdBwd outcry1(outry1);
    CtcFwdBwd outcry2(outry2);

    CtcUnion inrtemp(incrx1,incrx2,incry1);
    CtcUnion inr1(inrtemp,incry2);
    CtcCompo outrtemp(outcrx1,outcrx2,outcry1);
    CtcCompo outr1(outrtemp,outcry2);

    //2nd rectangle
    xr = par->xr + wr/2;

    NumConstraint inrx21(x,y,x>xr+ep);
    NumConstraint outrx21(x,y,x<xr+ep);
    NumConstraint inrx22(x,y,x<xr-ep);
    NumConstraint outrx22(x,y,x>xr-ep);
    NumConstraint inry21(x,y,y<yr-lr/2);
    NumConstraint outry21(x,y,y>yr-lr/2);
    NumConstraint inry22(x,y,y>yr+lr/2);
    NumConstraint outry22(x,y,y<yr+lr/2);

    CtcFwdBwd incrx21(inrx21);
    CtcFwdBwd incrx22(inrx22);
    CtcFwdBwd incry21(inry21);
    CtcFwdBwd incry22(inry22);

    CtcFwdBwd outcrx21(outrx21);
    CtcFwdBwd outcrx22(outrx22);
    CtcFwdBwd outcry21(outry21);
    CtcFwdBwd outcry22(outry22);

    CtcUnion inrtemp2(incrx21,incrx22,incry21);
    CtcUnion inr2(inrtemp2,incry22);
    CtcCompo outrtemp2(outcrx21,outcrx22,outcry21);
    CtcCompo outr2(outrtemp2,outcry22);


    //3nd rectangle top rectangle
    yr=par->yr+par->lr/2;
    xr=par->xr;

    NumConstraint inrx31(x,y,x>xr+wr/2+ep);
    NumConstraint outrx31(x,y,x<xr+wr/2+ep);
    NumConstraint inrx32(x,y,x<xr-wr/2-ep);
    NumConstraint outrx32(x,y,x>xr-wr/2-ep);
    NumConstraint inry31(x,y,y<yr-ep);
    NumConstraint outry31(x,y,y>yr-ep);
    NumConstraint inry32(x,y,y>yr+ep);
    NumConstraint outry32(x,y,y<yr+ep);

    CtcFwdBwd incrx31(inrx31);
    CtcFwdBwd incrx32(inrx32);
    CtcFwdBwd incry31(inry31);
    CtcFwdBwd incry32(inry32);

    CtcFwdBwd outcrx31(outrx31);
    CtcFwdBwd outcrx32(outrx32);
    CtcFwdBwd outcry31(outry31);
    CtcFwdBwd outcry32(outry32);

    CtcUnion inrtemp3(incrx31,incrx32,incry31);
    CtcUnion inr3(inrtemp3,incry32);
    CtcCompo outrtemp3(outcrx31,outcrx32,outcry31);
    CtcCompo outr3(outrtemp3,outcry32);

    //4 rectangle bot

    yr=par->yr-par->lr/2;
    xr=par->xr;

    NumConstraint inrx41(x,y,x>xr+wr/2+ep);
    NumConstraint outrx41(x,y,x<xr+wr/2+ep);
    NumConstraint inrx42(x,y,x<xr-wr/2-ep);
    NumConstraint outrx42(x,y,x>xr-wr/2-ep);
    NumConstraint inry41(x,y,y<yr-ep);
    NumConstraint outry41(x,y,y>yr-ep);
    NumConstraint inry42(x,y,y>yr+ep);
    NumConstraint outry42(x,y,y<yr+ep);

    CtcFwdBwd incrx41(inrx41);
    CtcFwdBwd incrx42(inrx42);
    CtcFwdBwd incry41(inry41);
    CtcFwdBwd incry42(inry42);

    CtcFwdBwd outcrx41(outrx41);
    CtcFwdBwd outcrx42(outrx42);
    CtcFwdBwd outcry41(outry41);
    CtcFwdBwd outcry42(outry42);

    CtcUnion inrtemp4(incrx41,incrx42,incry41);
    CtcUnion inr4(inrtemp4,incry42);
    CtcCompo outrtemp4(outcrx41,outcrx42,outcry41);
    CtcCompo outr4(outrtemp4,outcry42);

    CtcCompo inrtp(inr1,inr2,inr3);
    CtcUnion outrtp(outr1,outr2,outr3);

    CtcCompo inr(inrtp,inr4);
    CtcUnion outr(outrtp,outr4);

    yr = par->yr;

    int maxq = 3; //nb of contractors
    int Qinter = 2;
    int ctcq = maxq - Qinter + 1; //nb for q-relaxed function of Ibex


    Array<Ctc> inside1r1(inside1,inr,ain);
    Array<Ctc> outside1r1(outside1,outr,aout);

    Array<Ctc> inside2r1(inside2,inr,ain);
    Array<Ctc> outside2r1(outside2,outr,aout);

    Array<Ctc> inside3r1(inside3,inr,ain);
    Array<Ctc> outside3r1(outside3,outr,aout);

    CtcQInter outside1r(outside1r1,Qinter);
    CtcQInter inside1r(inside1r1,ctcq);

    CtcQInter outside2r(outside2r1,Qinter);
    CtcQInter inside2r(inside2r1,ctcq);

    CtcQInter outside3r(outside3r1,Qinter);
    CtcQInter inside3r(inside3r1,ctcq);


    // Build the initial box.
    IntervalVector box(2);
    box[0]=Interval(-10,10);
    box[1]=Interval(-10,10);
    par->vin.clear();
    // Build the way boxes will be bisected.
    // "LargestFirst" means that the dimension bisected
    // is always the largest one.

    int nbox1=0;
    LargestFirst lf;
    IntervalVector viinside1(2);
    stack<IntervalVector> s;
    s.push(box);
    while (!s.empty()) {
        IntervalVector box=s.top();
        s.pop();
            contract_and_draw(inside1r,box,viinside1,1,par,nbox1,Qt::magenta,Qt::red);
            if (box.is_empty()) { continue; }

            contract_and_draw(outside1r,box,viinside1,0,par,nbox1,Qt::darkBlue,Qt::cyan);
            if (box.is_empty()) { continue; }

            if (box.max_diam()<epsilon) {
                R.DrawBox(box[0].lb(),box[0].ub(),box[1].lb(),box[1].ub(),QPen(Qt::yellow),QBrush(Qt::NoBrush));
            } else {
                pair<IntervalVector,IntervalVector> boxes=lf.bisect(box);
                s.push(boxes.first);
                s.push(boxes.second);
            }
    }

    if(par->isinside==1){
        robot_position_estimator(nbox1,par);
        par->isinside1=1;
        par->isinside=0;
        //cout<<"area1: "<<par->area<<endl;
    }

    IntervalVector box2(2);
    box2[0]=Interval(-10,10);
    box2[1]=Interval(-10,10);

    // Build the way boxes will be bisected.
    // "LargestFirst" means that the dimension bisected
    // is always the largest one.
    int nbox2=0;
    LargestFirst lf2;
    IntervalVector viinside2(2);
    stack<IntervalVector> s2;
    s2.push(box2);
    while (!s2.empty()) {
        IntervalVector box2=s2.top();
        s2.pop();
            contract_and_draw(inside2r,box2,viinside2,2,par,nbox2,Qt::magenta,Qt::red);
            if (box2.is_empty()) { continue; }

            contract_and_draw(outside2r,box2,viinside2,0,par,nbox2,Qt::darkBlue,Qt::cyan);
            if (box2.is_empty()) { continue; }

            if (box2.max_diam()<epsilon) {
                R.DrawBox(box2[0].lb(),box2[0].ub(),box2[1].lb(),box2[1].ub(),QPen(Qt::yellow),QBrush(Qt::NoBrush));
            } else {
                pair<IntervalVector,IntervalVector> boxes2=lf2.bisect(box2);
                s2.push(boxes2.first);
                s2.push(boxes2.second);
            }
    }
    if(par->isinside==1){
        robot_position_estimator(nbox2,par);
        par->isinside2=1;
        par->isinside=0;
        //cout<<"area2: "<<par->area<<endl;
    }
    IntervalVector box3(2);
    box3[0]=Interval(-10,10);
    box3[1]=Interval(-10,10);

    // Build the way boxes will be bisected.
    // "LargestFirst" means that the dimension bisected
    // is always the largest one.
    int nbox3=0;
    LargestFirst lf3;
    IntervalVector viinside3(2);
    stack<IntervalVector> s3;
    s3.push(box3);
    while (!s3.empty()) {
        IntervalVector box3=s3.top();
        s3.pop();
            contract_and_draw(inside3r,box3,viinside3,3,par,nbox3,Qt::magenta,Qt::red);
            if (box3.is_empty()) { continue; }

            contract_and_draw(outside3r,box3,viinside3,0,par,nbox3,Qt::darkBlue,Qt::cyan);
            if (box3.is_empty()) { continue; }

            if (box3.max_diam()<epsilon) {
                R.DrawBox(box3[0].lb(),box3[0].ub(),box3[1].lb(),box3[1].ub(),QPen(Qt::yellow),QBrush(Qt::NoBrush));
            } else {
                pair<IntervalVector,IntervalVector> boxes3=lf3.bisect(box3);
                s3.push(boxes3.first);
                s3.push(boxes3.second);
            }
    }
    if(par->isinside==1){
        robot_position_estimator(nbox3,par);
        par->isinside3=1;
        par->isinside=0;
        //cout<<"area3: "<<par->area<<endl;
    }
    par->state.clear();
    if (par->isinside1 ==1 || par->isinside2 ==1 || par->isinside3 ==1){
        double *aimth = new double[3];
        aimth[0] = get_angle(xb,yb,par->xin,par->yin)+M_PI ;
        aimth[1] = get_angle(xb2,yb2,par->xin,par->yin)+M_PI;
        aimth[2] = get_angle(xb3,yb3,par->xin,par->yin)+M_PI;

        R.DrawLine(xb,yb,xb+r*cos(aimth[0]),yb+r*sin(aimth[0]),QPen(Qt::red));
        R.DrawLine(xb2,yb2,xb2+r*cos(aimth[1]),yb2+r*sin(aimth[1]),QPen(Qt::red));
        R.DrawLine(xb3,yb3,xb3+r*cos(aimth[2]),yb3+r*sin(aimth[2]),QPen(Qt::red));

        par->state = std::string("found");
        double kp = par->kp;
        double u[3];

        for (int i=0;i<3;i++){
            u[i] =   -kp*atan(tan((par->th[i] - (aimth[i] - arc/2.0 ))/2));
            if(u[i]>par->sonar_speed) par->th[i] += par->sonar_speed;
            if(u[i]<-par->sonar_speed) par->th[i] += -par->sonar_speed;
            else par->th[i] += u[i];
        }
//        for (int i=0;i<3;i++){
//            u[i] =   atan(tan((par->th[i] - (aimth[i] - arc/2.0 ))/2));
//            par->th[i] -=u[i];
//        }
    }

    r = sqrt(r);
    //cout<<"th1"<<th1<<endl;
    R.DrawEllipse(xb,yb,par->ei,QPen(Qt::black),QBrush(Qt::NoBrush));
    R.DrawEllipse(xb2,yb2,par->ei,QPen(Qt::black),QBrush(Qt::NoBrush));
    R.DrawEllipse(xb3,yb3,par->ei,QPen(Qt::black),QBrush(Qt::NoBrush));

    R.DrawLine(xb,yb,xb+r*cos(th2),yb+r*sin(th2),QPen(Qt::green));
    R.DrawLine(xb2,yb2,xb2+r*cos(th22),yb2+r*sin(th22),QPen(Qt::green));
    R.DrawLine(xb3,yb3,xb3+r*cos(th32),yb3+r*sin(th32),QPen(Qt::green));

    R.DrawLine(xb,yb,xb+r*cos(th1),yb+r*sin(th1),QPen(Qt::green));
    R.DrawLine(xb2,yb2,xb2+r*cos(th21),yb2+r*sin(th21),QPen(Qt::green));
    R.DrawLine(xb3,yb3,xb3+r*cos(th31),yb3+r*sin(th31),QPen(Qt::green));

    R.DrawEllipse(par->xa,par->ya,par->ra,QPen(Qt::black),QBrush(Qt::NoBrush));

    R.DrawRobot(xr-wr/2,yr+lr/2,-3.14/2,wr,lr);
    R.Save("paving");

    par->vin.clear();
}
int
main (int   arg,
      char *argv[])
{
  GModule *module_self, *module_a, *module_b;
  gchar *dir;
  gchar *plugin_a, *plugin_b;
  SimpleFunc f_a, f_b, f_self;
  GModuleFunc gmod_f;

  if (!g_module_supported ())
    return 0;

  dir = g_get_current_dir ();

  plugin_a = g_strconcat (dir, G_DIR_SEPARATOR_S "libmoduletestplugin_a", 
			  NULL);
  plugin_b = g_strconcat (dir, G_DIR_SEPARATOR_S "libmoduletestplugin_b", 
			  NULL);

  g_free (dir);

  /* module handles */
  
  module_self = g_module_open (NULL, G_MODULE_BIND_LAZY);
  if (!module_self)
    g_error ("error: %s", g_module_error ());

  if (!g_module_symbol (module_self, "g_module_close", (gpointer *) &f_self))
    g_error ("error: %s", g_module_error ());

  module_a = g_module_open (plugin_a, G_MODULE_BIND_LAZY);
  if (!module_a)
    g_error ("error: %s", g_module_error ());

  module_b = g_module_open (plugin_b, G_MODULE_BIND_LAZY);
  if (!module_b)
    g_error ("error: %s", g_module_error ());

  /* get plugin state vars */

  if (!g_module_symbol (module_a, "gplugin_a_state", 
			(gpointer *) &gplugin_a_state))
    g_error ("error: %s", g_module_error ());
  
  if (!g_module_symbol (module_b, "gplugin_b_state", 
			(gpointer *) &gplugin_b_state))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, "check-init");
  
  /* get plugin specific symbols and call them
   */
  if (!g_module_symbol (module_a, "gplugin_a_func", (gpointer *) &f_a))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, NULL);
 
  if (!g_module_symbol (module_b, "gplugin_b_func", (gpointer *) &f_b))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, NULL);
 
  f_a ();
  test_states (NULL, "Hello world", NULL);
  
  f_b ();
  test_states (NULL, NULL, "Hello world");
  
  /* get and call globally clashing functions
   */
 
  if (!g_module_symbol (module_self, "g_clash_func", (gpointer *) &f_self))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, NULL);

  if (!g_module_symbol (module_a, "g_clash_func", (gpointer *) &f_a))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, NULL);
 
  if (!g_module_symbol (module_b, "g_clash_func", (gpointer *) &f_b))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, NULL);
 
  f_self ();
  test_states ("global clash", NULL, NULL);
  
  f_a ();
  test_states (NULL, "global clash", NULL);

  f_b ();
  test_states (NULL, NULL, "global clash");

  /* get and call clashing plugin functions  */

  if (!g_module_symbol (module_a, "gplugin_clash_func", (gpointer *) &f_a))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, NULL);

  if (!g_module_symbol (module_b, "gplugin_clash_func", (gpointer *) &f_b))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, NULL);

  plugin_clash_func = f_a;
  plugin_clash_func ();
  test_states (NULL, "plugin clash", NULL);

  plugin_clash_func = f_b;
  plugin_clash_func ();
  test_states (NULL, NULL, "plugin clash");

  /* call gmodule function from A  */

  if (!g_module_symbol (module_a, "gplugin_a_module_func", (gpointer *) &gmod_f))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, NULL);

  gmod_f (module_b);
  test_states (NULL, NULL, "BOOH");
 
  gmod_f (module_a);
  test_states (NULL, "BOOH", NULL);

  /* unload plugins  */

  if (!g_module_close (module_a))
    g_error ("error: %s", g_module_error ());

  if (!g_module_close (module_b))
    g_error ("error: %s", g_module_error ());
 
  return 0;
}
Exemple #4
0
int
main (int   arg,
      char *argv[])
{
  GModule *module_self, *module_a, *module_b;
  gchar *string;
  gchar *plugin_a, *plugin_b;
  SimpleFunc f_a, f_b, f_self;
  GModuleFunc gmod_f;

  string = g_get_current_dir ();
  g_print ("testgmodule (%s):\n", string);

#if (G_MODULE_IMPL == G_MODULE_IMPL_WIN32)
  plugin_a = g_strconcat (string, "\\libgplugin_a.dll", NULL);
  plugin_b = g_strconcat (string, "\\libgplugin_b.dll", NULL);
#elif (G_MODULE_IMPL == G_MODULE_IMPL_DLD)
  plugin_a = g_strconcat (string, "/.libs/", "libgplugin_a.sl", NULL);
  plugin_b = g_strconcat (string, "/.libs/", "libgplugin_b.sl", NULL);
#else /* neither DLD nor WIN32 */
  plugin_a = g_strconcat (string, "/.libs/", "libgplugin_a.so", NULL);
  plugin_b = g_strconcat (string, "/.libs/", "libgplugin_b.so", NULL);
#endif
  g_free (string);

  /* module handles
   */
  g_print ("get main module handle\n");
  module_self = g_module_open (NULL, G_MODULE_BIND_LAZY);
  if (!module_self)
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("check that not yet bound symbols in shared libraries of main module are retrievable:\n");
  string = "g_module_close";
  g_print ("retrive symbol `%s' from \"%s\":\n", string, g_basename (g_module_name (module_self)));
  if (!g_module_symbol (module_self, string, (gpointer) &f_self))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("retrived symbol `%s' as %p\n", string, f_self);
  g_print ("load plugin from \"%s\"\n", plugin_a);
  module_a = g_module_open (plugin_a, G_MODULE_BIND_LAZY);
  if (!module_a)
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("load plugin from \"%s\"\n", plugin_b);
  module_b = g_module_open (plugin_b, G_MODULE_BIND_LAZY);
  if (!module_b)
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }

  /* get plugin specific symbols and call them
   */
  string = "gplugin_a_func";
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
  if (!g_module_symbol (module_a, string, (gpointer) &f_a))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  string = "gplugin_b_func";
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_b)));
  if (!g_module_symbol (module_b, string, (gpointer) &f_b))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("call plugin function(%p) A: ", f_a);
  f_a ();
  g_print ("call plugin function(%p) B: ", f_b);
  f_b ();

  /* get and call globally clashing functions
   */
  string = "g_clash_func";
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_self)));
  if (!g_module_symbol (module_self, string, (gpointer) &f_self))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
  if (!g_module_symbol (module_a, string, (gpointer) &f_a))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_b)));
  if (!g_module_symbol (module_b, string, (gpointer) &f_b))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("call plugin function(%p) self: ", f_self);
  f_self ();
  g_print ("call plugin function(%p) A: ", f_a);
  f_a ();
  g_print ("call plugin function(%p) B: ", f_b);
  f_b ();

  /* get and call clashing plugin functions
   */
  string = "gplugin_clash_func";
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_self)));
  if (!g_module_symbol (module_self, string, (gpointer) &f_self))
    f_self = NULL;
  g_print ("retrived function `%s' from self: %p\n", string, f_self);
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
  if (!g_module_symbol (module_a, string, (gpointer) &f_a))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_b)));
  if (!g_module_symbol (module_b, string, (gpointer) &f_b))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("call plugin function(%p) A: ", f_a);
  plugin_clash_func = f_a;
  plugin_clash_func ();
  g_print ("call plugin function(%p) B: ", f_b);
  plugin_clash_func = f_b;
  plugin_clash_func ();

  /* call gmodule function form A
   */
  string = "gplugin_a_module_func";
  g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
  if (!g_module_symbol (module_a, string, (gpointer) &gmod_f))
    {
      g_print ("error: %s\n", g_module_error ());
      return 1;
    }
  g_print ("call plugin A's module function(%p):\n{\n", gmod_f);
  gmod_f (module_b);
  g_print ("}\n");

  
  /* unload plugins
   */
  g_print ("unload plugin A:\n");
  if (!g_module_close (module_a))
    g_print ("error: %s\n", g_module_error ());
  g_print ("unload plugin B:\n");
  if (!g_module_close (module_b))
    g_print ("error: %s\n", g_module_error ());

#if 0
  g_log_set_fatal_mask ("GModule", G_LOG_FATAL_MASK|G_LOG_LEVEL_WARNING);
  g_module_symbol (0, 0, 0);
  g_warning("jahooo");
  g_on_error_query (".libs/testgmodule");
#endif
  
  return 0;
}
Exemple #5
0
int
main (int    argc,
      char **argv)
{
  GModule *module_self, *module_a, *module_b;
  gchar *plugin_a, *plugin_b;
  SimpleFunc f_a, f_b, f_self;
  GModuleFunc gmod_f;

  g_test_init (&argc, &argv, NULL);

  if (!g_module_supported ())
    g_error ("dynamic modules not supported");

  plugin_a = g_test_build_filename (G_TEST_BUILT, "libmoduletestplugin_a", NULL);
  plugin_b = g_test_build_filename (G_TEST_BUILT, "libmoduletestplugin_b", NULL);

  /* module handles */
  
  module_self = g_module_open (NULL, G_MODULE_BIND_LAZY);
  if (!module_self)
    g_error ("error: %s", g_module_error ());

  if (!g_module_symbol (module_self, "g_module_close", (gpointer *) &f_self))
    g_error ("error: %s", g_module_error ());

  module_a = g_module_open (plugin_a, G_MODULE_BIND_LAZY);
  if (!module_a)
    g_error ("error: %s", g_module_error ());

  module_b = g_module_open (plugin_b, G_MODULE_BIND_LAZY);
  if (!module_b)
    g_error ("error: %s", g_module_error ());

  /* get plugin state vars */

  if (!g_module_symbol (module_a, "gplugin_a_state", 
			(gpointer *) &gplugin_a_state))
    g_error ("error: %s", g_module_error ());
  
  if (!g_module_symbol (module_b, "gplugin_b_state", 
			(gpointer *) &gplugin_b_state))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, "check-init");
  
  /* get plugin specific symbols and call them
   */
  if (!g_module_symbol (module_a, "gplugin_a_func", (gpointer *) &f_a))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, NULL);
 
  if (!g_module_symbol (module_b, "gplugin_b_func", (gpointer *) &f_b))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, NULL);
 
  f_a ();
  test_states (NULL, "Hello world", NULL);
  
  f_b ();
  test_states (NULL, NULL, "Hello world");
  
  /* get and call globally clashing functions
   */
 
  if (!g_module_symbol (module_self, "g_clash_func", (gpointer *) &f_self))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, NULL);

  if (!g_module_symbol (module_a, "g_clash_func", (gpointer *) &f_a))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, NULL);
 
  if (!g_module_symbol (module_b, "g_clash_func", (gpointer *) &f_b))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, NULL);
 
  f_self ();
  test_states ("global clash", NULL, NULL);
  
  f_a ();
  test_states (NULL, "global clash", NULL);

  f_b ();
  test_states (NULL, NULL, "global clash");

  /* get and call clashing plugin functions  */

  if (!g_module_symbol (module_a, "gplugin_clash_func", (gpointer *) &f_a))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, NULL);

  if (!g_module_symbol (module_b, "gplugin_clash_func", (gpointer *) &f_b))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, NULL);

  plugin_clash_func = f_a;
  plugin_clash_func ();
  test_states (NULL, "plugin clash", NULL);

  plugin_clash_func = f_b;
  plugin_clash_func ();
  test_states (NULL, NULL, "plugin clash");

  /* call gmodule function from A  */

  if (!g_module_symbol (module_a, "gplugin_a_module_func", (gpointer *) &gmod_f))
    g_error ("error: %s", g_module_error ());
  test_states (NULL, NULL, NULL);

  gmod_f (module_b);
  test_states (NULL, NULL, "BOOH");
 
  gmod_f (module_a);
  test_states (NULL, "BOOH", NULL);

  /* unload plugins  */

  if (!g_module_close (module_a))
    g_error ("error: %s", g_module_error ());

  if (!g_module_close (module_b))
    g_error ("error: %s", g_module_error ());

  g_free (plugin_a);
  g_free (plugin_b);
  g_module_close (module_self);
  return 0;
}
Exemple #6
0
int main()
{
   setbuf(stdout, NULL);
   SetSeed(ZZ(0));

   for (long l = 256; l <= 16384; l *= 2) {
      // for (long n = 256; n <= 16384; n *= 2) {
      for (long idx = 0; idx < 13; idx ++) {
         long n  = 256*(1L << idx/2);
         if (idx & 1) n += n/2;

         SetSeed((ZZ(l) << 64) + ZZ(n));

         ZZ p;
      
         RandomLen(p, l);
         if (!IsOdd(p)) p++;
         ZZ_p::init(p);
      
      
         ZZ_pX a, c, f;
      
         random(a, n);
         random(f, n);
         SetCoeff(f, n);
      
         ZZ_pXModulus F(f);
      
      
         double t;
      
         SqrMod(c, a, F);
      
         long iter = 1;
         do {
            t = GetTime();
            for (long i = 0; i < iter; i++) SqrMod(c, a, F);
            t = GetTime() - t;
            iter *= 2;
         } while (t < 3);
         iter /= 2;
      
         t = GetTime();
         for (long i = 0; i < iter; i++) SqrMod(c, a, F);
         t = GetTime()-t;
         double NTLTime = t;
      
      
         FlintZZ_pX f_a(a), f_c, f_f(f), f_finv;
         fmpz_mod_poly_reverse(f_finv.value, f_f.value, f_f.value->length); 
         fmpz_mod_poly_inv_series_newton(f_finv.value, f_finv.value, f_f.value->length);
      
         fmpz_mod_poly_mulmod_preinv(f_c.value, f_a.value, f_a.value, f_f.value, f_finv.value);
      
      
         t = GetTime();
         for (long i = 0; i < iter; i++) 
            fmpz_mod_poly_mulmod_preinv(f_c.value, f_a.value, f_a.value, f_f.value, f_finv.value);
         t = GetTime()-t;
         double FlintTime = t;

         printf("%8.2f", FlintTime/NTLTime);
      }

      printf("\n");
   }
}
Exemple #7
0
int main()
{
   setbuf(stdout, NULL);

   for (long l = 5; l <= 60; l += 5) {
      // for (long n = 1024; n <= 65536; n *= 2) {
      for (long idx = 0; idx < 13; idx ++) {
         long n  = 1024*(1L << idx/2);
         if (idx & 1) n += n/2;
           SetSeed((ZZ(l) << 64) + ZZ(n));

	   long p;

	   RandomLen(p, l);
           if (p % 2 == 0) p++;
	   zz_p::init(p);


	   zz_pX a, b, c, f;

	   random(a, n);
	   random(b, n);
           random(f, n);
           SetCoeff(f, n);

           zz_pXModulus F(f);
           zz_pXMultiplier B(b, F);

	   double t;

	   MulMod(c, a, B, F);

	   long iter = 1;
	   do {
	      t = GetTime();
	      for (long i = 0; i < iter; i++) MulMod(c, a, B, F);
	      t = GetTime() - t;
	      iter *= 2;
	   } while (t < 3);
	   iter /= 2;

	   t = GetTime();
	   for (long i = 0; i < iter; i++) MulMod(c, a, B, F);
	   t = GetTime()-t;
	   double NTLTime = t;



         Flintzz_pX f_a(a), f_b(b), f_c, f_f(f), f_finv;
         nmod_poly_reverse(f_finv.value, f_f.value, f_f.value->length);
         nmod_poly_inv_series_newton(f_finv.value, f_finv.value, f_f.value->length);

         nmod_poly_mulmod_preinv(f_c.value, f_a.value, f_b.value, f_f.value, f_finv.value);


         t = GetTime();
         for (long i = 0; i < iter; i++)
            nmod_poly_mulmod_preinv(f_c.value, f_a.value, f_b.value, f_f.value, f_finv.value);
         t = GetTime()-t;
         double FlintTime = t;


         printf("%8.2f", FlintTime/NTLTime);
      }

      printf("\n");
   }
}