TEST(ComputeRandomPermutation, ComputeSingle)
{
  std::vector<int> expectedData{ 0 };
  EXPECT_EQ(expectedData, compute(1));
}
示例#2
0
void HelloWorld::set(double r1_, double r2_)
{ 
    r1 = r1_;
    r2 = r2_; 
    compute();  // compute s
}
示例#3
0
文件: XListBox.cpp 项目: dulton/XGUI
void XListBox::mouseWheelUp(X_Event *event)
{
	compute(6);
	onPaint(X_UPDATE);
	showWidget();
}
示例#4
0
//main program
int main(int argc, char *argv[])
{
	MPI_Init(&argc, &argv);
	int size, rank;
	long t1, t2;
	static int ranks[1] = { 0 };
	MPI_Request request1, request2, request3, request4;
	MPI_Status status, status1, status2, status3, status4;
	MPI_Group MPI_GROUP_WORLD, grprem;
	MPI_Comm commslave, newcomm;
	MPI_Comm commsp;
	MPI_Comm_group(MPI_COMM_WORLD, &MPI_GROUP_WORLD);
	MPI_Group_excl(MPI_GROUP_WORLD, 1, ranks, &grprem);
	MPI_Comm_create(MPI_COMM_WORLD, grprem, &commslave);
	MPI_Comm_size(MPI_COMM_WORLD, &size);
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);
	printf("Node %d in %d is ready\n", rank, size);
	//Initialize
	double *grid0 = creat_grid(x_size, y_size, z_size, size, rank, GRID0);
	double *grid1 = creat_grid(x_size, y_size, z_size, size, rank, GRID1);
	MPI_Barrier(MPI_COMM_WORLD);
	if (size != 1)
	{
		if (rank == 0)
		{
			for (int i = 1; i < size; i++)
			{
				int len = (i == size - 1) ? (x_size / (size - 1)) : (x_size / (size - 1) + x_size % (size - 1));
				MPI_Isend(grid0 + (i - 1)*x_size / (size - 1), len*y_size*z_size, MPI_DOUBLE, i, i, MPI_COMM_WORLD, &request1);
				MPI_Wait(&request1, &status1);
			}
		}
		else
		{
			for (int i = 1; i < size; i++)
			{
				if (rank == i)
				{
					int len = (i == size - 1) ? (x_size / (size - 1)) : (x_size / (size - 1) + x_size % (size - 1));
					MPI_Irecv(grid0 + y_size*z_size, len*y_size*z_size, MPI_DOUBLE, 0, i, MPI_COMM_WORLD, &request2);
					MPI_Wait(&request2, &status2);
				}
			}

		}
	}
	//Compute
	if (rank == 0) printf("Start computing...\n");
	if (rank != 0 && size > 1)
	{
		for (int t = 0; t < stepnum; t++)
		{
			compute(grid0, grid1, rank, size);
			//send right slice of data to next node, then receieve right slice of data form next node
			if (rank < size - 1)
			{
				MPI_Isend(grid1 + (1 + x_size / (size - 1))*y_size*z_size,
					y_size*z_size, MPI_DOUBLE, rank + 1, rank, MPI_COMM_WORLD, &request1);
				MPI_Irecv(grid1 + (1 + x_size / (size - 1))*y_size*z_size,
					y_size*z_size, MPI_DOUBLE, rank + 1, rank + 1, MPI_COMM_WORLD, &request2);
				MPI_Wait(&request1, &status1);
				MPI_Wait(&request2, &status2);
			}
			//receieve left slice of data from perior node, then send left slice of data to perior node
			if (rank > 1)
			{
				MPI_Irecv(grid1, y_size*z_size, MPI_DOUBLE, rank - 1, rank - 1, MPI_COMM_WORLD, &request3);
				MPI_Isend(grid1, y_size*z_size, MPI_DOUBLE, rank - 1, rank, MPI_COMM_WORLD, &request4);
				MPI_Wait(&request3, &status3);
				MPI_Wait(&request4, &status4);
			}
			double *temp;
			temp = grid0;
			grid0 = grid1;
			grid1 = temp;
			MPI_Barrier(commslave);
		}
	}
	else if (size == 1)
	{
		for (int t = 0; t < stepnum; t++)
		{
			compute(grid0, grid1, rank, size);
			double *temp;
			temp = grid0;
			grid0 = grid1;
			grid1 = temp;
		}
	}
	else { ; }
	MPI_Barrier(MPI_COMM_WORLD);
	printf("Rank %d finished computing!\n", rank);
	//Gather data form nodes to host
	if (size != 1)
	{
		if (stepnum % 2)
		{
			double *temp;
			temp = grid0;
			grid0 = grid1;
			grid1 = temp;
		}
		for (int i = 1; i < size; i++)
		{
			if (rank == i)
			{
				int len = (i == size - 1) ? (x_size / (size - 1)) : (x_size / (size - 1) + x_size % (size - 1));
				MPI_Isend(grid0 + y_size*z_size, len*y_size*z_size, MPI_DOUBLE, 0, i, MPI_COMM_WORLD, &request2);
				MPI_Wait(&request2, &status2);
			}
		}
		if (rank == 0)
		{
			for (int i = 1; i < size; i++)
			{
				int len = (i == size - 1) ? (x_size / (size - 1)) : (x_size / (size - 1) + x_size % (size - 1));
				MPI_Irecv(grid1, len*y_size*z_size, MPI_DOUBLE, i, i, MPI_COMM_WORLD, &request1);
				MPI_Wait(&request1, &status1);
			}
		}
	}
	MPI_Barrier(MPI_COMM_WORLD);
	if (rank == 0) printf("All work complete\n");
	MPI_Finalize();
	return 0;
}
void passThrough(int *p) {
  use2(p, compute());
  // expected-note@-1 {{Passing null pointer value via 1st parameter 'ptr'}}
  // expected-note@-2 {{Calling 'use2'}}
}
示例#6
0
__declspec(dllexport) long Multiplicate(long arg1, long arg2)
{
	return compute(arg1, arg2);
}
示例#7
0
MatrixXf Permutohedral::compute ( const MatrixXf & in, bool reverse ) const
{
    MatrixXf r;
    compute( r, in, reverse );
    return r;
}
示例#8
0
const_shared_ptr<Result> BinaryExpression::compute(const std::uint8_t& left,
		const double& right, yy::location left_position,
		yy::location right_position) const {
	double converted_left = left;
	return compute(converted_left, right, left_position, right_position);
}
示例#9
0
const_shared_ptr<Result> BinaryExpression::compute(const std::uint8_t& left,
		const string& right, yy::location left_position,
		yy::location right_position) const {
	return compute(*AsString(left), right, left_position, right_position);
}
示例#10
0
// Boolean
const_shared_ptr<Result> BinaryExpression::compute(const bool& left,
		const int& right, yy::location left_position,
		yy::location right_position) const {
	int converted_left = left;
	return compute(converted_left, right, left_position, right_position);
}
示例#11
0
// Byte
const_shared_ptr<Result> BinaryExpression::compute(const std::uint8_t& left,
		const bool& right, yy::location left_position,
		yy::location right_position) const {
	std::uint8_t converted_right = right;
	return compute(left, converted_right, left_position, right_position);
}
示例#12
0
SUMOReal
HelpersHBEFA::computeFuel(SUMOEmissionClass c, double v, double a) {
    return compute(c, FUEL_OFFSET, v, a) / 790.;
}
示例#13
0
SUMOReal
HelpersHBEFA::computePMx(SUMOEmissionClass c, double v, double a) {
    return compute(c, PMx_OFFSET, v, a);
}
示例#14
0
void mexFunction(int nlhs, mxArray  *plhs[], int nrhs, const mxArray  *prhs[])
{
	int atria_preprocessing_given = 0;		// flag wheter preprocessing is already given on command line
	long opt_flag = 0;	// 0 => eucl.norm, upper triangle matrix, 1 => max.norm, utm, 2 => eucl,full matrix, 3 => max.,full matrix

	be_verbose = 0; // Don't spit out feedback to user by default

	// try to see if the first parameter given is an atria structure
	// If this is true, the order of input parameters is shifted by one
	if ((nrhs > 0) && mxIsStruct(prhs[0])) {
		atria_preprocessing_given = 1;
		prhs++; 	// these two lines enable us to use the old argument parsing block without changing it
		nrhs--;
	}

	/* check input args */
	if (nrhs < 3)
	{
		mexErrMsgTxt("Correlation sum : Data set of points (row vectors), reference points and relative range (relative to attractor diameter) must be given, number of bins is optional");
		return;
	}

	if (nrhs > 4) opt_flag = (long) *((double *)mxGetPr(prhs[4]));

	if (opt_flag & (long) 2)
		be_verbose = 0;

	if (atria_preprocessing_given) {
#ifdef MATLAB_MEX_FILE
		char* metric = 0;

		if (mxIsChar(mxGetField(prhs[-1], 0, "optional"))) {
    		long buflen = (mxGetM(mxGetField(prhs[-1], 0, "optional")) * mxGetN(mxGetField(prhs[-1], 0, "optional"))) + 1;
 			metric = (char*) mxMalloc(buflen);
        	mxGetString(mxGetField(prhs[-1], 0, "optional"), metric, buflen);
		}

		if ((metric == 0) || (!strncmp("euclidian", metric, strlen(metric)))) {
			euclidian_distance dummy;

			if (be_verbose)
				mexPrintf("Using euclidian metric to calculated distances\n");

			compute(nlhs, plhs, nrhs, prhs, 1, dummy);
		}
		else if ((!strncmp("maximum", metric, strlen(metric)))) {
			maximum_distance dummy;

			if (be_verbose)
				mexPrintf("Using maximum metric to calculated distances\n");

			compute(nlhs, plhs, nrhs, prhs, 1, dummy);
		}
		else
			printf("ATRIA preprocessing structure was not created using a supported metric; doing preprocessing again\n");

		mxFree(metric);
#endif
	} else {
		if (opt_flag & (long)1) {
			maximum_distance dummy;

			if (be_verbose)
				mexPrintf("Using maximum metric to calculated distances\n");
			compute(nlhs, plhs, nrhs, prhs, 0, dummy);
		} else {
			euclidian_distance dummy;
			if (be_verbose)
				mexPrintf("Using euclidian metric to calculated distances\n");

			compute(nlhs, plhs, nrhs, prhs, 0, dummy);
		}
	}
}
/**
* \ingroup Stimulus
* Set the angular aperture of the cylinder in radians
* \param _startAngle Starting angle in radians
* \param _endAngle End angle in radians
**/
void CylinderPointsStimulus::setAperture(double _startAngle, double _endAngle )
{  startAngle = _startAngle;
   endAngle = _endAngle;
   compute();
}
示例#16
0
const_shared_ptr<Result> BinaryExpression::compute(const double& left,
		const int& right, yy::location left_position,
		yy::location right_position) const {
	double converted_right = right;
	return compute(left, converted_right, left_position, right_position);
}
示例#17
0
static long evaluate(char *symbolicexpr, char **resultexpr, value_t **valuelist, char **errbuf)
{
	char expr[MAX_LINE_LEN];
	char *inp, *outp, *symp;
	char symbol[MAX_LINE_LEN];
	int done;
	int insymbol = 0;
	int result, error;
	long oneval;
	int onecolor;
	value_t *valhead = NULL, *valtail = NULL;
	value_t *newval;
	char errtext[1024];

	done = 0; inp=symbolicexpr; outp=expr; symp = NULL; 
	while (!done) {
		if (isalpha((int)*inp)) {
			if (!insymbol) { insymbol = 1; symp = symbol; }
			*symp = *inp; symp++;
		}
		else if (insymbol && (isdigit((int) *inp) || (*inp == '.'))) {
			*symp = *inp; symp++;
		}
		else if (insymbol && ((*inp == '\\') && (*(inp+1) > ' '))) {
			*symp = *(inp+1); symp++; inp++;
		}
		else {
			if (insymbol) {
				/* Symbol finished - evaluate the symbol */
				char *hname, *tname;

				*symp = '\0';
				insymbol = 0;
				hname = gethname(symbol); 
				tname = gettname(symbol);
				if (hname && tname) {
					oneval = getvalue(gethname(symbol), gettname(symbol), &onecolor, errbuf);
				}
				else {
					errprintf("Invalid data for symbol calculation - missing host/testname: %s\n",
						  symbol);
					oneval = 0;
					onecolor = COL_CLEAR;
				}

				sprintf(outp, "%ld", oneval);
				outp += strlen(outp);

				newval = (value_t *) malloc(sizeof(value_t));
				newval->symbol = strdup(symbol);
				newval->color = onecolor;
				newval->next = NULL;
				if (valhead == NULL) {
					valtail = valhead = newval;
				}	
				else {
					valtail->next = newval;
					valtail = newval;
				}
			}

			*outp = *inp; outp++; symp = NULL;
		}

		if (*inp == '\0') done = 1; else inp++;
	}

	*outp = '\0';

	if (resultexpr) *resultexpr = strdup(expr);
	dbgprintf("Symbolic '%s' converted to '%s'\n", symbolicexpr, expr);

	error = 0; 
	result = compute(expr, &error);

	if (error) {
		sprintf(errtext, "compute(%s) returned error %d\n", expr, error);
		if (*errbuf == NULL) {
			*errbuf = strdup(errtext);
		}
		else {
			*errbuf = (char *)realloc(*errbuf, strlen(*errbuf)+strlen(errtext)+1);
			strcat(*errbuf, errtext);
		}
	}

	*valuelist = valhead;
	return result;
}
示例#18
0
const_shared_ptr<Result> BinaryExpression::compute(const string& left,
		const double& right, yy::location left_position,
		yy::location right_position) const {
	return compute(left, *AsString(right), left_position, right_position);
}
 void LMMNormalDriftCalculator::compute(const LMMCurveState& cs,
                                        std::vector<Real>& drifts) const {
     compute(cs.forwardRates(), drifts);
 }
示例#20
0
const_shared_ptr<Result> BinaryExpression::Evaluate(
		const shared_ptr<ExecutionContext> context,
		const shared_ptr<ExecutionContext> closure) const {
	ErrorListRef errors = ErrorList::GetTerminator();
	const_shared_ptr<Expression> left = GetLeft();
	const_shared_ptr<Expression> right = GetRight();

	const_shared_ptr<Result> left_result = left->Evaluate(context, closure);
	if (!ErrorList::IsTerminator(left_result->GetErrors())) {
		return left_result;
	}

	const_shared_ptr<Result> right_result = right->Evaluate(context, closure);
	if (!ErrorList::IsTerminator(right_result->GetErrors())) {
		return right_result;
	}

	auto left_type_specifier_result = left->GetTypeSpecifier(context);
	auto right_type_specifier_result = right->GetTypeSpecifier(context);

	errors = left_type_specifier_result.GetErrors();
	if (ErrorList::IsTerminator(errors)) {
		errors = right_type_specifier_result.GetErrors();
		if (ErrorList::IsTerminator(errors)) {
			yy::location left_position = left->GetLocation();
			yy::location right_position = right->GetLocation();

			auto type_table = context->GetTypeTable();

			auto left_type = left_type_specifier_result.GetData();
			auto right_type = right_type_specifier_result.GetData();

			// This logic is essentially a big muxer.
			// It works in tandem with C++ type widening to convert operands to the same data type
			if (left_type->AnalyzeAssignmentTo(
					PrimitiveTypeSpecifier::GetBoolean(), type_table)
					== EQUIVALENT) {
				bool left_value = *(left_result->GetData<bool>());

				if (right_type->AnalyzeAssignmentTo(
						PrimitiveTypeSpecifier::GetBoolean(), type_table)
						== EQUIVALENT) {
					bool right_value = *(right_result->GetData<bool>());
					return compute(left_value, right_value, left_position,
							right_position);
				} else if (right_type->AnalyzeAssignmentTo(
						PrimitiveTypeSpecifier::GetByte(), type_table)
						== EQUIVALENT) {
					auto right_value = *(right_result->GetData<std::uint8_t>());
					return compute(left_value, right_value, left_position,
							right_position);
				} else if (right_type->AnalyzeAssignmentTo(
						PrimitiveTypeSpecifier::GetInt(), type_table)
						== EQUIVALENT) {
					int right_value = *(right_result->GetData<int>());
					return compute(left_value, right_value, left_position,
							right_position);
				} else if (right_type->AnalyzeAssignmentTo(
						PrimitiveTypeSpecifier::GetDouble(), type_table)
						== EQUIVALENT) {
					double right_value = *(right_result->GetData<double>());
					return compute(left_value, right_value, left_position,
							right_position);
				} else if (right_type->AnalyzeAssignmentTo(
						PrimitiveTypeSpecifier::GetString(), type_table)
						== EQUIVALENT) {
					string right_value = *(right_result->GetData<string>());
					return compute(left_value, right_value, left_position,
							right_position);
				} else {
					assert(false);
				}
			} else if (left_type->AnalyzeAssignmentTo(
					PrimitiveTypeSpecifier::GetByte(), type_table)
					== EQUIVALENT) {
				auto left_value = *(left_result->GetData<std::uint8_t>());

				if (right_type->AnalyzeAssignmentTo(
						PrimitiveTypeSpecifier::GetBoolean(), type_table)
						== EQUIVALENT) {
					bool right_value = *(right_result->GetData<bool>());
					return compute(left_value, right_value, left_position,
							right_position);
				} else if (right_type->AnalyzeAssignmentTo(
						PrimitiveTypeSpecifier::GetByte(), type_table)
						== EQUIVALENT) {
					auto right_value = *(right_result->GetData<std::uint8_t>());
					return compute(left_value, right_value, left_position,
							right_position);
				} else if (right_type->AnalyzeAssignmentTo(
						PrimitiveTypeSpecifier::GetInt(), type_table)
						== EQUIVALENT) {
					int right_value = *(right_result->GetData<int>());
					return compute(left_value, right_value, left_position,
							right_position);
				} else if (right_type->AnalyzeAssignmentTo(
						PrimitiveTypeSpecifier::GetDouble(), type_table)
						== EQUIVALENT) {
					double right_value = *(right_result->GetData<double>());
					return compute(left_value, right_value, left_position,
							right_position);
				} else if (right_type->AnalyzeAssignmentTo(
						PrimitiveTypeSpecifier::GetString(), type_table)
						== EQUIVALENT) {
					string right_value = *(right_result->GetData<string>());
					return compute(left_value, right_value, left_position,
							right_position);
				} else {
					assert(false);
				}
			} else if (left_type->AnalyzeAssignmentTo(
					PrimitiveTypeSpecifier::GetInt(), type_table)
					== EQUIVALENT) {
				int left_value = *(left_result->GetData<int>());

				if (right_type->AnalyzeAssignmentTo(
						PrimitiveTypeSpecifier::GetBoolean(), type_table)
						== EQUIVALENT) {
					bool right_value = *(right_result->GetData<bool>());
					return compute(left_value, right_value, left_position,
							right_position);
				} else if (right_type->AnalyzeAssignmentTo(
						PrimitiveTypeSpecifier::GetByte(), type_table)
						== EQUIVALENT) {
					auto right_value = *(right_result->GetData<std::uint8_t>());
					return compute(left_value, right_value, left_position,
							right_position);
				} else if (right_type->AnalyzeAssignmentTo(
						PrimitiveTypeSpecifier::GetInt(), type_table)
						== EQUIVALENT) {
					int right_value = *(right_result->GetData<int>());
					return compute(left_value, right_value, left_position,
							right_position);
				} else if (right_type->AnalyzeAssignmentTo(
						PrimitiveTypeSpecifier::GetDouble(), type_table)
						== EQUIVALENT) {
					double right_value = *(right_result->GetData<double>());
					return compute(left_value, right_value, left_position,
							right_position);
				} else if (right_type->AnalyzeAssignmentTo(
						PrimitiveTypeSpecifier::GetString(), type_table)
						== EQUIVALENT) {
					string right_value = *(right_result->GetData<string>());
					return compute(left_value, right_value, left_position,
							right_position);
				} else {
					assert(false);
				}
			} else if (left_type->AnalyzeAssignmentTo(
					PrimitiveTypeSpecifier::GetDouble(), type_table)
					== EQUIVALENT) {
				double left_value = *(left_result->GetData<double>());

				if (right_type->AnalyzeAssignmentTo(
						PrimitiveTypeSpecifier::GetBoolean(), type_table)
						== EQUIVALENT) {
					bool right_value = *(right_result->GetData<bool>());
					return compute(left_value, right_value, left_position,
							right_position);
				} else if (right_type->AnalyzeAssignmentTo(
						PrimitiveTypeSpecifier::GetByte(), type_table)
						== EQUIVALENT) {
					auto right_value = *(right_result->GetData<std::uint8_t>());
					return compute(left_value, right_value, left_position,
							right_position);
				} else if (right_type->AnalyzeAssignmentTo(
						PrimitiveTypeSpecifier::GetInt(), type_table)
						== EQUIVALENT) {
					int right_value = *(right_result->GetData<int>());
					return compute(left_value, right_value, left_position,
							right_position);
				} else if (right_type->AnalyzeAssignmentTo(
						PrimitiveTypeSpecifier::GetDouble(), type_table)
						== EQUIVALENT) {
					double right_value = *(right_result->GetData<double>());
					return compute(left_value, right_value, left_position,
							right_position);
				} else if (right_type->AnalyzeAssignmentTo(
						PrimitiveTypeSpecifier::GetString(), type_table)
						== EQUIVALENT) {
					string right_value = *(right_result->GetData<string>());
					return compute(left_value, right_value, left_position,
							right_position);
				} else {
					assert(false);
				}
			} else if (left_type->AnalyzeAssignmentTo(
					PrimitiveTypeSpecifier::GetString(), type_table)
					== EQUIVALENT) {
				string left_value = *(left_result->GetData<string>());

				if (right_type->AnalyzeAssignmentTo(
						PrimitiveTypeSpecifier::GetBoolean(), type_table)
						== EQUIVALENT) {
					bool right_value = *(right_result->GetData<bool>());
					return compute(left_value, right_value, left_position,
							right_position);
				} else if (right_type->AnalyzeAssignmentTo(
						PrimitiveTypeSpecifier::GetByte(), type_table)
						== EQUIVALENT) {
					auto right_value = *(right_result->GetData<std::uint8_t>());
					return compute(left_value, right_value, left_position,
							right_position);
				} else if (right_type->AnalyzeAssignmentTo(
						PrimitiveTypeSpecifier::GetInt(), type_table)
						== EQUIVALENT) {
					int right_value = *(right_result->GetData<int>());
					return compute(left_value, right_value, left_position,
							right_position);
				} else if (right_type->AnalyzeAssignmentTo(
						PrimitiveTypeSpecifier::GetDouble(), type_table)
						== EQUIVALENT) {
					double right_value = *(right_result->GetData<double>());
					return compute(left_value, right_value, left_position,
							right_position);
				} else if (right_type->AnalyzeAssignmentTo(
						PrimitiveTypeSpecifier::GetString(), type_table)
						== EQUIVALENT) {
					string right_value = *(right_result->GetData<string>());
					return compute(left_value, right_value, left_position,
							right_position);
				} else {
					assert(false);
				}
			} else {
				assert(false);
			}
		}
	}

	return make_shared<Result>(nullptr, errors);
}
示例#21
0
long main()
{
	printf("compute=%d\n", compute(1, 2, 3));
}
示例#22
0
void *thread_body(void *arg) {
  
  int ret;
  int nperiods;
  struct sched_param param;
  timing_point_t *timings;
  pid_t tid;
  struct sched_attr attr;
  unsigned int flags = 0;
  struct timespec t, t_next;
  timing_point_t tmp_timing;
  timing_point_t *curr_timing;
  unsigned long t_start_usec;
  int i = 0;

  thread_data_t *data = (thread_data_t*) arg;

  /* set thread affinity */
  if (data->cpuset != NULL) {
    log_notice("[%d] setting cpu affinity to CPU(s) %s",
      data->ind, data->cpuset_str);
    ret = pthread_setaffinity_np(pthread_self(),
      sizeof(cpu_set_t), data->cpuset);
    if (ret < 0) {
      errno = ret;
      perror("pthread_setaffinity_np");
      exit(EXIT_FAILURE);
    }
  }

  /* set scheduling policy and print pretty info on stdout */
  log_notice("[%d] Using %s policy:", data->ind, data->sched_policy_descr);
  switch (data->sched_policy) {
    case rr:
    case fifo:
      fprintf(data->log_handler, "# Policy : %s\n",
        (data->sched_policy == rr ? "SCHED_RR" : "SCHED_FIFO"));
      param.sched_priority = data->sched_prio;
      ret = pthread_setschedparam(pthread_self(),
        data->sched_policy, &param);
      if (ret != 0) {
        errno = ret; 
        perror("pthread_setschedparam"); 
        exit(EXIT_FAILURE);
      }

      log_notice("[%d] starting thread with period: %" PRIu64 
        ", exec: %" PRIu64 ",""deadline: %" PRIu64 ", priority: %d",
        data->ind,
        timespec_to_usec(&data->period), 
        timespec_to_usec(&data->min_et),
        timespec_to_usec(&data->deadline),
        data->sched_prio
      );
      break;
    case other:
      fprintf(data->log_handler, "# Policy : SCHED_OTHER\n");
      log_notice("[%d] starting thread with period: %" PRIu64 
           ", exec: %" PRIu64 ",""deadline: %" PRIu64 "", data->ind,
        timespec_to_usec(&data->period), 
        timespec_to_usec(&data->min_et),
        timespec_to_usec(&data->deadline)
      );
      data->lock_pages = 0; /* forced off for SCHED_OTHER */
      break;
    case deadline:
      fprintf(data->log_handler, "# Policy : SCHED_DEADLINE\n");
      tid = gettid();
      attr.size = sizeof(attr);
      attr.sched_flags = data->sched_flags;
      if (data->sched_flags && SCHED_FLAG_SOFT_RSV)
        fprintf(data->log_handler, "# Type : SOFT_RSV\n");
      else
        fprintf(data->log_handler, "# Type : HARD_RSV\n");
      attr.sched_policy = SCHED_DEADLINE;
      attr.sched_priority = 0;
      attr.sched_runtime = timespec_to_nsec(&data->max_et) +
        (timespec_to_nsec(&data->max_et) /100) * BUDGET_OVERP;
      attr.sched_deadline = timespec_to_nsec(&data->period);
      attr.sched_period = timespec_to_nsec(&data->period);  
      break;
    default:
      log_error("Unknown scheduling policy %d",
        data->sched_policy);
      exit(EXIT_FAILURE);
  }

  if (data->lock_pages == 1) {
    log_notice("[%d] Locking pages in memory", data->ind);
    ret = mlockall(MCL_CURRENT | MCL_FUTURE);
    if (ret < 0) {
      errno = ret;
      perror("mlockall");
      exit(EXIT_FAILURE);
    }
  }

  /* if we know the duration we can calculate how many periods we will
   * do at most, and the log to memory, instead of logging to file.
   */
  timings = NULL;
  if (data->duration > 0) {
    nperiods = (int) ceil( (data->duration * 10e6) / 
              (double) timespec_to_usec(&data->period));
    timings = malloc ( nperiods * sizeof(timing_point_t));
  }

  fprintf(data->log_handler, "#idx\tperiod\tmin_et\tmax_et\trel_st\tstart"
           "\t\tend\t\tdeadline\tdur.\tslack\tresp_t"
           "\tBudget\tUsed Budget\n");

  if (data->ind == 0) {
    clock_gettime(CLOCK_MONOTONIC, &t_zero);
#ifdef TRACE_SETS_ZERO_TIME
    if (opts.ftrace)
      log_ftrace(ft_data.marker_fd,
           "[%d] sets zero time",
           data->ind);
#endif
  }

  pthread_barrier_wait(&threads_barrier);

  /*
   * Set the task to SCHED_DEADLINE as far as possible touching its
   * budget as little as possible for the first iteration.
   */
  if (data->sched_policy == SCHED_DEADLINE) {
    ret = sched_setattr(tid, &attr, flags);
    if (ret != 0) {
      log_critical("[%d] sched_setattr "
        "returned %d", data->ind, ret);
      errno = ret;
      perror("sched_setattr");
      exit(EXIT_FAILURE);
    }
  }

  t = t_zero;
  t_next = msec_to_timespec(1000LL);
  t_next = timespec_add(&t, &t_next);
  clock_nanosleep(CLOCK_MONOTONIC, 
    TIMER_ABSTIME, 
    &t_next,
    NULL);

  data->deadline = timespec_add(&t_next, &data->deadline);

  while (continue_running) {
    int pn;
    struct timespec t_start, t_end, t_diff, t_slack, t_resp;

    /* Thread numeration reported starts with 1 */
#ifdef TRACE_BEGINS_LOOP
    if (opts.ftrace)
      log_ftrace(ft_data.marker_fd, "[%d] begins job %d", data->ind+1, i);
#endif
    clock_gettime(CLOCK_MONOTONIC, &t_start);
    if (data->nphases == 0) {
      compute(data->ind, &data->min_et, NULL, 0);
    } else {
      for (pn = 0; pn < data->nphases; pn++) {
        log_notice("[%d] phase %d start", data->ind+1, pn);
        exec_phase(data, pn);
        log_notice("[%d] phase %d end", data->ind+1, pn);
      }
    }
    clock_gettime(CLOCK_MONOTONIC, &t_end);
    
    t_diff = timespec_sub(&t_end, &t_start);
    t_slack = timespec_sub(&data->deadline, &t_end);
    t_resp = timespec_sub(&t_end, &t_next);
    t_start_usec = timespec_to_usec(&t_start); 

    if (i < nperiods) {
      if (timings)
        curr_timing = &timings[i];
      else
        curr_timing = &tmp_timing;

      curr_timing->ind = data->ind;
      curr_timing->period = timespec_to_usec(&data->period);
      curr_timing->min_et = timespec_to_usec(&data->min_et);
      curr_timing->max_et = timespec_to_usec(&data->max_et);
      curr_timing->rel_start_time = 
        t_start_usec - timespec_to_usec(&data->main_app_start);
      curr_timing->abs_start_time = t_start_usec;
      curr_timing->end_time = timespec_to_usec(&t_end);
      curr_timing->deadline = timespec_to_usec(&data->deadline);
      curr_timing->duration = timespec_to_usec(&t_diff);
      curr_timing->slack =  timespec_to_lusec(&t_slack);
      curr_timing->resp_time =  timespec_to_usec(&t_resp);
    }
    if (!timings)
      log_timing(data->log_handler, curr_timing);

    t_next = timespec_add(&t_next, &data->period);
    data->deadline = timespec_add(&data->deadline, &data->period);
#ifdef TRACE_END_LOOP
    if (opts.ftrace)
      log_ftrace(ft_data.marker_fd, "[%d] end loop %d", data->ind, i);
#endif
    if (curr_timing->slack < 0)
      log_notice("[%d] DEADLINE MISS !!!", data->ind+1);
    i++;
  }

  free(timings);
}
示例#23
0
bool PhTimeCodeEdit::eventFilter(QObject *, QEvent *event)
{
	switch (event->type()) {
	case QEvent::KeyPress:
		{
			QKeyEvent *keyEvent = (QKeyEvent*)event;
			switch (keyEvent->key()) {
			case Qt::Key_0:
			case Qt::Key_1:
			case Qt::Key_2:
			case Qt::Key_3:
			case Qt::Key_4:
			case Qt::Key_5:
			case Qt::Key_6:
			case Qt::Key_7:
			case Qt::Key_8:
			case Qt::Key_9:
				_addedNumbers.push(keyEvent->key());
				compute(true);
				return true;
			case Qt::Key_Backspace:
				if(_addedNumbers.length()) {
					_addedNumbers.pop();
					compute(false);
				}
				return true;
			case Qt::Key_Escape:
			case Qt::Key_Enter:
			case Qt::Key_Return:
				return false;
			default:
				return true;
			}
		}
	case QEvent::MouseButtonPress:
		QApplication::setOverrideCursor(Qt::SizeVerCursor);
		_mousePressed = true;
		_mousePressedLocation = static_cast<QMouseEvent *>(event)->pos();
		_selectedIndex = (cursorPositionAt(_mousePressedLocation) / 3) * 3;

		return true;
	case QEvent::MouseButtonRelease:
		QApplication::setOverrideCursor(Qt::ArrowCursor);
		_mousePressed = false;
		return true;
	case QEvent::MouseMove:
		{
			if(_mousePressed) {
				int y = static_cast<QMouseEvent *>(event)->pos().y();
				PhFrame currentFrame = PhTimeCode::frameFromString(this->text(), _tcType);
				PhFrame fps = PhTimeCode::getFps(_tcType);

				PhFrame offset = 0;
				switch(_selectedIndex) {
				case 0:
					offset = fps * 60 * 60;
					break;
				case 3:
					offset = fps * 60;
					break;
				case 6:
					offset = fps;
					break;
				case 9:
					offset = 1;
					break;
				}
				if(_mousePressedLocation.y() > y)
					currentFrame += offset;
				else
					currentFrame -= offset;

				_mousePressedLocation.setY(y);
				this->setText(PhTimeCode::stringFromFrame(currentFrame, _tcType));

				if(text().contains("-"))
					setSelection(_selectedIndex + 1, 2);
				else
					setSelection(_selectedIndex, 2);

				return true;
			}
			return false;
		}

	default:
		return false;
	}
}
示例#24
0
//Compute the Derivatives
void computeDeriv(double R,double Z, double phi,
		  double t,
		  struct potentialArg * potentialArgs, double * F)
{
    double * args= potentialArgs->args;
    //Get args
    double a = *args++;
    int isNonAxi = (int)*args++;
    int N = *args++;
    int L = *args++;
    int M = *args++;
    double* Acos = args;

    double * caching_i = (args + (isNonAxi + 1)*N*L*M);
    double *Asin;
    if (isNonAxi == 1)
    {
        Asin = args + N*L*M;
    }

    double *cached_type = caching_i;
    double * cached_coords = (caching_i+ 1);
    double * cached_values = (caching_i + 4);
    if ((int)*cached_type==DERIV)
    {
        if (*cached_coords == R && *(cached_coords + 1) == Z && *(cached_coords + 2) == phi)
        {
            *F = *cached_values;
            *(F + 1) = *(cached_values + 1);
            *(F + 2) = *(cached_values + 2);
            return;
        }
    }

    double r;
    double theta;
    cyl_to_spher(R, Z, &r, &theta);

    double xi;
    calculateXi(r, a, &xi);

//Compute the gegenbauer polynomials and its derivative.
    double C[N*L];
    double dC[N*L];
    double d2C[N*L];

    compute_C(xi, N, L, &C);
    compute_dC(xi, N, L, &dC);
    compute_d2C(xi, N, L, &d2C);

//Compute phiTilde and its derivative
    double phiTilde[L*N];
    compute_phiTilde(r, a, N, L, &C, &phiTilde);

    double dphiTilde[L*N];
    compute_dphiTilde(r, a, N, L, &C, &dC, &dphiTilde);

    double d2phiTilde[L*N];
    compute_d2phiTilde(r, a, N, L, &C, &dC, &d2C, &d2phiTilde);


//Compute Associated Legendre Polynomials
    int M_eff = M;
    int size = 0;
    
    if (isNonAxi==0)
    {
    M_eff = 1;
    size = L;    
    } else{
    size = L*L - L*(L-1)/2;
    }
    double P[size];


    compute_P(cos(theta), L,M_eff, &P);



    int num_eq = 3;


    double (*PhiTilde_Pointer[3]) = {&d2phiTilde, &phiTilde, &dphiTilde};
    double (*P_Pointer[3]) = {&P, &P, &P};

    double Constant[3] = {1., 1., 1.};

    if (isNonAxi==1)
    {
        double (*Eq[3])(double, double, double, double, double, double, int) = {&computeF_rr, &computeF_phiphi, &computeF_rphi};
        equations e = {Eq,&PhiTilde_Pointer, &P_Pointer, &Constant};
        computeNonAxi(a, N, L, M,r, theta, phi, Acos, Asin, 3, e, F);
    }
    else
    {
        double (*Eq[3])(double, double, double) = {&computeAxiF_rr, &computeAxiF_phiphi, &computeAxiF_rphi};
        axi_equations e = {Eq,&PhiTilde_Pointer, &P_Pointer, &Constant};
        compute(a, N, L, M,r, theta, phi, Acos, 3, e, F);
    }


    //Caching

    *cached_type = (double)DERIV;

    * cached_coords = R;
    * (cached_coords + 1) = Z;
    * (cached_coords + 2) = phi;
    * (cached_values) = *F;
    * (cached_values + 1) = *(F + 1);
    * (cached_values + 2) = *(F + 2);

}
 void SingleChannelHistogram::compute(
   const sensor_msgs::Image::ConstPtr& msg)
 {
   compute(msg, sensor_msgs::Image::ConstPtr());
 }
示例#26
0
//Compute the Potential
double SCFPotentialEval(double R,double Z, double phi,
                        double t,
                        struct potentialArg * potentialArgs)
{
    double * args= potentialArgs->args;
    //Get args
    double a = *args++;
    int isNonAxi = (int)*args++;
    int N = *args++;
    int L = *args++;
    int M = *args++;
    double* Acos = args;
    double* Asin;
    if (isNonAxi==1) //LCOV_EXCL_START
    {
        Asin = args + N*L*M;
    } //LCOV_EXCL_STOP
    //convert R,Z to r, theta
    double r;
    double theta;
    cyl_to_spher(R, Z,&r, &theta);
    double xi;
    calculateXi(r, a, &xi);

    //Compute the gegenbauer polynomials and its derivative.
    double C[N*L];

    compute_C(xi, N, L, &C);

    //Compute phiTilde and its derivative
    double phiTilde[L*N];
    compute_phiTilde(r, a, N, L, &C, &phiTilde);
    //Compute Associated Legendre Polynomials

    int M_eff = M;
    int size = 0;
    
    if (isNonAxi==0)
    {
    M_eff = 1;
    size = L;    
    } else{ //LCOV_EXCL_START
    size = L*L - L*(L-1)/2;
    } //LCOV_EXCL_STOP
    
    double P[size];


    compute_P(cos(theta), L,M_eff, &P);

    double potential;

    int num_eq = 1;


    double (*PhiTilde_Pointer[1]) = {&phiTilde};
    double (*P_Pointer[1]) = {&P};

    double Constant[1] = {1.};

    if (isNonAxi==1) //LCOV_EXCL_START
    {
        double (*Eq[1])(double, double, double, double, double, double, int) = {&computePhi};
        equations e = {Eq,&PhiTilde_Pointer, &P_Pointer, &Constant};
        computeNonAxi(a, N, L, M,r, theta, phi, Acos, Asin, 1, e, &potential);
    } //LCOV_EXCL_STOP
    else
    {
        double (*Eq[1])(double, double, double) = {&computeAxiPhi};
        axi_equations e = {Eq,&PhiTilde_Pointer, &P_Pointer, &Constant};
        compute(a, N, L, M,r, theta, phi, Acos, 1, e, &potential);
    }

    return potential;
}
示例#27
0
HelloWorld::HelloWorld()
{
    r1 = r2 = 0;
    compute();
}
示例#28
0
Form::Form()
{
	this->setObjectName(QString::fromUtf8("Form"));
	this->resize(QSize(370, 139).expandedTo(this->minimumSizeHint()));
	validator = new QDoubleValidator(this);
	
	widget = new QWidget(this);
	widget->setObjectName(QString::fromUtf8("widget"));
	widget->setGeometry(QRect(10, 50, 351, 26));
	hboxLayout = new QHBoxLayout(widget);
	hboxLayout->setSpacing(6);
	hboxLayout->setMargin(0);
	hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
	lineEdit_a = new QLineEdit(widget);
	lineEdit_a->setObjectName(QString::fromUtf8("lineEdit_a"));
	lineEdit_a->setValidator(validator);

	hboxLayout->addWidget(lineEdit_a);

	comboBox = new QComboBox(widget);
	comboBox->setObjectName(QString::fromUtf8("comboBox"));

	hboxLayout->addWidget(comboBox);
	lineEdit_b = new QLineEdit(widget);
	lineEdit_b->setObjectName(QString::fromUtf8("lineEdit_b"));
	lineEdit_b->setValidator(validator);

	hboxLayout->addWidget(lineEdit_b);

	label_eauql = new QLabel(widget);
	label_eauql->setObjectName(QString::fromUtf8("label_eauql"));

	hboxLayout->addWidget(label_eauql);

	lineEdit_c = new QLineEdit(widget);
	lineEdit_c->setObjectName(QString::fromUtf8("lineEdit_c"));
	lineEdit_c->setReadOnly(true);
	
	hboxLayout->addWidget(lineEdit_c);

	layoutWidget = new QWidget(this);
	layoutWidget->setObjectName(QString::fromUtf8("layoutWidget"));
	layoutWidget->setGeometry(QRect(100, 100, 182, 30));
	hboxLayout1 = new QHBoxLayout(layoutWidget);
	hboxLayout1->setSpacing(6);
	hboxLayout1->setMargin(0);
	hboxLayout1->setObjectName(QString::fromUtf8("hboxLayout1"));
	pushButton_ok = new QPushButton(layoutWidget);
	pushButton_ok->setObjectName(QString::fromUtf8("pushButton_ok"));

	hboxLayout1->addWidget(pushButton_ok);

	pushButton_close = new QPushButton(layoutWidget);
	pushButton_close->setObjectName(QString::fromUtf8("pushButton_close"));

	hboxLayout1->addWidget(pushButton_close);

	label_compute = new QLabel(this);
	label_compute->setObjectName(QString::fromUtf8("label_compute"));
	label_compute->setGeometry(QRect(10, 20, 71, 16));
	retranslateUi();
	QObject::connect(pushButton_close, SIGNAL(clicked()), this, SLOT(close()));
	QObject::connect(pushButton_ok, SIGNAL(clicked()), this, SLOT(compute()));

	QMetaObject::connectSlotsByName(this);

} // setupUi
double StandardUptakeValueMeasureHandler::computePreferredFormula(double activityConcentrationValueInImageUnits)
{
    return compute(activityConcentrationValueInImageUnits, getPreferredFormula());
}
示例#30
0
 bool HashFunction::verify(const std::string& msg,
                           const std::string& salt,
                           const std::string& hash) const
 {
     return compute(msg, salt) == hash;
 }