int main(){

	float a[10000]; /* a is an array of 10000 floats */
	float b[10000]; /* b is an array of 10000 floats */

	/* initialize elements of array n to 0 */
	for (int i = 0; i < 10000; i++) {
		a[i] = i + 1; /* set element at location i to i + 1 */
		b[i] = i + 1; /* set element at location i to i + 1 */
	}

	struct timeval start, end;
	double elapsedTime;
	gettimeofday(&start, NULL);
	compute1(a, 10000);
	gettimeofday(&end, NULL);
	elapsedTime = (end.tv_sec - start.tv_sec) * 1000.0;      // sec to ms
    elapsedTime += (end.tv_usec - start.tv_usec) / 1000.0;   // us to ms
	printf("In compute1 work took %f ms\n", elapsedTime);

	gettimeofday(&start, NULL);
	compute2(b, 10000);
	gettimeofday(&end, NULL);
	elapsedTime = (end.tv_sec - start.tv_sec) * 1000.0;      // sec to ms
    elapsedTime += (end.tv_usec - start.tv_usec) / 1000.0;   // us to ms
	printf("In compute2 work took %f ms\n", elapsedTime);
}
Example #2
0
int main(void)
{
	pthread_t t1;
	int i;
	pthread_create(&t1, NULL, thread1, NULL);
	compute1();
	compute2();
	compute3();
	pthread_join(t1, NULL);
	return 0;
}
Example #3
0
void eval(void) 
{ int tmp ;
  int tmp___0 ;
  int tmp___1 ;
  int tmp___2 ;
  int tmp___3 ;

  {
  {
  while (1) {
    while_4_continue: /* CIL Label */ ;
    if ((int )wl_st == 0) {

    } else {
      if ((int )c1_st == 0) {

      } else {
        if ((int )c2_st == 0) {

        } else {
          if ((int )wb_st == 0) {

          } else {
            if ((int )r_st == 0) {

            } else {
              goto while_4_break;
            }
          }
        }
      }
    }
    if ((int )wl_st == 0) {
      {
	tmp =  __VERIFIER_nondet_int(); 
      }
      if (tmp) {
        {
        wl_st = 1;
        write_loop();
        }
      } else {

      }
    } else {

    }
    if ((int )c1_st == 0) {
      {
	tmp___0 =  __VERIFIER_nondet_int(); 
      }
      if (tmp___0) {
        {
        c1_st = 1;
        compute1();
        }
      } else {

      }
    } else {

    }
    if ((int )c2_st == 0) {
      {
	tmp___1 =  __VERIFIER_nondet_int(); 
      }
      if (tmp___1) {
        {
        c2_st = 1;
        compute2();
        }
      } else {

      }
    } else {

    }
    if ((int )wb_st == 0) {
      {
	tmp___2 =  __VERIFIER_nondet_int(); 
      }
      if (tmp___2) {
        {
        wb_st = 1;
        write_back();
        }
      } else {

      }
    } else {

    }
    if ((int )r_st == 0) {
      {
	tmp___3 = __VERIFIER_nondet_int();
      }
      if (tmp___3) {
        {
        r_st = 1;
        read();
        }
      } else {

      }
    } else {

    }
  }
  while_4_break: /* CIL Label */ ;
  }

  return;
}
}
Example #4
0
int compute1(long double &a,string s,int angle=0)//算术综合运算
{
    if(!check_b(s))
        return 0;
    Stack<long double> ss(20);
    Stack<char> sf(20);
    int i=0,j;
    string s1,s2;
    char c;
    long double b;
    while(IsUselessChar(s[i]))
        i++;
    if(s[i]=='-')
    {
        ss.PushStack(-1);
        sf.PushStack('*');
        i++;
    }
    else if(s[i]=='+')
        i++;
    while(s[i])
    {
        s2="\0";
        if(IsUselessChar(s[i]))
            i++;
        else if(IsBracket(s[i])==1)
        {
            if(i>0&&!IsOperator1(s[i-1]))
                if(!sf.PushStack('*'))
                    return 0;
            s2=GetBracketData(s,i);
            if(!compute1(a,s2,angle)||!ss.PushStack(a))
                return 0;
        }
        else if(IsOperator1(s[i]))
        {
            if(s[i]=='!')
            {
                if(!ss.PopStack(b)||!factorial(a,(int)b)||!ss.PushStack(a))
                    return 0;
                i++;
                continue;
            }
            while(sf.GetTopData(c))
            {
                if(PRI(s[i])>PRI(c))
                    break;
                if(!ss.PopStack(b)||!ss.PopStack(a)||!sf.PopStack(c)||!Account1(a,b,c)||!ss.PushStack(a))
                    return 0;
            }
            if(!sf.PushStack(s[i++]))
                return 0;
        }
        else if(IsData(s[i])==1)
        {
            while(IsData(s[i])==1)
                s2+=s[i++];
            if(!ss.PushStack(string_double(s2)))
                return 0;
        }
        else if(s[i]=='S')
        {
            if(i>0&&!IsOperator1(s[i-1]))
                if(!sf.PushStack('*'))
                    return 0;
            s2="\0";
            for(j=0; j<4&&s[i]; j++,i++)
                s2+=s[i];
            if(s2!="Sqrt"||IsBracket(s[i])!=1)
                return 0;
            s2=GetBracketData(s,i);
            s1="\0";
            for(j=0; s2[j]; j++)
            {
                if(IsBracket(s2[j])==1)
                    s1+="("+GetBracketData(s2,j)+")";
                if(s2[j]==',')
                {
                    j++;
                    break;
                }
                else
                    s1+=s2[j];
            }
            if(!compute1(a,s1,angle))
                return 0;
            s1="\0";
            for(; s2[j]; j++)
                s1+=s2[j];
            if(!compute1(b,s1,angle)||!Sqrt(a,b)||!ss.PushStack(a))
                return 0;
        }
        else if(s[i]>='a'&&s[i]<='z'||s[i]=='L')
        {
            s1="\0";
            if(i>0&&!IsOperator1(s[i-1]))
                if(!sf.PushStack('*'))
                    return 0;
            while(s[i]>='a'&&s[i]<='z'||s[i]=='L'||s[i]=='^')
            {
                s1+=s[i++];
                if(s[i-1]=='e'&&s[i]!='^')
                    s1+='^';
            }
            if(s[i-1]=='e')
                s2="1";
            else if(IsBracket(s[i])==1)
                s2=GetBracketData(s,i);
            else if(IsData(s[i])==1)
            {
                while(s[i])
                {
                    if(IsData(s[i])==1)
                        s2+=s[i++];
                    else
                        break;
                }
            }
            else if(s[i]=='P'||s[i+1]=='i')
                s2="Pi";
            else if(s[i]=='S')
            {
                for(j=0; j<4&&s[i]; j++,i++)
                    s2+=s[i];
                if(s2!="Sqrt"||IsBracket(s[i])!=1)
                    return 0;
                s2+="("+GetBracketData(s,i)+")";
            }
            else
                return 0;
            if(!compute1(a,s2,angle)||!compute3(b,s1,a,angle)||!ss.PushStack(b))
                return 0;
        }
        else if(s[i]=='P')
        {
            if(i>0&&!IsOperator1(s[i-1])&&!sf.PushStack('*')||!ss.PushStack(P))
                return 0;
            i+=2;
        }
        else
            return 0;
    }
    while(sf.PopStack(c))
        if(!ss.PopStack(b)||!ss.PopStack(a)||!Account1(a,b,c)||!ss.PushStack(a))
            return 0;
    if(!ss.PopStack(a)||ss.State()>=0)
        return 0;
    return 1;
}
double kshell_tri_interp(vector<double> &x, vector<double> &y, vector<double> &z, vector<double> &data, double x0, double y1, double z1, int KK)
{
  //cout << "Entering kshel" << endl;
  int NI = 53;
  int NJ = 60;
  int NK = 65;
  double p[NI][NJ];
  double q[NI][NJ];
  double data1[NI][NJ];
  double d = 0.0;
  double p1,q1;

  for(int i = 0; i < NI; i++)
  {
    for(int j = 0; j < NJ; j++)
    {
      p[i][j] = x[shellIndex(i,j,KK)];
      q[i][j] = sqrt(pow(y[shellIndex(i,j,KK)],2.0)+pow(z[shellIndex(i,j,KK)],2.0));
      p1=x0;
      q1=sqrt(pow(y1,2.0)+pow(z1,2.0));
      data1[i][j] = data[shellIndex(i,j,KK)];
    }
  }

  //Find out which triangle is (p1.q1) in
  //search through (i,j) pairs, each cell is divided into two triangles
  // 1 (i,j) (i+1,j),(i,j+1)
  // 2 (i+1,j+1) (i+1,j), (i,j+1)

  double s1[2];
  double s2[2];
  double s3[2];
  double s4[2];
  double xx1,yy1,ff1,xx2,yy2,ff2,xx3,yy3,ff3;

  for(int i = 0; i < NI-1; i++)
  {
    for(int j = 0; j < NJ-1; j++)
    {
      s1[0] = p[i][j]-p1;
      s1[1] = q[i][j]-q1;
      s2[0] = p[i+1][j]-p1;
      s2[1] = q[i+1][j]-q1;
      s3[0] = p[i+1][j+1]-p1;
      s3[1] = q[i+1][j+1]-q1;
      s4[0] = p[i][j+1]-p1;
      s4[1] = q[i][j+1]-q1;

      //Triangle 1, ANG(12)+ANG(24)+ANG(41)=2*pi
      double theta12, theta24, theta41;
      theta12=acos((s1[0]*s2[0]+s1[1]*s2[1])/sqrt((pow(s1[0],2)+pow(s1[1],2))*(pow(s2[0],2)+pow(s2[1],2))));
      theta24=acos((s2[0]*s4[0]+s2[1]*s4[1])/sqrt((pow(s2[0],2)+pow(s2[1],2))*(pow(s4[0],2)+pow(s4[1],2))));
      theta41=acos((s4[0]*s1[0]+s4[1]*s1[1])/sqrt((pow(s4[0],2)+pow(s4[1],2))*(pow(s1[0],2)+pow(s1[1],2))));

      if(abs(theta12+theta24+theta41-2.0*PI) < 0.001)
      {
        xx1=p[i][j];
        yy1=q[i][j];
        ff1=data1[i][j];
        xx2=p[i+1][j];
        yy2=q[i+1][j];
        ff2=data1[i+1][j];
        xx3=p[i][j+1];
        yy3=q[i][j+1];
        ff3=data1[i][j+1];
        break;
      }

      //Triangle 2, ANG(23)+ANG(34)+ANG(42)=2*pi
      double theta23, theta34, theta42;
      theta23=acos((s2[0]*s3[0]+s2[1]*s3[1])/sqrt((pow(s2[0],2)+pow(s2[1],2))*(pow(s3[0],2)+pow(s3[1],2))));
      theta34=acos((s3[0]*s4[0]+s3[1]*s4[1])/sqrt((pow(s3[0],2)+pow(s3[1],2))*(pow(s4[0],2)+pow(s4[1],2))));
      theta42=acos((s4[0]*s2[0]+s4[1]*s2[1])/sqrt((pow(s4[0],2)+pow(s4[1],2))*(pow(s2[0],2)+pow(s2[1],2))));


      if(abs(theta23+theta34+theta42-2.0*PI) < 0.001)
      {
        xx1=p[i+1][j+1];
        yy1=q[i+1][j+1];
        ff1=data1[i+1][j+1];
        xx2=p[i+1][j];
        yy2=q[i+1][j];
        ff2=data1[i+1][j];
        xx3=p[i][j+1];
        yy3=q[i][j+1];
        ff3=data1[i][j+1];
        break;
      }

    }
  }

  Array2D< double > arr1(3,3);
  Array2D< double > arr2(3,3);
  Array2D< double > arr3(3,3);
  Array2D< double > arr(3,3);

  double temp[3][3] = { {xx1, yy1, 1},
                       {xx2, yy2, 1},
                       {xx3, yy3, 1}};
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      arr[i][j] = temp[i][j];
    }
  }

  double temp1[3][3] = { {p1, q1, 1},
                        {xx2, yy2, 1},
                        {xx3, yy3, 1}};
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      arr1[i][j] = temp1[i][j];
    }
  }

  double temp2[3][3] = { {p1, q1, 1},
                        {xx1, yy1, 1},
                        {xx3, yy3, 1}};
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      arr2[i][j] = temp2[i][j];
    }
  }

  double temp3[3][3] = { {p1, q1, 1},
                        {xx1, yy1, 1},
                        {xx2, yy2, 1}};
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      arr3[i][j] = temp3[i][j];
    }
  }

  JAMA::LU< double > compute(arr);
  JAMA::LU< double > compute1(arr1);
  JAMA::LU< double > compute2(arr2);
  JAMA::LU< double > compute3(arr3);

  d = (ff1*compute1.det() - ff2*compute2.det() + ff3*compute3.det())/compute.det();


  return d;


}