Exemplo n.º 1
0
 //! Put time into an ostream 
 static void duration_put(const time_duration_type& td, 
                          ostream_type& os)
 {
   if(td.is_special()) {
     os << td.get_rep(); 
   }
   else {
     charT fill_char = '0';
     if(td.is_negative()) {
       os << '-';
     }
     os  << std::setw(2) << std::setfill(fill_char) 
         << absolute_value(td.hours()) << ":";
     os  << std::setw(2) << std::setfill(fill_char) 
         << absolute_value(td.minutes()) << ":";
     os  << std::setw(2) << std::setfill(fill_char) 
         << absolute_value(td.seconds());
     fractional_seconds_type frac_sec = 
       absolute_value(td.fractional_seconds());
     if (frac_sec != 0) {
       os  << "." 
           << std::setw(time_duration_type::num_fractional_digits())
           << std::setfill(fill_char)
           << frac_sec;
     }
   } // else
 } // duration_put
Exemplo n.º 2
0
void print_absolute_value()
{
  long i = -1;
  float f = -1.0;
  short s = -1;
  std::cout << "absolute value of " << i << " is " << absolute_value(i) << std::endl;
  std::cout << "absolute value of " << f << " is " << absolute_value(f) << std::endl;
  std::cout << "absolute value of " << s << " is " << absolute_value(s) << std::endl;
}
Exemplo n.º 3
0
uint64_t platform_get_nanosecond_clock_value(void)
{
    uint64_t nanos;
    uint32_t cycles;
    uint32_t diff;
    cycles = DWT->CYCCNT;

    /* add values to the ns part of the time which can be divided by 12 */
    /* every time such value is added we will increment our clock by 125ns = 1/8 000000( cycle counter is running on the CPU frequency ),  */
    /* values will be 12, 24, 36, etc */
    diff = absolute_value((int)(cycles - prev_cycles));
    nsclock_nsec += ( diff / 12 ) * 125;

    /* when ns counter rolls over, add one second */
    if( nsclock_nsec >= 1000000000 )
    {
        nsclock_sec++;
        nsclock_nsec = nsclock_nsec - 1000000000;
    }
    prev_cycles = cycles - (diff % 3);

    nanos = nsclock_sec;
    nanos *= 1000000000;
    nanos += nsclock_nsec;
    return nanos;
}
Exemplo n.º 4
0
 void operator()(image_type& src)
 {
     typedef tipl::image<class image_type::value_type,image_type::dimension> image_buf_type;
     image_buf_type gx;
     gradient_2x(src,gx);
     absolute_value(gx.begin(),gx.end());
     gx.swap(src);
 }
Exemplo n.º 5
0
    //! Any negative argument results in a negative tick_count
    static tick_type to_tick_count(hour_type hours,
                                   min_type  minutes,
                                   sec_type  seconds,
                                   fractional_seconds_type  fs)
    {
      if (hours < 0 || minutes < 0 || seconds < 0 || fs < 0)
      {
        hours = absolute_value(hours);
        minutes = absolute_value(minutes);
        seconds = absolute_value(seconds);
        fs = absolute_value(fs);
        return (((((fractional_seconds_type(hours)*3600)
                   + (fractional_seconds_type(minutes)*60)
                   + seconds)*res_adjust()) + fs) * -1);
      }

      return (((fractional_seconds_type(hours)*3600)
               + (fractional_seconds_type(minutes)*60)
               + seconds)*res_adjust()) + fs;
    }
Exemplo n.º 6
0
//#############################################################################
// Calculates the dimensions (width, height, depth) of the model.
// Also returns the min/maxs of x, y, z of the model.
//#############################################################################
GLvoid Model::compute_dimensions (GLfloat& maxx, GLfloat&minx, 
								  GLfloat& maxy, GLfloat& miny, 
								  GLfloat& maxz, GLfloat& minz,
								  GLfloat& width, GLfloat& height, GLfloat& depth)
{
	GLuint i;
    
    // get the max/mins 
    maxx = minx = m_vertices[3 + 0];
    maxy = miny = m_vertices[3 + 1];
    maxz = minz = m_vertices[3 + 2];
    for (i = 1; i <= m_numvertices; i++) {
        if (maxx < m_vertices[3 * i + 0])
            maxx = m_vertices[3 * i + 0];
        if (minx > m_vertices[3 * i + 0])
            minx = m_vertices[3 * i + 0];
        
        if (maxy < m_vertices[3 * i + 1])
            maxy = m_vertices[3 * i + 1];
        if (miny > m_vertices[3 * i + 1])
            miny = m_vertices[3 * i + 1];
        
        if (maxz < m_vertices[3 * i + 2])
            maxz = m_vertices[3 * i + 2];
        if (minz > m_vertices[3 * i + 2])
            minz = m_vertices[3 * i + 2];
    }
    
    // calculate model width, height, and depth 
    width = absolute_value(maxx) + absolute_value(minx);
    height = absolute_value(maxy) + absolute_value(miny);
    depth = absolute_value(maxz) + absolute_value(minz);
}
Exemplo n.º 7
0
void Computation::checkLegSwing(double velocity[3], Bone * bone, int skelNum) {

	//TODO find presentation that shows whether the leg swings were detected correctly
	if(strcmp(bone->name, "lfoot") == 0) {
		//TODO printf("%f, %f, % f\n",velocity[0], velocity[1], velocity[2] );
		if (absolute_value(velocity[2] < 0.0037) ) left = false;
			else left = true;

		//printf("\nleft, %f, %f, %f, ",velocity[0], velocity[1], velocity[2]);


	} else if(strcmp(bone->name, "rfoot") == 0) {
		//TODO printf("%f, %f, % f\n",velocity[0], velocity[1], velocity[2] );
		if(absolute_value(velocity[2]) < 0.0037) right = false;
			else right = true;

		//printf("right, %f, %f, %f, ", velocity[0], velocity[1], velocity[2]);

	}
	//if (left) printf("left");
	//if(right) printf("right");
}
Exemplo n.º 8
0
//#############################################################################
// Generates texture coordinates according to a
// linear projection of the texture map.  It generates these by
// linearly mapping the vertices onto a square.
//#############################################################################
GLvoid Model::linear_texture()
{
	Group *group;
    GLfloat dimensions[3];
    GLfloat x, y, scalefactor;
    GLuint i;
    
    if (m_texcoords) delete [] m_texcoords;
    m_numtexcoords = m_numvertices;
    m_texcoords= new GLfloat [2*(m_numtexcoords+1)];
    
	GLfloat a, b, c, d, e, f;
    compute_dimensions(a, b, c, d, e, f,
		               dimensions[0], dimensions[1], dimensions[2]);

    scalefactor = 2.0 / absolute_value(maximum_value(maximum_value(dimensions[0], dimensions[1]), dimensions[2]));
    
    // do the calculations 
    for(i = 1; i <= m_numvertices; i++) {
        x = m_vertices[3 * i + 0] * scalefactor;
        y = m_vertices[3 * i + 2] * scalefactor;
        m_texcoords[2 * i + 0] = (x + 1.0) / 2.0;
        m_texcoords[2 * i + 1] = (y + 1.0) / 2.0;
    }
    
    // go through and put texture coordinate indices in all the triangles 
    group = m_groups;
    while(group) 
	{
        for(i = 0; i < group->numtriangles; i++) 
		{
            m_triangles[group->triangles[i]].set_tindex(0,m_triangles[group->triangles[i]].inq_vindex(0));
            m_triangles[group->triangles[i]].set_tindex(1,m_triangles[group->triangles[i]].inq_vindex(1));
            m_triangles[group->triangles[i]].set_tindex(2,m_triangles[group->triangles[i]].inq_vindex(2));
        }    
        group = group->next;
    }
}
Exemplo n.º 9
0
string cardinal(int x) {
    string tmp;
    int a;

    if(!x) return "zero";
    if(x < 0) {
        tmp = "negative ";
        x = absolute_value(x);
    }
    else tmp = "";
    switch(x) {
        case 1: return tmp+"one";
        case 2: return tmp+"two";
        case 3: return tmp+"three";
        case 4: return tmp+"four";
        case 5: return tmp+"five";
        case 6: return tmp+"six";
        case 7: return tmp+"seven";
        case 8: return tmp+"eight";
        case 9: return tmp+"nine";
        case 10: return tmp+"ten";
        case 11: return tmp+"eleven";
        case 12: return tmp+"twelve";
        case 13: return tmp+"thirteen";
        case 14: return tmp+"fourteen";
        case 15: return tmp+"fifteen";
        case 16: return tmp+"sixteen";
        case 17: return tmp+"seventeen";
        case 18: return tmp+"eighteen";
        case 19: return tmp+"nineteen";
        case 20: return tmp+"twenty";
        default:
            if(x > 1000000000) return "over a billion";
            else if(a = x /1000000) {
                if(x = x %1000000)
                  return sprintf("%s million %s", cardinal(a),cardinal(x));
                else return sprintf("%s million", cardinal(a));
            }
            else if(a = x / 1000) {
                if(x = x % 1000)
                  return sprintf("%s thousand %s", cardinal(a),cardinal(x));
                else return sprintf("%s thousand", cardinal(a));
            }
            else if(a = x / 100) {
                if(x = x % 100)
                  return sprintf("%s hundred %s", cardinal(a),cardinal(x));
                else return sprintf("%s hundred", cardinal(a));
            }
            else {
                a = x / 10;
                if(x = x % 10) tmp = "-"+cardinal(x);
                else tmp = "";
                switch(a) {
                    case 2: return "twenty"+tmp;
                    case 3: return "thirty"+tmp;
                    case 4: return "forty"+tmp;
                    case 5: return "fifty"+tmp;
                    case 6: return "sixty"+tmp;
                    case 7: return "seventy"+tmp;
                    case 8: return "eighty"+tmp;
                    case 9: return "ninety"+tmp;
                    default: return "error";
                }
            }
    }
}
Exemplo n.º 10
0
void
testcase(gchar *msg,
         gint parse_flags,
         gchar *bad_hostname_re,
         gint expected_pri,
         unsigned long expected_stamp_sec,
         unsigned long expected_stamp_usec,
         unsigned long expected_stamp_ofs,
         const gchar *expected_host,
         const gchar *expected_program,
         const gchar *expected_msg,
         const gchar *expected_sd_str,
         const gchar *expected_pid,
         const gchar *expected_msgid,
         const gchar *expected_sd_pairs[][2])
{
  LogMessage *parsed_message;
  LogStamp *parsed_timestamp;
  time_t now;
  GString *sd_str;

  testcase_begin("Testing log message parsing; parse_flags='%x', bad_hostname_re='%s', msg='%s'",
                 parse_flags, bad_hostname_re ? : "(null)", msg);

  parsed_message = parse_log_message(msg, parse_flags, bad_hostname_re);
  parsed_timestamp = &(parsed_message->timestamps[LM_TS_STAMP]);

  if (expected_stamp_sec)
    {
      if (expected_stamp_sec != 1)
        assert_guint(parsed_timestamp->tv_sec, expected_stamp_sec, "Unexpected timestamp");
      assert_guint32(parsed_timestamp->tv_usec, expected_stamp_usec, "Unexpected microseconds");
      assert_guint32(parsed_timestamp->zone_offset, expected_stamp_ofs, "Unexpected timezone offset");
    }
  else
    {
      time(&now);
      assert_true(absolute_value(parsed_timestamp->tv_sec - now) <= 5,
                  "Expected parsed message timestamp to be set to now; now='%d', timestamp->tv_sec='%d'",
                  (gint)now, (gint)parsed_timestamp->tv_sec, NULL);
    }
  assert_guint16(parsed_message->pri, expected_pri, "Unexpected message priority");
  assert_log_message_value(parsed_message, LM_V_HOST, expected_host);
  assert_log_message_value(parsed_message, LM_V_PROGRAM, expected_program);
  assert_log_message_value(parsed_message, LM_V_MESSAGE, expected_msg);
  if (expected_pid)
    assert_log_message_value(parsed_message, LM_V_PID, expected_pid);
  if (expected_msgid)
    assert_log_message_value(parsed_message, LM_V_MSGID, expected_msgid);
  if (expected_sd_str)
    {
      sd_str = g_string_sized_new(0);
      log_msg_format_sdata(parsed_message, sd_str, 0);
      assert_string(sd_str->str, expected_sd_str, "Unexpected formatted SData");
      g_string_free(sd_str, TRUE);
    }

  assert_log_message_sdata_pairs(parsed_message, expected_sd_pairs);

  log_msg_unref(parsed_message);

  testcase_end();
}
Exemplo n.º 11
0
//Computes the angular momentum about the general center of mass
void Computation::computeAngularMomentum() {

	double translation[3], rotation[3];
	double R[4][4],Rx[4][4],Ry[4][4],Rz[4][4];
	double mean_w[3];

	Bone * root;
	Mass * mass;



	if(m_pSkeletonList != NULL)
	{

		for (int i = 0; i < numOfSkeletons && i < MAX_SKELS; i++)
		{
			double transform[4][4];
			identity(transform);

			double r_i_cm[m_pSkeletonList[i]->NUM_BONES_IN_ASF_FILE][3]; //stores previous position of local center of mass in global cs

			root = m_pSkeletonList[i]->getRoot();

			if(m_pMassDistributionList[i] != NULL) {

				//reset angular momentum
				m_pSkeletonList[i]->H[0] = 0.;
				m_pSkeletonList[i]->H[1] = 0.;
				m_pSkeletonList[i]->H[2] = 0.;


				//store old local cm in global cs of each bone:

				for( int k = 0; k < m_pSkeletonList[i]->NUM_BONES_IN_ASF_FILE; k++)
				{
					//store previous position of local cm in global cs in r_i_cm
					r_i_cm[k][0] = m_pSkeletonList[i]->getBone(root, k)->r_i[0];
					r_i_cm[k][1] = m_pSkeletonList[i]->getBone(root, k)->r_i[1];
					r_i_cm[k][2] = m_pSkeletonList[i]->getBone(root, k)->r_i[2];
				}

				//compute current position of lcm in global cs

					m_pSkeletonList[i]->GetTranslation(translation);
					m_pSkeletonList[i]->GetRotationAngle(rotation);

					//creating Rotation matrix for initial rotation of Skeleton
					rotationX(Rx, rotation[0]);
					rotationY(Ry, rotation[1]);
					rotationZ(Rz, rotation[2]);

					matrix4_mult(Rz, Ry, R);
					matrix4_mult(R, Rx, R);

					matrix4_mult(transform, R, transform);

					transform[0][3] += (MOCAP_SCALE*translation [0]);
					transform[1][3] += (MOCAP_SCALE*translation [1]);
					transform[2][3] += (MOCAP_SCALE*translation [2]);

					traverse(root, i, transform, 'h');

					//TODO delete

					mean_w[0] = 0;
					mean_w[1] = 0;
					mean_w[2] = 0;



					for(int j = 0; j < m_pSkeletonList[i]->NUM_BONES_IN_ASF_FILE; j++) { //for every bone compute: (r_i - r_cm) x m_i(v_i - v_cm) + I_i*w_i

						double rel_pos[3], v_i[3], v_cm[3], v_rel[3], I_G[3][3], w_i[3], local_inertia[3], cross[3], S[3][3], S_transpose[3][3];

						Bone * bone;
						bone = m_pSkeletonList[i]->getBone(root, j);

						if(m_pMassDistributionList[i]->getMass(bone->name) != NULL) {

							mass = m_pMassDistributionList[i]->getMass(bone->name);

							//rel_pos = r_i - r_cm
							rel_pos[0] = bone->r_i[0] - m_pSkeletonList[i]->cm[0];
							rel_pos[1] = bone->r_i[1] - m_pSkeletonList[i]->cm[1];
							rel_pos[2] = bone->r_i[2] - m_pSkeletonList[i]->cm[2];

							//v_i = r_i - r_i_cm
							v_i[0] = (bone->r_i[0] - r_i_cm[j][0]);
							v_i[1] = (bone->r_i[1] - r_i_cm[j][1]);
							v_i[2] = (bone->r_i[2] - r_i_cm[j][2]);

							//if v_i is zero switch flag
							checkLegSwing(v_i, bone, i);

						//	if(mass->mass != 0 && ((strcmp(mass->segName, "rfoot") == 0) || (strcmp(mass->segName, "lfoot") == 0))) printf("v_i_%s: %f %f %f\n",mass->segName, v_i[0], v_i[1], v_i[2]);

							//v_cm = r_cm - r_cm_prev
							v_cm[0] = (m_pSkeletonList[i]->cm[0] - m_pSkeletonList[i]->cm_prev[0]);
							v_cm[1] = (m_pSkeletonList[i]->cm[1] - m_pSkeletonList[i]->cm_prev[1]);
							v_cm[2] = (m_pSkeletonList[i]->cm[2] - m_pSkeletonList[i]->cm_prev[2]);


							//v_rel = v_i - v_cm
							v_rel[0] = v_i[0] - v_cm[0];
							v_rel[1] = v_i[1] - v_cm[1];
							v_rel[2] = v_i[2] - v_cm[2];


							//Inertia tensor

								double Ri[4][4], Ri_transpose[4][4], I_i[4][4];

								//rotation from global to local
								rotationX(Rx, -bone->axis_x);
								rotationY(Ry, -bone->axis_y);
								rotationZ(Rz, -bone->axis_z);

								matrix4_mult(Rz, Ry, Ri);
								matrix4_mult(Ri, Rx, Ri);

								matrix4_transpose(Ri, Ri_transpose);

								I_i[0][0] = mass->Ixx;
								I_i[0][1] = I_i[1][0] =(-1)*mass->Ixy;
								I_i[0][2] = I_i[2][0] = (-1)*mass->Ixz;
								I_i[1][1] = mass->Iyy;
								I_i[1][2] = I_i[2][1] = (-1)*mass->Iyz;
								I_i[2][2] = mass->Izz;
								I_i[0][3] = I_i[1][3] = I_i[2][3] = 0;
								I_i[3][0] = I_i[3][1] = I_i[3][2] = 0;
								I_i[3][3] = 1.0;

								//~I_G = R_i^T * I_i * R_i
								//~I_G is inertia tensor relative to bone's cm in rotation of global cs.

								matrix4_mult(Ri_transpose, I_i, I_i);
								matrix4_mult(I_i, Ri, I_i);

								//parallel axes theorem
								// I_G = I_i + m_i * S^T(rel_pos)* S(rel_pos) with S is skew matrix for cross product

								cross_matrix(rel_pos, S); //works

								matrix3_transpose(S, S_transpose);//works
								matrix3_mult(S_transpose, S, S); //works


								matrix3_scalar_mult(S, mass->mass); //works

								//copy entries into I_G
								identity3(I_G);

								for (int x = 0; x < 3; x++)
									for (int y = 0; y < 3; y++)
										I_G[x][y] = I_i[x][y] + S[x][y];


								//w_i = R_i^T * ({rx,ry,rz} - {rx_prev, ry_prev, rz_prev});

								w_i[0] = (bone->rx - bone->rx_prev);
								w_i[1] = (bone->ry - bone->ry_prev);
								w_i[2] = (bone->rz - bone->rz_prev);

								//clamping

								if(absolute_value(w_i[0]) > 1.5) w_i[0] = 0;
								if(absolute_value(w_i[1]) > 1.5) w_i[1] = 0;
								if(absolute_value(w_i[2]) > 1.5) w_i[2] = 0;

								mean_w[0] += absolute_value(w_i[0]);
								mean_w[1] += absolute_value(w_i[1]);
								mean_w[2] += absolute_value(w_i[2]);





								vector_rotationXYZ(w_i, bone->axis_x, bone->axis_y, bone->axis_z);

								//local_inertia = I_i*w_i
								matrix3_v3_mult(I_G,w_i, local_inertia);


							//cross = (r_i - r_cm) x m_i(v_i - v_cm)
							v_rel[0] *= m_pMassDistributionList[i]->getMass(bone->name)->mass;
							v_rel[1] *= m_pMassDistributionList[i]->getMass(bone->name)->mass;
							v_rel[2] *= m_pMassDistributionList[i]->getMass(bone->name)->mass;


							v3_cross(rel_pos, v_rel, cross);


							//H is sum of angular momentum of every bone
							m_pSkeletonList[i]->H[0] += (cross[0] + local_inertia[0]);
							m_pSkeletonList[i]->H[1] += (cross[1] + local_inertia[1]);
							m_pSkeletonList[i]->H[2] += (cross[2] + local_inertia[2]);





						} //if end
					}//for bones end

					setLegSwing(i);

					mean_w[0] /= m_pSkeletonList[i]->NUM_BONES_IN_ASF_FILE;
					mean_w[1] /= m_pSkeletonList[i]->NUM_BONES_IN_ASF_FILE;
					mean_w[2] /= m_pSkeletonList[i]->NUM_BONES_IN_ASF_FILE;

					//normalization N=M*H*V
					// to make H dimensionless, divide by subject's height (in m), subject's mass (in kg) and subject's average velocity(0.012 m/frame or 1.44 m/s)
					double n = m_pSkeletonList[i]->totalMass*m_pSkeletonList[i]->height*(1.44);

					m_pSkeletonList[i]->H[0] /= n;
					m_pSkeletonList[i]->H[1] /= n;
					m_pSkeletonList[i]->H[2] /= n;

					//printf("mean w values: %f %f %f\n", mean_w[0], mean_w[1], mean_w[2]);
					//printf("angular momentum: %f %f %f\n", m_pSkeletonList[i]->H[0],m_pSkeletonList[i]->H[1],m_pSkeletonList[i]->H[2]);
					//printf("position cm: %f %f %f\n", m_pSkeletonList[i]->cm[0], m_pSkeletonList[i]->cm[1], m_pSkeletonList[i]->cm[2]);

			}//if end

		}// for Skeletons end
	}
}
Exemplo n.º 12
0
  void solve_bicgstab(const MatrixExpression &A, 
	       const PreconditionerExpression &preconditioner, 
	       VectorTypeX &result,
	       const VectorExpressionB &b, double tol, unsigned max_iterations, 
	       unsigned *iteration_count = NULL, unsigned debug_level = 0)
  {
    typedef 
      VectorTypeX
      vector_t;
    typedef 
      typename vector_t::value_type
      v_t;

    typedef 
      typename decomplexify<v_t>::type
      real_t;

    if (A().size1() != A().size2())
      throw std::runtime_error("bicgstab: A is not quadratic");

    if (debug_level >= 2)
      std::cout << "rhs:" << b << std::endl;

    // typed up from Figure 2.10 of 
    // Templates for the Solution of Linear Systems: 
    // Building Blocks for Iterative Methods
    // (R. Barrett, M. Berry, T. F. Chan, et al.)

    unsigned iterations = 0;

    // "next" refers to i
    // "" refers to i-1
    // "last" refers to i-2

    v_t rho, last_rho, alpha, omega;
    vector_t p, v, x(result);

    vector_t r(b-prod(A,x));
    vector_t r_tilde(r);
    real_t initial_residual = norm_2(r);

    // silence "used uninitialized" warnings
    last_rho = 0;
    alpha = 0;

    while (iterations < max_iterations)
    {
      rho = inner_prod(conj(r_tilde), r);
      if (absolute_value(rho) == 0)
	throw std::runtime_error("bicgstab failed, rho == 0");
      if (iterations == 0)
	{
	  p = r;
	}
      else
	{
	  v_t beta = (rho/last_rho)*(alpha/omega);
	  p = r + beta*(p-omega*v);
	}

      vector_t p_hat = prod(preconditioner, p);
      v = prod(A, p_hat);
      alpha = rho/inner_prod(conj(r_tilde), v);
      vector_t s = r - alpha*v;

      {
        real_t norm_s = norm_2(s);
        if (norm_s < tol * initial_residual)
          {
            x += alpha*p_hat;
            break;
          }
      }

      vector_t s_hat = prod(preconditioner, s);
      vector_t t = prod(A, s_hat);
      omega = inner_prod(conj(t), s)/inner_prod(conj(t), t);
      x += alpha * p_hat + omega * s_hat;
      r = s - omega * t;

      {
        real_t norm_r = norm_2(r);
        if (norm_r < tol * initial_residual)
          break;
      }

      if (absolute_value(omega) == 0)
        throw std::runtime_error("bicgstab failed, omega == 0");

      last_rho = rho;

      if (debug_level)
        {
          if (debug_level >= 2 || iterations % 10 == 0)
            std::cout << double(norm_2(r)) << std::endl;
        }
      iterations++;
    }

    result = x;

    if ( iterations == max_iterations)
      throw std::runtime_error("bicgstab failed to converge");

    if (iteration_count)
      *iteration_count = iterations;
  }
Exemplo n.º 13
0
int main(int argc, char** argv)
{
  if (argc < 5) {
    std::cout << "Usage: patt_rec [data_matrix.txt] [pattern_matrix.txt] [mode 0: serial, 1: parallel] [number of threads]" << std::endl;
    return 1;
  }

  int data_n_rows, data_n_cols;

  std::ifstream data_file(argv[1]);
  if (!data_file) error_exit("Data file not found!");
  data_file >> data_n_rows >> data_n_cols;

  int data[data_n_rows][data_n_cols];

  for (int i = 0; i < data_n_rows; ++i)
  {
    for (int j = 0; j < data_n_cols; ++j)
    {
      data_file >> data[i][j];
    }
  }

  int pattern_n_rows, pattern_n_cols;

  std::ifstream pattern_file(argv[2]);
  if (!pattern_file) error_exit("Pattern file not found");
  pattern_file >> pattern_n_rows >> pattern_n_cols;

  int pattern[pattern_n_rows][pattern_n_cols];

  std::vector<int> pattern_elements;

  for (int i = 0; i < pattern_n_rows; ++i)
  {
    for (int j = 0; j < pattern_n_cols; ++j)
    {
      pattern_file >> pattern[i][j];
      pattern_elements.push_back(pattern[i][j]);
    }
  }

  std::nth_element(pattern_elements.begin(),
                   pattern_elements.begin() + pattern_elements.size()/2,
                   pattern_elements.end());
  const int median_pattern = pattern_elements[pattern_elements.size()/2];


  std::vector<std::tuple<int, int, double>> matches;

  double size_of_pattern_matrix = (double) pattern_n_cols * pattern_n_rows; //Evil C way.

  bool is_parallel {atoi(argv[3]) == 1}; //Absolutly horribly... but works. Should be checked with a stream.

  double time_start = omp_get_wtime();
  int num_of_threads = atoi(argv[4]);
  int chunk_size = data_n_rows / (num_of_threads * 10);
  #pragma omp parallel for num_threads(num_of_threads) if(is_parallel) schedule(guided, chunk_size)
  for (int i = 0; i < data_n_rows - pattern_n_rows; ++i) {
    std::cout << omp_get_thread_num() << std::endl;
    for (int j = 0; j < data_n_cols - pattern_n_cols; ++j) {
      double current_goodness = 0;
      std::vector<int>submatrix_elements;

      for (int m_i = 0; m_i < pattern_n_rows; ++m_i) {
        for (int m_j = 0; m_j < pattern_n_cols; ++m_j) {
          int diff = absolute_value(data[i+m_i][j+m_j] - pattern[m_i][m_j]);
          current_goodness += (double)diff;
          submatrix_elements.push_back(data[i+m_i][j+m_j]);
          if (diff > 9)
            goto BREAK_OUUUUUUUT;
        }
      }

      std::nth_element(submatrix_elements.begin(),
                       submatrix_elements.begin() + submatrix_elements.size()/2,
                       submatrix_elements.end());

      if (absolute_value(submatrix_elements[submatrix_elements.size()/2] - median_pattern) > 2)
        goto BREAK_OUUUUUUUT;

      current_goodness /= size_of_pattern_matrix;

      #pragma omp critical
      matches.push_back(std::make_tuple(i, j, current_goodness));


BREAK_OUUUUUUUT : ;
    }
  }

  double time_end = omp_get_wtime();

  std::cout << "Took " << (time_end - time_start) << " seconds" << std::endl;

  std::cout << "Matches (row, col, goodness)" << std::endl;
  double min_goodness {std::numeric_limits<double>::max()}, max_goodness {std::numeric_limits<double>::min()}, average_goodness {0};
  for (auto p : matches) {
    std::cout << "(" << std::get<0>(p) << ", " << std::get<1>(p) << ", " << std::get<2>(p) << ")" << std::endl;
    double current_goodness = std::get<2>(p);
    if (current_goodness < min_goodness) min_goodness = current_goodness;
    if (current_goodness > max_goodness) max_goodness = current_goodness;
    average_goodness += current_goodness;
  }

  std::cout << "Min goodness: " << min_goodness << std::endl
            << "Max goodness: " << max_goodness << std::endl
            << "Average goodness: " << average_goodness / matches.size() << std::endl;

  return 0;
}
Exemplo n.º 14
0
/* The benchmarking program */
int main (int argc, char **argv)
{
  printf ("Description:\t%s\n\n", dgemm_desc);

  /* Test sizes should highlight performance dips at multiples of certain powers-of-two */

  int test_sizes[] = 

  /* Multiples-of-32, +/- 1. Currently commented. */
   {31,32,33,63,64,65,95,96,97,127,128,129,159,160,161,191,192,193,223,224,225,255,256,257,287,288,289,319,320,321,351,352,353,383,384,385,415,416,417,447,448,449,479,480,481,511,512,513,543,544,545,575,576,577,607,608,609,639,640,641,671,672,673,703,704,705,735,736,737,767,768,769,799,800,801,831,832,833,863,864,865,895,896,897,927,928,929,959,960,961,991,992,993,1023,1024,1025}; 

  /* A representative subset of the first list. Currently uncommented. */ 
  //{ 31, 32, 96, 97, 127, 128, 129, 191, 192, 229, 255, 256, 257,
  //  319, 320, 321, 417, 479, 480, 511, 512, 639, 640, 767, 768, 769 };

  int nsizes = sizeof(test_sizes)/sizeof(test_sizes[0]);

  /* assume last size is also the largest size */
  int nmax = test_sizes[nsizes-1];

  /* allocate memory for all problems */
  double* buf = NULL;
  buf = (double*) malloc (3 * nmax * nmax * sizeof(double));
  if (buf == NULL) die ("failed to allocate largest problem size");

  double Mflops_s[nsizes],per[nsizes],aveper;

  /* For each test size */
  for (int isize = 0; isize < sizeof(test_sizes)/sizeof(test_sizes[0]); ++isize) {
    for( int block_size = 3;block_size<200;block_size++) {
    /* Create and fill 3 random matrices A,B,C*/
        int n = test_sizes[isize];

        double* A = buf + 0;
        double* B = A + nmax*nmax;
        double* C = B + nmax*nmax;

        fill (A, n*n);
        fill (B, n*n);
        fill (C, n*n);

        /* Measure performance (in Gflops/s). */

        /* Time a "sufficiently long" sequence of calls to reduce noise */
        double Gflops_s, seconds = -1.0;
        double timeout = 0.1; // "sufficiently long" := at least 1/10 second.
        for (int n_iterations = 1; seconds < timeout; n_iterations *= 2) {
        /* Warm-up */
        square_dgemm (block_size,n, A, B, C);

        /* Benchmark n_iterations runs of square_dgemm */
        seconds = -wall_time();
        for (int it = 0; it < n_iterations; ++it)
	       square_dgemm (block_size,n, A, B, C);
        seconds += wall_time();

        /*  compute Gflop/s rate */
        Gflops_s = 2.e-9 * n_iterations * n * n * n / seconds;
    }
  
    /* Storing Mflop rate and calculating percentage of peak */
    Mflops_s[isize] = Gflops_s*1000;
    per[isize] = Gflops_s*100/MAX_SPEED;

    printf ("Size: %d\t Block Size: %d\t Mflop/s: %8g\tPercentage:%6.2lf\n", n, block_size,Mflops_s[isize],per[isize]);

    /* Ensure that error does not exceed the theoretical error bound. */

    /* C := A * B, computed with square_dgemm */
    memset (C, 0, n * n * sizeof(double));
    square_dgemm (block_size,n, A, B, C);

    /* Do not explicitly check that A and B were unmodified on square_dgemm exit
     *  - if they were, the following will most likely detect it:   
     * C := C - A * B, computed with reference_dgemm */
    reference_dgemm(n, -1., A, B, C);

    /* A := |A|, B := |B|, C := |C| */
    absolute_value (A, n * n);
    absolute_value (B, n * n);
    absolute_value (C, n * n);

    /* C := |C| - 3 * e_mach * n * |A| * |B|, computed with reference_dgemm */ 
    reference_dgemm (n, -3.*DBL_EPSILON*n, A, B, C);

    /* If any element in C is positive, then something went wrong in square_dgemm */
    for (int i = 0; i < n * n; ++i)
      if (C[i] > 0)
	die("*** FAILURE *** Error in matrix multiply exceeds componentwise error bounds.\n" );

  }

  }

  free (buf);

  return 0;
}
Exemplo n.º 15
0
int main( int argc, char **argv )
{
    printf ("Description:\t%s\n\n", dgemm_desc);

    /* These sizes should highlight performance dips at multiples of certain powers-of-two */
    int test_sizes[] = {
        31, 32, 96, 97, 127, 128, 129, 191, 192, 229, 255, 256, 257,
        319, 320, 321, 417, 479, 480, 511, 512, 639, 640, 767, 768, 769,
    };
 
	/*For each test size*/
    for( int isize = 0; isize < sizeof(test_sizes)/sizeof(test_sizes[0]); isize++ )
    {
		/*Craete and fill 3 random matrices A,B,C*/
        int n = test_sizes[isize];

        double *A = (double*) malloc( n * n * sizeof(double) );
        double *B = (double*) malloc( n * n * sizeof(double) );
        double *C = (double*) malloc( n * n * sizeof(double) );

        fill( A, n * n );
        fill( B, n * n );
        fill( C, n * n );
        
        /*  measure Mflop/s rate; time a sufficiently long sequence of calls to eliminate noise*/
        double Mflop_s, seconds = -1.0;
        for( int n_iterations = 1; seconds < 0.1; n_iterations *= 2 ) 
        {
            /* warm-up */
            square_dgemm( n, A, B, C );
            
            /*  measure time */
            seconds = read_timer( );
            for( int i = 0; i < n_iterations; i++ )
                square_dgemm( n, A, B, C );
            seconds = read_timer( ) - seconds;
           
            /*  compute Mflop/s rate */
            Mflop_s = 2e-6 * n_iterations * n * n * n / seconds;
        }
        printf ("Size: %d\tMflop/s: %g\n", n, Mflop_s);
        
        /*  Ensure that error does not exceed the theoretical error bound */
		
		/* Set initial C to 0 and do matrix multiply of A*B */
        memset( C, 0, sizeof( double ) * n * n );
        square_dgemm( n, A, B, C );
		/*Subtract A*B from C using standard dgemm (note that this should be 0 to within machine roundoff)*/
        dgemm( 'N','N', n,n,n, -1, A,n, B,n, 1, C,n );
		/*Subtract the maximum allowed roundoff from each element of C*/
        absolute_value( A, n * n );
        absolute_value( B, n * n );
        absolute_value( C, n * n );
        dgemm( 'N','N', n,n,n, -3.0*DBL_EPSILON*n, A,n, B,n, 1, C,n );
		/*After this test if any element in C is still positive something went wrong in square_dgemm*/
        for( int i = 0; i < n * n; i++ )
            if( C[i] > 0 )
            {
                printf( "FAILURE: error in matrix multiply exceeds an acceptable margin\n" );
                exit(-1);
            }

		/*Deallocate memory*/
        free( C );
        free( B );
        free( A );
    }
    
    return 0;
}
Exemplo n.º 16
0
 //! Returns count of fractional seconds at given resolution
 fractional_seconds_type fractional_seconds() const
 {
   return absolute_value((ticks()%rep_type::res_adjust()));
 }
Exemplo n.º 17
0
 //! Returns normalized number of seconds
 sec_type seconds() const
 {
   return absolute_value((ticks()/rep_type::res_adjust()) % 60);
 }
Exemplo n.º 18
0
 //! Returns normalized number of minutes
 min_type minutes() const
 {
   return absolute_value(((ticks() / (60*rep_type::res_adjust())) % 60));
 }
Exemplo n.º 19
0
int
testcase(gchar *msg,
         gint parse_flags, /* LP_NEW_PROTOCOL */
         gchar *bad_hostname_re,
         gint expected_pri,
         guint expected_version,
         unsigned long expected_stamps_sec,
         unsigned long expected_stamps_usec,
         unsigned long expected_stamps_ofs,
         const gchar *expected_host,
         const gchar *expected_msg,
         const gchar *expected_program,
         const gchar *expected_sd_str,
         const gchar *expected_process_id,
         const gchar *expected_message_id
         )
{
  LogMessage *logmsg, *cloned;
  time_t now;
  regex_t bad_hostname;
  GSockAddr *addr = g_sockaddr_inet_new("10.10.10.10", 1010);
  gchar logmsg_addr[256], cloned_addr[256];
  LogPathOptions path_options = LOG_PATH_OPTIONS_INIT;
  GString *sd_str = g_string_sized_new(0);

  if (bad_hostname_re)
    TEST_ASSERT(regcomp(&bad_hostname, bad_hostname_re, REG_NOSUB | REG_EXTENDED) == 0, "%d", 0, 0);

  parse_options.flags = parse_flags;
  parse_options.bad_hostname = &bad_hostname;
  logmsg = log_msg_new(msg, strlen(msg), addr, &parse_options);
  TEST_ASSERT(logmsg->pri == expected_pri, "%d", logmsg->pri, expected_pri);
  if (expected_stamps_sec)
    {
      if (expected_stamps_sec != 1)
        {
            TEST_ASSERT(logmsg->timestamps[LM_TS_STAMP].time.tv_sec == expected_stamps_sec, "%d", (int) logmsg->timestamps[LM_TS_STAMP].time.tv_sec, (int) expected_stamps_sec);
          }
        TEST_ASSERT(logmsg->timestamps[LM_TS_STAMP].time.tv_usec == expected_stamps_usec, "%d", (int) logmsg->timestamps[LM_TS_STAMP].time.tv_usec, (int) expected_stamps_usec);
        TEST_ASSERT(logmsg->timestamps[LM_TS_STAMP].zone_offset == expected_stamps_ofs, "%d", (int) logmsg->timestamps[LM_TS_STAMP].zone_offset, (int) expected_stamps_ofs);
    }
  else
    {
      time(&now);
      TEST_ASSERT(absolute_value(logmsg->timestamps[LM_TS_STAMP].time.tv_sec - now) < 1, "%d", 0, 0);
    }
  TEST_ASSERT(strcmp(log_msg_get_value(logmsg, LM_V_HOST, NULL), expected_host) == 0, "%s", log_msg_get_value(logmsg, LM_V_HOST, NULL), expected_host);
  TEST_ASSERT(strcmp(log_msg_get_value(logmsg, LM_V_PROGRAM, NULL), expected_program) == 0, "%s", log_msg_get_value(logmsg, LM_V_PROGRAM, NULL), expected_program);
  TEST_ASSERT(strcmp(log_msg_get_value(logmsg, LM_V_MESSAGE, NULL), expected_msg) == 0, "%s", log_msg_get_value(logmsg, LM_V_MESSAGE, NULL), expected_msg);
  TEST_ASSERT(strcmp(log_msg_get_value(logmsg, LM_V_PID, NULL), expected_process_id) == 0, "%s", log_msg_get_value(logmsg, LM_V_PID, NULL), expected_process_id);
  TEST_ASSERT(strcmp(log_msg_get_value(logmsg, LM_V_MSGID, NULL), expected_message_id) == 0, "%s", log_msg_get_value(logmsg, LM_V_MSGID, NULL), expected_message_id);

  /* SD elements */
  log_msg_format_sdata(logmsg, sd_str);
  TEST_ASSERT(strcmp(sd_str->str, expected_sd_str) == 0, "%s", sd_str->str, expected_sd_str);

  /* check if the sockaddr matches */
  g_sockaddr_format(logmsg->saddr, logmsg_addr, sizeof(logmsg_addr), GSA_FULL);

  path_options.flow_control = FALSE;
  cloned = log_msg_clone_cow(logmsg, &path_options);

  g_sockaddr_format(cloned->saddr, cloned_addr, sizeof(cloned_addr), GSA_FULL);
  TEST_ASSERT(strcmp(logmsg_addr, cloned_addr) == 0, "%s", cloned_addr, logmsg_addr);

  TEST_ASSERT(logmsg->pri == cloned->pri, "%d", logmsg->pri, cloned->pri);
  TEST_ASSERT(logmsg->timestamps[LM_TS_STAMP].time.tv_sec == cloned->timestamps[LM_TS_STAMP].time.tv_sec, "%d", (int) logmsg->timestamps[LM_TS_STAMP].time.tv_sec, (int) cloned->timestamps[LM_TS_STAMP].time.tv_sec);
  TEST_ASSERT(logmsg->timestamps[LM_TS_STAMP].time.tv_usec == cloned->timestamps[LM_TS_STAMP].time.tv_usec, "%d", (int) logmsg->timestamps[LM_TS_STAMP].time.tv_usec, (int) cloned->timestamps[LM_TS_STAMP].time.tv_usec);
  TEST_ASSERT(logmsg->timestamps[LM_TS_STAMP].zone_offset == cloned->timestamps[LM_TS_STAMP].zone_offset, "%d", (int) logmsg->timestamps[LM_TS_STAMP].zone_offset, (int) cloned->timestamps[LM_TS_STAMP].zone_offset);
  TEST_ASSERT(strcmp(log_msg_get_value(logmsg, LM_V_HOST, NULL), log_msg_get_value(cloned, LM_V_HOST, NULL)) == 0, "%s", log_msg_get_value(logmsg, LM_V_HOST, NULL), log_msg_get_value(cloned, LM_V_HOST, NULL));
  TEST_ASSERT(strcmp(log_msg_get_value(logmsg, LM_V_PROGRAM, NULL), log_msg_get_value(cloned, LM_V_PROGRAM, NULL)) == 0, "%s", log_msg_get_value(logmsg, LM_V_PROGRAM, NULL), log_msg_get_value(cloned, LM_V_PROGRAM, NULL));
  TEST_ASSERT(strcmp(log_msg_get_value(logmsg, LM_V_MESSAGE, NULL), log_msg_get_value(cloned, LM_V_MESSAGE, NULL)) == 0, "%s", log_msg_get_value(logmsg, LM_V_MESSAGE, NULL), log_msg_get_value(cloned, LM_V_MESSAGE, NULL));
  TEST_ASSERT(strcmp(log_msg_get_value(logmsg, LM_V_PID, NULL), log_msg_get_value(cloned, LM_V_PID, NULL)) == 0, "%s", log_msg_get_value(logmsg, LM_V_PID, NULL), log_msg_get_value(cloned, LM_V_PID, NULL));
  TEST_ASSERT(strcmp(log_msg_get_value(logmsg, LM_V_MSGID, NULL), log_msg_get_value(cloned, LM_V_MSGID, NULL)) == 0, "%s", log_msg_get_value(logmsg, LM_V_MSGID, NULL), log_msg_get_value(cloned, LM_V_MSGID, NULL));

  /* SD elements */
  log_msg_format_sdata(cloned, sd_str);
  TEST_ASSERT(strcmp(sd_str->str, expected_sd_str) == 0, "%s", sd_str->str, expected_sd_str);


  log_msg_set_value(cloned, LM_V_HOST, "newhost", -1);
  log_msg_set_value(cloned, LM_V_HOST_FROM, "newhost", -1);
  log_msg_set_value(cloned, LM_V_MESSAGE, "newmsg", -1);
  log_msg_set_value(cloned, LM_V_PROGRAM, "newprogram", -1);
  log_msg_set_value(cloned, LM_V_PID, "newpid", -1);
  log_msg_set_value(cloned, LM_V_MSGID, "newmsgid", -1);
  log_msg_set_value(cloned, LM_V_SOURCE, "newsource", -1);
  log_msg_set_value(cloned, log_msg_get_value_handle("newvalue"), "newvalue", -1);

  /* retest values in original logmsg */

  TEST_ASSERT(strcmp(log_msg_get_value(logmsg, LM_V_HOST, NULL), expected_host) == 0, "%s", log_msg_get_value(logmsg, LM_V_HOST, NULL), expected_host);
  TEST_ASSERT(strcmp(log_msg_get_value(logmsg, LM_V_PROGRAM, NULL), expected_program) == 0, "%s", log_msg_get_value(logmsg, LM_V_PROGRAM, NULL), expected_program);
  TEST_ASSERT(strcmp(log_msg_get_value(logmsg, LM_V_MESSAGE, NULL), expected_msg) == 0, "%s", log_msg_get_value(logmsg, LM_V_MESSAGE, NULL), expected_msg);
  TEST_ASSERT(strcmp(log_msg_get_value(logmsg, LM_V_PID, NULL), expected_process_id) == 0, "%s", log_msg_get_value(logmsg, LM_V_PID, NULL), expected_process_id);
  TEST_ASSERT(strcmp(log_msg_get_value(logmsg, LM_V_MSGID, NULL), expected_message_id) == 0, "%s", log_msg_get_value(logmsg, LM_V_MSGID, NULL), expected_message_id);
  TEST_ASSERT(strcmp(log_msg_get_value(logmsg, LM_V_SOURCE, NULL), "") == 0, "%s", log_msg_get_value(logmsg, LM_V_SOURCE, NULL), "");

  /* check newly set values in cloned */

  TEST_ASSERT(strcmp(log_msg_get_value(cloned, LM_V_HOST, NULL), "newhost") == 0, "%s", log_msg_get_value(cloned, LM_V_HOST, NULL), "newhost");
  TEST_ASSERT(strcmp(log_msg_get_value(cloned, LM_V_HOST_FROM, NULL), "newhost") == 0, "%s", log_msg_get_value(cloned, LM_V_HOST_FROM, NULL), "newhost");
  TEST_ASSERT(strcmp(log_msg_get_value(cloned, LM_V_PROGRAM, NULL), "newprogram") == 0, "%s", log_msg_get_value(cloned, LM_V_PROGRAM, NULL), "newprogram");
  TEST_ASSERT(strcmp(log_msg_get_value(cloned, LM_V_MESSAGE, NULL), "newmsg") == 0, "%s", log_msg_get_value(cloned, LM_V_MESSAGE, NULL), "newmsg");
  TEST_ASSERT(strcmp(log_msg_get_value(cloned, LM_V_PID, NULL), "newpid") == 0, "%s", log_msg_get_value(cloned, LM_V_PID, NULL), "newpid");
  TEST_ASSERT(strcmp(log_msg_get_value(cloned, LM_V_MSGID, NULL), "newmsgid") == 0, "%s", log_msg_get_value(cloned, LM_V_MSGID, NULL), "newmsgid");
  TEST_ASSERT(strcmp(log_msg_get_value(cloned, LM_V_SOURCE, NULL), "newsource") == 0, "%s", log_msg_get_value(cloned, LM_V_SOURCE, NULL), "newsource");

  log_msg_unref(cloned);
  log_msg_unref(logmsg);
  g_string_free(sd_str, TRUE);
  return 0;
}
Exemplo n.º 20
0
int main( int argc, char **argv )
{
    int done = 0, myid, numprocs, i;
	int from, to;
    int  namelen;
    char processor_name[MPI_MAX_PROCESSOR_NAME];
	double seconds, Mflop_s;;
	
	int root_process = 0;
	int n_iterations = 1, iter = 0;
	int n = 1600; 

   	double *A = (double*) malloc( n * n * sizeof(double) );
   	double *B = (double*) malloc( n * n * sizeof(double) );
   	double *C = (double*) malloc( n * n * sizeof(double) );
    
	MPI_Init(&argc,&argv);
    MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
    MPI_Comm_rank(MPI_COMM_WORLD,&myid);
    MPI_Get_processor_name(processor_name,&namelen);
	
	/* These sizes should highlight performance dips at multiples of certain powers-of-two */
	/*Craete and fill 3 random matrices A,B,C*/
	from = myid * n/numprocs;
	to = (myid+1) * n/numprocs;
	if(myid == root_process){
    	printf ("Description:\t%s\n\n", dgemm_desc);
		n_iterations = 1;
	}

START:	
	if (myid == root_process){
		

    	fill( A, n * n );
    	fill( B, n * n );
    	//fill( C, n * n );
        memset( C, 0, sizeof( double ) * n * n );

	}
	MPI_Bcast(A, n * n, MPI_DOUBLE, 0,MPI_COMM_WORLD);
	MPI_Bcast(B, n * n, MPI_DOUBLE, 0,MPI_COMM_WORLD);
	MPI_Bcast(C, n * n, MPI_DOUBLE, 0,MPI_COMM_WORLD);


	if(myid == root_process){
		iter = 0;
	}
	
	double *T = (double*) malloc( n * n * sizeof(double) );
	
ITERATION:
   	if(myid == root_process){
   		seconds = MPI_Wtime();
   	}
   	

	square_dgemm(n, from, to, A, B, C, T);
//	MPI_Barrier(MPI_COMM_WORLD);

	MPI_Gather(T + from * n,
               		n * (n / numprocs),
			        MPI_DOUBLE,
					C + from * n,
				    n * (n / numprocs),
				    MPI_DOUBLE,
				    0,
				    MPI_COMM_WORLD);




/*		
		if (iter < n_iterations){
			iter++;
			goto ITERATION;
		}

        seconds = MPI_Wtime() - seconds;
        if (seconds < 0.1){
			n_iterations *= 2;
			goto START;
		}
*/
        seconds = MPI_Wtime() - seconds;
		Mflop_s = 1e-6 * n_iterations * n * n * n / seconds;
		printf("Mflops: %g time: %g \n", Mflop_s, seconds);
        
		cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, n,n,n, -1, A,n, B,n, 1, C,n );
		/*Subtract the maximum allowed roundoff from each element of C*/
        absolute_value( A, n * n );
        absolute_value( B, n * n );
        absolute_value( C, n * n );
        //dgemm( 'N','N', n,n,n, -3.0*DBL_EPSILON*n, A,n, B,n, 1, C,n );
        cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, n,n,n, -3.0*DBL_EPSILON*n, A,n, B,n, 1, C,n );
		/*After this test if any element in C is still positive something went wrong in square_dgemm*/
        for( int i = 0; i < n * n; i++ )
            if( C[i] > 0 ) {
                printf( "FAILURE: error in matrix multiply exceeds an acceptable margin\n" );
                exit(-1);
            }

/*		
		if (iter < n_iterations){
			iter++;
			goto ITERATION;
		}

        seconds = MPI_Wtime() - seconds;
        if (seconds < 0.1){
			n_iterations *= 2;
			goto START;
		}
*/

    
	}