コード例 #1
0
ファイル: 100.c プロジェクト: rollen/uva
void testComputation(){
  assert(4 == computation(1));
  assert(2 == computation(4));
  assert(10 == computation(20));
  assert(5 == computation(10));
  assert(16 == computation(5));
  assert(8 == computation(16));
  assert(4 == computation(8));
  assert(2 == computation(4));
  assert(1 == computation(2));
}
コード例 #2
0
Renewal::Renewal(const RenewalData &irenewal_data , const DiscreteParametric &iinter_event)

{
  int i;
  int nb_value;


  nb_iterator = 0;
  renewal_data = new RenewalData(irenewal_data);
  renewal_data->type = EQUILIBRIUM;

  type = EQUILIBRIUM;

  time = new Distribution(*(renewal_data->htime));

  inter_event = new DiscreteParametric(iinter_event);
  length_bias = new LengthBias(*inter_event);
  backward = new Backward(inter_event->nb_value - 1 , inter_event->ident ,
                          inter_event->inf_bound , inter_event->sup_bound ,
                          inter_event->parameter , inter_event->probability);
  forward = new Forward(*inter_event);

  nb_event = new NbEvent*[time->nb_value];

  for (i = 0;i < time->offset;i++) {
    nb_event[i] = NULL;
  }
  for (i = time->offset;i < time->nb_value;i++) {
    if (time->mass[i] > 0.) {
      switch (type) {
      case ORDINARY :
        nb_value = i / inter_event->offset + 1;
        break;
      case EQUILIBRIUM :
        nb_value = (i - 1) / inter_event->offset + 2;
        break;
      }

      nb_event[i] = new NbEvent(type , i , nb_value , inter_event->ident ,
                                inter_event->inf_bound , inter_event->sup_bound ,
                                inter_event->parameter , inter_event->probability);
    }

    else {
      nb_event[i] = NULL;
    }
  }

  mixture = new Distribution(nb_value);

  nb_event_max = nb_value - 1;
  nevent_time = new DiscreteParametric*[nb_event_max + 1];
  for (i = 0;i <= nb_event_max;i++) {
    nevent_time[i] = NULL;
  }

  index_event = new Curves(2 , time->nb_value);

  computation(false);
}
コード例 #3
0
NbEvent::NbEvent(process_type itype , int itime , DiscreteParametric &inter_event)

{
  type = itype;
  time = itime;

  switch (type) {
  case ORDINARY :
    Distribution::init(time / inter_event.offset + 1);
    break;
  case EQUILIBRIUM :
    Distribution::init((time - 1) / inter_event.offset + 2);
    break;
  }

  ident = inter_event.ident;

  inf_bound = inter_event.inf_bound;
  sup_bound = inter_event.sup_bound;
  parameter = inter_event.parameter;
  probability = inter_event.probability;

  switch (type) {
  case ORDINARY :
    ordinary_computation(inter_event);
    break;
  case EQUILIBRIUM :
    computation(inter_event);
    break;
  }
}
コード例 #4
0
ファイル: timedloop.c プロジェクト: timed-c/kta
int main(int args, char **argv)
{
  
  int v;
  int i;
  int first = 1;
  int k = 2;
  
  int period = 10000;

  long x = get_time();
 
  for(;;){

    if(!first){
      delay_until(x);
      mtfd_end();
    }

    mtfd_begin(period);    
    if(!first)
      actuating(k);  
    v = sensing();  
    x += period;    
    k = computation(v);      
    first = 0;
  }

  // The interesting thing is that the final code
  // includes to call to pret_mt

  return k;
}
コード例 #5
0
// function to evaluate expression
float evaluate(char *exp, int value){
	int exp_length = strlen(exp);
    //evaluate postfix function
    infix_to_postfix(exp);
    //printf("%s\n",postfix);
    int i=0,to=-1;
    float result;
    float arr[100];
    int length = strlen(postfix);
    while(length > 0){
        if(postfix[i] =='+' || postfix[i] =='-' || postfix[i] =='*' || postfix[i] =='/' || postfix[i] =='^'){
            float secondOperand=arr[to--];
            float firstOperand=arr[to--];
            char operator=postfix[i];
            result = computation(firstOperand,operator,secondOperand);
            //printf("result%f\n",result);
            arr[++to] = result;
            i++;     
        }
        else{
            if(postfix[i] == 'x' || postfix[i] == 'y') arr[++to]= value;
            else  arr[++to] = postfix[i] - '0';
            i++; 
        }
        length--;
    }
    return arr[to];
}
コード例 #6
0
int main() {
	int cpu_model = detect_cpu();
	if (cpu_model < 0) {
		printf("Unsupported CPU type\n");
		return -1;
	}

	int core0 = msr_open(0);
	int core1 = msr_open(1);

	PETU_t pet0 = msr_calculate_units(core0);
	PETU_t pet1 = msr_calculate_units(core1);

	PackagePowerInfo_t ppi0 = msr_get_package_power_info(core0, &pet0);
	PackagePowerInfo_t ppi1 = msr_get_package_power_info(core1, &pet1);

	printf("PP Core 0: %.3f %.3f\n", ppi0.minimum_power, ppi0.maximum_power);
	printf("PP Core 1: %.3f %.3f\n", ppi1.minimum_power, ppi1.maximum_power);

	printf("Computation begins\n");
	double e0 = msr_get_package_energy(core0, &pet0);
	double e1 = msr_get_package_energy(core1, &pet1);

	computation();

	e0 = msr_get_package_energy(core0, &pet0) - e0;
	e1 = msr_get_package_energy(core1, &pet1) - e1;
	printf("Computation ends\n");

	printf("Energy consumed: Core 0: %.3fJ\n", e0);
	printf("Energy consumed: Core 1: %.3fJ\n", e1);

	return 0;
}
コード例 #7
0
ファイル: 100.c プロジェクト: rollen/uva
int numberOfCounts(int n){
  int count = 1;
  while( n != 1 ){
    n = computation(n);
    count++;
  }
  return count;
}
コード例 #8
0
ファイル: main.cpp プロジェクト: satorikomeiji/HeatEquation
int main(int argc, const char * argv[]) {
    
    
    Settings settings;
    HeatTransferComputation computation(settings);
    computation.eval();
    computation.outputSolution();
    
    return 0;
}
コード例 #9
0
double cached_computation(double x){                // (2)
	static double cached_x = 0.0;
	static double cached_result = COMPUTATION_OF_ZERO;
	double result;
    {
        std::lock_guard<std::mutex> lck(m);
		if (cached_x == x) return cached_result;
		result = computation(x);
		cached_x = x;
		cached_result = result;
    }
	return result;
}
コード例 #10
0
ファイル: compound.cpp プロジェクト: pradal/StructureAnalysis
Compound::Compound(const DiscreteParametric &sum_dist , const DiscreteParametric &dist ,
                   double cumul_threshold)

{
  compound_data = NULL;

  sum_distribution = new DiscreteParametric(sum_dist , NORMALIZATION);
  distribution = new DiscreteParametric(dist , NORMALIZATION);

  Distribution::init((sum_distribution->nb_value - 1) * (distribution->nb_value - 1) + 1);

  computation(1 , cumul_threshold , false , false);
}
コード例 #11
0
ファイル: bubblesort.c プロジェクト: tudinfse/elzar
int main() {
    int i, j;

    int size = sizeof(a_l)/sizeof(int);
    for (j = 0; j < size; j++)
    {
        a_l[j] = rand() % MAXRANDINT;
    }

    precomputation();
    computation(3, size);
    postcomputation();

    return 0;
}
コード例 #12
0
ファイル: example12_species.c プロジェクト: tue-es/bones
// This is 'example12', demonstrating a classification in another function
int main(void) {
	int i;
	
	// Declare input/output arrays
	int* A = (int*)malloc(128*sizeof(int));
	int* B = (int*)malloc(128*sizeof(int));
	
	// Set the input data
	for(i=0;i<128;i++) {
		A[i] = i+3;
		B[i] = 999;
	}
	int constant = 3;
	
	// Call the computation function
	computation(A,B,constant);
	
	// Clean-up and exit the function
	free(A);
	free(B);
	fflush(stdout);
	return 0;
}
コード例 #13
0
float evaluation(char *exp1,int valueOFVariable){
	//define variables
char exp[] = {'(','3','^','2',')','+','4','*','(','3','-','3',')'};
    
	length =strlen(exp);
	while(length > 0){
		if(exp[i]==' '){  // to avoid space
			i++;length--;
			continue;
		}
		num1=0;
		num2=0;
		temp = exp[i];
		i++; length--;
		if(temp == '('){
			result = subFunction(valueOFVariable);
			array_store[++index] = result;
		}

		printf("\nResult after paran loop = %f, exp[i] = %c",array_store[index],exp[i]);
        
		if(isdigit(temp) || temp == 'x' || temp == 'y'){
			if(temp == 'x' || temp == 'y')    
				num1 = valueOFVariable;
			else
				num1 = temp - '0';
			length--;
			while(isdigit(exp[i])){
				number = exp[i] - '0';
				num1 = num1 * 10 + number;
				length--;
				i++;
			}// to get whole number
			array_store[++index] = num1;
		}// if close
		else{
			operator=temp;
			if(isdigit(exp[i]) || exp[i] == 'x' || exp[i] == 'y') {
				if(exp[i] == 'x' || exp[i] == 'y')    
					num2 = valueOFVariable;
				else
					num2 = exp[i] - '0';
				length--;
				i=i+1;
				while(isdigit(exp[i])){
					number = exp[i] - '0';
					num2 = num2 * 10 + number;
					length--;
					i++;
				}// to get whole number
			}// if close
			else if(isdigit(exp[i]) == '('){
				num2 = subFunction(valueOFVariable);
				//array_store[++index] = result;
			}
        	if(array_store[index]){
				num1 = array_store[index--];
			}
			#ifdef DEBUG
					printf("\nnum1 = %f, operator = %c, num2 = %f",num1,operator,num2);
			#endif
			result = computation(num1, operator, num2);
			array_store[++index] = result;
			//printf("%f, index = %d\n",result,index);
		}//else close

	}//while close
	return array_store[index];
}
コード例 #14
0
float subFunction(int valueOFVariable){
	while(exp[i] != ')'){
				num1=0;
				num2=0;
				temp = exp[i];
				i++; length--;
				#ifdef DEBUG
					printf("\nUnder while temp = %c",temp);
				#endif

				if(isdigit(temp) || temp == 'x' || temp == 'y'){
					if(temp == 'x' || temp == 'y')    
						num1 = valueOFVariable;
					else
						num1 = temp - '0';
					length--;
					while(isdigit(exp[i])){
						number = exp[i] - '0';
						num1 = num1 * 10 + number;
						length--;
						i++;
					}// to get whole number
					array_store[++index] = num1;
				}// if close
				else{
					operator=temp;
					if(isdigit(exp[i]) || exp[i] == 'x' || exp[i] == 'y') {
						if(exp[i] == 'x' || exp[i] == 'y')    
							num2 = valueOFVariable;
						else
							num2 = exp[i] - '0';
						length--;
						i=i+1;
						while(isdigit(exp[i])){
							number = exp[i] - '0';
							num2 = num2 * 10 + number;
							length--;
							i++;
						}// to get whole number
					}// if close
		        	if(array_store[index]){
						num1 = array_store[index--];
					}
					result = computation(num1, operator, num2);
					array_store[++index] = result;
					//printf("%f, index = %d\n",result,index);
				}//else close

				 
				#ifdef DEBUG
					printf("\nAfter while exp = %c",exp[i]);
				#endif
			}
			i++;
			length--;
			temp = exp[i];
			i++;
			length--;


return array_store[index];
}
コード例 #15
0
/**
 * @fn int CacheMissComputation::computation(FrameWork *ws, AST *ast);
 * Compute the number of Miss for each AST node by using annotations coming from other modules. 
 * Furthermore put annotations (ETS::MISSES) of each AST node.
 * @param ws	Container framework.
 * @param ast	AST to process.
 * @return Miss of the current AST.
 */
int CacheMissComputation::computation(WorkSpace *ws, AST *ast){
	int misses;
	switch (ast->kind()){
		case AST_Call:{	
			ASTInfo *ast_info = ws->getASTInfo();
			Option< FunAST *> fun_res = ast_info->get(ast->toCall()->function()->name());
			if (fun_res){
				AST *fun_ast = (*fun_res)->ast();
				misses = computation(ws, fun_ast);
				MISSES(ast->toCall()) = misses;
				CHC_OUT(cout << "|| " << ast->toCall()->function()->name() << " a pour nb de miss : " << ast->toCall()->use<int>(ETS::ID_MISSES)<< '\n');	
				return MISSES(ast->toCall());
			}
			break;
		}
		case AST_Block: 
			CHC_OUT(cout << "|| " << ast->toBlock()->first()->get<String>(File::ID_Label,"unknown ") << " a pour nb de miss : " << ast->toBlock()->use<int>(ETS::ID_MISSES)<< '\n');
			return MISSES(ast->toBlock()) + CONFLICTS(ast->toBlock());
			break;
		case AST_Seq: {	
			misses = 	computation(ws, ast->toSeq()->child1())
						+ computation(ws, ast->toSeq()->child2());
			MISSES(ast->toSeq()) = misses;
			CHC_OUT(cout << "|| " << ast->toSeq()->first()->get<String>(File::ID_Label,"unknown ") << " a pour nb de miss : " << ast->toSeq()->use<int>(ETS::ID_MISSES)<< '\n');
			return MISSES(ast->toSeq());
			break;
		}
		case AST_If: {
		 	misses = computation(ws, ast->toIf()->elsePart());
			int misses1 = computation(ws, ast->toIf()->thenPart());
			if(misses < misses1)
				MISSES(ast->toIf()) = misses1 + computation(ws, ast->toIf()->condition());
			else
				MISSES(ast->toIf()) = misses + computation(ws, ast->toIf()->condition());
			CHC_OUT(cout << "|| " << ast->toIf()->condition()->first()->get<String>(File::ID_Label,"unknown ") << " a pour nb de miss : " << ast->toIf()->use<int>(ETS::ID_MISSES)<< '\n');
			return MISSES(ast->toIf());
			break;
		}
		case AST_While:	{
			int N = LOOP_COUNT(ast->toWhile());
			
			misses = 	computation(ws, ast->toWhile()->condition())
						+ N
						*( 	computation(ws, ast->toWhile()->condition())
							+ computation(ws, ast->toWhile()->body()));
							
			int misses_coming_from_first_misses =
				FIRST_MISSES(ast->toWhile()->condition())
				+ FIRST_MISSES(ast->toWhile()->body());	
			
			MISSES(ast->toWhile()) = misses + misses_coming_from_first_misses;
			CHC_OUT(cout << "|| " << ast->toWhile()->condition()->first()->get<String>(File::ID_Label,"unknown ") << " a pour nb de miss : " << ast->toWhile()->use<int>(ETS::ID_MISSES)<< '\n');
			return MISSES(ast->toWhile());
			break;
		}
		case AST_For:	{	
			int N = LOOP_COUNT(ast->toFor());
			
			misses = 	computation(ws, ast->toFor()->condition())
						+ computation(ws, ast->toFor()->initialization())
						+ N
						*( 	computation(ws, ast->toFor()->condition())
							+ computation(ws, ast->toFor()->body())
							+ computation(ws, ast->toFor()->incrementation()));
			
			int misses_coming_from_first_misses =
				FIRST_MISSES(ast->toFor()->condition())
				+ FIRST_MISSES(ast->toFor()->body()) 
				+ FIRST_MISSES(ast->toFor()->incrementation());
					
			MISSES(ast->toFor()) = misses + misses_coming_from_first_misses;
			CHC_OUT(cout << "|| " << ast->toFor()->condition()->first()->get<String>(File::ID_Label,"unknown ") << " a pour nb de miss : " << ast->toFor()->use<int>(ETS::ID_MISSES)<< '\n');
			return MISSES(ast->toFor());
			break;
		}
		case AST_DoWhile:	{
			int N = LOOP_COUNT(ast->toDoWhile());
			
			misses = 	computation(ws, ast->toDoWhile()->body())
						+ N
						*( 	computation(ws, ast->toDoWhile()->condition())
							+ computation(ws, ast->toDoWhile()->body()));
							
			int misses_coming_from_first_misses =
				FIRST_MISSES(ast->toDoWhile()->body())
				+ FIRST_MISSES(ast->toDoWhile()->condition());
			
			MISSES(ast->toDoWhile()) = misses + misses_coming_from_first_misses;
			CHC_OUT(cout << "|| " << ast->toDoWhile()->condition()->first()->get<String>(File::ID_Label,"unknown ") << " a pour nb de miss : " << ast->toDoWhile()->use<int>(ETS::ID_MISSES)<< '\n');
			return MISSES(ast->toDoWhile());
			break;
		}
		default :
			return 0;
	}
	return 0;
}
コード例 #16
0
/**
 * @fn void CacheMissComputation::processAST(FrameWork *ws, AST *ast);
 * Get the number of Miss of ast with the recursive function: CacheMissComputation::computation(FrameWork *ws, AST *ast).
 * @param ws	Container framework.
 * @param ast	AST to process.
 */	
void CacheMissComputation::processAST(WorkSpace *ws, AST *ast) {
	/*int tmp =*/ computation(ws, ast);
}
コード例 #17
0
/**
 * @fn int WCETComputation::computation(FrameWork *ws, AST *ast);
 * Compute the WCET for each AST node by using annotations coming from other modules. 
 * Furthermore put annotations (WCET) of each AST node.
 * @param ws	Container workspace.
 * @param ast	AST to process.
 * @return	WCET of the current AST.
 * @exception	io::IOException if one number of iteration of loop or one WCET of function cannot be found.
 */
int WCETComputation::computation(WorkSpace *ws, AST *ast) {
		ASSERT(ast);
		int ELSE, THEN, wcet, N;
		switch(ast->kind()) {
			case AST_Call:{
				ASTInfo *ast_info = ws->getASTInfo();
				Option< FunAST *> fun_res = ast_info->get(ast->toCall()->function()->name());
				if (fun_res){
					AST *fun_ast = (*fun_res)->ast();
					wcet=computation(ws, fun_ast);
					WCET(ast->toCall()) = wcet;
					WC_OUT(cout << "|| " << ast->toCall()->function()->name() << " a pour wcet : " << ast->toCall()->use<int>(ETS::ID_WCET)<< '\n');	
					return wcet;
				}
				else{
					WC_TRACE;
					throw ProcessorException(*this, _
						<< "no wcet for the function : "
						<< ast->toCall()->function()->name());
				}
			}
			case AST_Block:
				WC_OUT(cout << "|| " << ast->toBlock()->first()->get<String>(File::ID_Label,"unknown ") << " a pour wcet : " << ast->toBlock()->use<int>(ETS::ID_WCET)<< '\n');
				return WCET(ast->toBlock());
				break;
			case AST_Seq:
				wcet=computation(ws, ast->toSeq()->child1())
						+ computation(ws, ast->toSeq()->child2());
				WCET(ast->toSeq()) = wcet;
				WC_OUT(cout << "|| " << ast->toSeq()->first()->get<String>(File::ID_Label,"unknown ") << " a pour wcet : " << ast->toSeq()->use<int>(ETS::ID_WCET)<< '\n');
				return wcet;
				break;
			case AST_If:
				THEN=computation(ws, ast->toIf()->condition())
					+ computation(ws, ast->toIf()->thenPart());
				ELSE=computation(ws, ast->toIf()->condition())
					+ computation(ws, ast->toIf()->elsePart());
				if (THEN>ELSE) 
					WCET(ast->toIf()) = THEN;
				else 
					WCET(ast->toIf()) = ELSE;
				WC_OUT(cout << "|| " << ast->toIf()->condition()->first()->get<String>(File::ID_Label,"unknown ") << " a pour wcet : " << ast->toIf()->use<int>(ETS::ID_WCET)<< '\n');
				return WCET(ast->toIf());
				break;
			case AST_While:
			 	N=LOOP_COUNT(ast->toWhile());
			 	if (N == -1){
					WC_TRACE;
					throw ProcessorException(*this, _ << "no loop bound at : "
						<< LABEL(ast->toWhile()->condition()->first())
						<< " ("
						<< ast->toWhile()->condition()->first()->address()
						<< ")");
				}
				wcet=N*(computation(ws, ast->toWhile()->condition())
							+ computation(ws, ast->toWhile()->body()))
						+ computation(ws, ast->toWhile()->condition());
				WCET(ast->toWhile()) = wcet;
				WC_OUT(cout << "|| " << ast->toWhile()->condition()->first()->get<String>(File::ID_Label,"unknown ") << " a pour wcet : " << ast->toWhile()->use<int>(ETS::ID_WCET)<< '\n');		
				return wcet;
				break;
			case AST_DoWhile:
				N=LOOP_COUNT(ast->toDoWhile());
				if (N == -1){
						WC_TRACE;
						throw io::IOException(_ << "no iteration count for loop"
							<< LABEL(ast->toDoWhile()->condition()->first()) /* "unknown "*/);
				}
				wcet=N*(computation(ws, ast->toDoWhile()->body())
							+ computation(ws, ast->toDoWhile()->condition()));
				WCET(ast->toDoWhile()) = wcet;	
				WC_OUT(cout << "|| " << ast->toDoWhile()->condition()->first()->get<String>(File::ID_Label,"unknown ") << " a pour wcet : " << ast->toDoWhile()->use<int>(ETS::ID_WCET)<< '\n');		
				return wcet;
				break;
			case AST_For:
				N=LOOP_COUNT(ast->toFor());
				if (N == -1){
					WC_TRACE;
					throw io::IOException(_ << "no iteration count for loop "
						<< LABEL(ast->toFor()->condition()->first()) /* "unknown " */);
				}
				wcet=computation(ws, ast->toFor()->initialization())
						+ N*(computation(ws, ast->toFor()->condition())
							+ computation(ws, ast->toFor()->incrementation())
							+ computation(ws, ast->toFor()->body()))
						+ computation(ws, ast->toFor()->condition());
				WCET(ast->toFor()) = wcet;
				WC_OUT(cout << "|| " << ast->toFor()->condition()->first()->get<String>(File::ID_Label,"unknown ") << " a pour wcet : " << ast->toFor()->use<int>(ETS::ID_WCET)<< '\n');	
				return wcet;
				break;
			default:
				WC_OUT(cout << "DEFAULT !!!\n");
				return 0;
		}
}