예제 #1
0
void ConditionManager::buildDependencies()
{
    for (const auto &pair : condEntries)
    {
        const ConditionEntry &entry = pair.second;
        if (entry.condTrigger == nullptr)
        {
            util::Debug() << "Undefined object " << pair.first;
            continue;
        }

        entry.condTrigger->setDelay(entry.del);
        if (entry.cond1 == 0)
        {
            if (entry.cond2 != 0)
                util::Debug() << "Abnormal condition " << pair.first;
            continue;
        }

        initCondition(entry.cond1, entry.dep1, entry.ref1, entry.condTrigger);
        if (entry.cond2 != 0)
            initCondition(entry.cond2, entry.dep2, entry.ref2, entry.condTrigger);
        entry.condTrigger->setLimit(entry.cond2 != 0 && entry.op == 0 ? 2 : 1);
        if (entry.op != 0 && entry.op != 1)
            util::Debug() << "Unhandled condition operation " << entry.op;
    }
    for (const auto &pair : condEntries)
        if (pair.second.condTrigger)
            pair.second.condTrigger->tryComplete();
}
예제 #2
0
int main(int argc, char **argv){

  // Archivo para imprimir las evolucion de u
  FILE *data = fopen("Navier-Stokes_LinearConvection.dat", "w");
  
  // Numero de iteraciones en espacio y tiempo y sus respectivos dt, dx
  int n_x = atoi(argv[1]);
  int n_t = atoi(argc[2]);
  FLOAT dx = 2.0/(nx-1);
  FLOAT dt = 0.001;
    
  
  // Condicion inicial
  FLOAT *x0 = malloc(n_x*sizeof(FLOAT));
  int j;
  for( j = 0; j < n_x; j++){
    x0[0] = j*dx;
  }

  // Constante c de la ecuacion diferencial de Linear convection
 
  // Vector de evolucion de la velocidad u del fluido
  FLOAT *u = malloc(n_x *sizeof(FLOAT));
  int i;
  u[i] = malloc(n_x*sizeof(FLOAT));
  for( j = 0; j < n_x; j++ ){
    u[j] = 1.0;
  }
  
  // Inicializa las condiciones iniciales en el vector u
  initCondition(u,x0,n_x);

  // Imprimir u
  for( i = 0; i < n_x-1; i++){
    fprintf(data, "%f ", (float) u[i]);
  }
  fprintf(data, "%f\n", (float) u[i]);

  // Actualiza la funcion u
  for( j= 0; j < n_t; j++){
    updateFunc(u,x0,n_x,dx,dt);
    // Imprimir la funcion u
    for( i = 0; i < n_x-1; i++){
      fprintf(data, "%f ", (float) u[i]);
    }
    fprintf(data, "%f\n", (float) u[i]);
   }
  return 0;
}
예제 #3
0
파일: Task.c 프로젝트: Eufavn/ghc
static Task*
newTask (rtsBool worker)
{
    Task *task;

#define ROUND_TO_CACHE_LINE(x) ((((x)+63) / 64) * 64)
    task = stgMallocBytes(ROUND_TO_CACHE_LINE(sizeof(Task)), "newTask");
    
    task->cap           = NULL;
    task->worker        = worker;
    task->stopped       = rtsFalse;
    task->running_finalizers = rtsFalse;
    task->n_spare_incalls = 0;
    task->spare_incalls = NULL;
    task->incall        = NULL;
    
#if defined(THREADED_RTS)
    initCondition(&task->cond);
    initMutex(&task->lock);
    task->wakeup = rtsFalse;
#endif

    task->next = NULL;

    ACQUIRE_LOCK(&all_tasks_mutex);

    task->all_prev = NULL;
    task->all_next = all_tasks;
    if (all_tasks != NULL) {
        all_tasks->all_prev = task;
    }
    all_tasks = task;

    taskCount++;
    if (worker) {
        workerCount++;
        currentWorkerCount++;
        if (currentWorkerCount > peakWorkerCount) {
            peakWorkerCount = currentWorkerCount;
        }
    }
    RELEASE_LOCK(&all_tasks_mutex);

    return task;
}
예제 #4
0
파일: Task.c 프로젝트: ForkBackups/ghc
void
discardTasksExcept (Task *keep)
{
    Task *task, *next;

    // Wipe the task list, except the current Task.
    ACQUIRE_LOCK(&all_tasks_mutex);
    for (task = all_tasks; task != NULL; task=next) {
        next = task->all_next;
        if (task != keep) {
            debugTrace(DEBUG_sched, "discarding task %" FMT_SizeT "", (size_t)TASK_ID(task));
#if defined(THREADED_RTS)
            // It is possible that some of these tasks are currently blocked
            // (in the parent process) either on their condition variable
            // `cond` or on their mutex `lock`. If they are we may deadlock
            // when `freeTask` attempts to call `closeCondition` or
            // `closeMutex` (the behaviour of these functions is documented to
            // be undefined in the case that there are threads blocked on
            // them). To avoid this, we re-initialize both the condition
            // variable and the mutex before calling `freeTask` (we do
            // precisely the same for all global locks in `forkProcess`).
            initCondition(&task->cond);
            initMutex(&task->lock);
#endif

            // Note that we do not traceTaskDelete here because
            // we are not really deleting a task.
            // The OS threads for all these tasks do not exist in
            // this process (since we're currently
            // in the child of a forkProcess).
            freeTask(task);
        }
    }
    all_tasks = keep;
    keep->all_next = NULL;
    keep->all_prev = NULL;
    RELEASE_LOCK(&all_tasks_mutex);
}
예제 #5
0
파일: Pthread.c 프로젝트: AaronFriel/ghc
void
initTicker (Time interval, TickProc handle_tick)
{
    itimer_interval = interval;
    stopped = 0;
    exited = 0;

    initCondition(&start_cond);
    initMutex(&mutex);

    /*
     * We can't use the RTS's createOSThread here as we need to remain attached
     * to the thread we create so we can later join to it if requested
     */
    if (! pthread_create(&thread, NULL, itimer_thread_func, (void*)handle_tick)) {
#if defined(HAVE_PTHREAD_SETNAME_NP)
        pthread_setname_np(thread, "ghc_ticker");
#endif
    } else {
        sysErrorBelch("Itimer: Failed to spawn thread");
        stg_exit(EXIT_FAILURE);
    }
}
int main( int argc, char** argv ){
  
  printf("%f %f\n", alpha , dt);

  //---------------------------
  // Declaración de Constantes
  //---------------------------
   
  //Número de iteraciones en el tiempo
  int nt = atoi(argv[1]);
  
  // Archivo de texto de evolucion 
  FILE *in = fopen("datos.dat","w");
  
  // Contadores
  int i;
  int j;
  
  // Espacio
  FLOAT *x0 = malloc(nx*sizeof(FLOAT));

  // Funcion de onda actual
  FLOAT *Im_p = malloc(nx*sizeof(FLOAT));
  FLOAT *Re_p = malloc(nx*sizeof(FLOAT));

  //-------------------------------
  // Solucion de la ED
  //-------------------------------
  
  // Llena el vector de posicion
  for( i = 0; i < nx; i++ ){
    x0[i] = x_min + i*dx;
  }

  // Condicion inicial ( y de frontera )
  initCondition( Re_p, Im_p, x0, nx );

  // Imprime la condicion inicial
  FLOAT ro = 0;
  fprintf(in, "%f %f ", (float) x0[0], 0.0); 
  for( i = 1; i < nx-1; i += (int) (nx-1)/imprx ){
    ro = Im_p[i]*Im_p[i] + Re_p[i]*Re_p[i];
    //printf("%f\n", ro, (float) ro);
    fprintf(in, "%f %f ", (float) x0[i], (float) ro); 
  }
  fprintf(in, "%f %f\n", (float) x0[nx-1], 0.0); 
  
  // Iteracion sobre el tiempo (se tiene que doblar el numero de pasos debido a la definicion de Re e Im en enteros y semienteros de tiempo)
  for( j = 0; j < 2*nt; j++ ){
    //printf("%d\n", j);
    // Actualiza los vectores dependiendo del step de tiempo
    if( j%2 == 0 ){
      // Copia RE
      FLOAT* tempR = malloc(nx*sizeof(FLOAT));
      memcpy( tempR , Re_p, nx*sizeof(FLOAT) );
      // Calcula el siguiente paso de tiempo para Re
      updateFunc( Re_p, Im_p, x0, nx, 1.0 ); 
      // imprime ro (IM) lolol
      FLOAT ro = 0;
      if( j%impr == 0 ){
	fprintf(in, "%f %f ", (float) x0[0], 0.0); 
      }
      for( i = 1; i < nx-1; i += (int) (nx-1)/imprx ){
	ro = Im_p[i]*Im_p[i] + tempR[i]*Re_p[i];
	if( j%impr == 0 ){
	  //printf("%f\n", ro, (float) ro);
	  fprintf(in, "%f %f ", (float) x0[i], (float) ro); 
	}   
      }
      if( j%impr == 0 ){
	fprintf(in, "%f %f\n", (float) x0[nx-1], 0.0); 
      }
      // Liberar memoria de la copia
      free( tempR );
    }
    else{
      // Copia IM
      FLOAT* tempI = malloc(nx*sizeof(FLOAT));
      memcpy( tempI , Im_p, nx*sizeof(FLOAT) );
      // Calcula el siguiente paso de tiempo para Im
      updateFunc( Im_p, Re_p, x0, nx, -1.0 ); 
      // imprime ro (RE) lolol
      FLOAT ro = 0;
      if( j%impr == 0 ){
	fprintf(in, "%f %f ", (float) x0[0], 0.0); 
      }
      for( i = 1; i < nx-1;  i += (int) (nx-1)/imprx ){
	ro = Re_p[i]*Re_p[i] + tempI[i]*Im_p[i];
	if( j%impr == 0 ){
	  fprintf(in, "%f %f ", (float) x0[i], (float) ro); 
	}
      }   
      if( j%impr == 0 ){
	fprintf(in, "%f %f\n", (float) x0[nx-1], 0.0); 
      }
      // Liberar memoria de la copia
      free( tempI );
    }
  }
  return 0;
}
예제 #7
0
int main(int argc, char **argv){

  // Archivo para imprimir las evolucion de u
  FILE *data = fopen("Wave_Eq.dat", "w");
  
  // Numero de iteraciones en espacio y tiempo y sus respectivos dt, dx
  int n_x = atoi(argv[1]);
  int n_t = atoi(argv[2]);
  //printf("%d \n", n_x );
  FLOAT dx = L/(n_x-1);
  //printf("%f %d \n", L, n_x );
  FLOAT dt = 2.0;
  // Parámetro de estabilidad (debe ser menor que 1)
  FLOAT r = c*(dt/dx);
  printf("%f \n", r);
  
  // Vector de posicion
  FLOAT *x0 = malloc(n_x*sizeof(FLOAT));
  int j;
  for( j = 0; j < n_x; j++){
    x0[j] = j*dx;
  }

  // Vector actual de la funcion de onda
  FLOAT *present_u = malloc(n_x *sizeof(FLOAT));
  int i;
  present_u = malloc(n_x*sizeof(FLOAT));
  
  // Condicion inicial
  initCondition(present_u,x0,n_x,dx);

  // Condiciones de frontera
  present_u[0] = 0;
  present_u[n_x-1] = 0;
  
  // Vector futuro de la funcion de onda
  FLOAT *future_u = malloc(n_x *sizeof(FLOAT));
  future_u = malloc(n_x*sizeof(FLOAT));

  // Condiciones de frontera
  future_u[0] = 0;
  future_u[n_x-1] = 0;

  // Calcula el primer valor de future_u
  for( i = 1; i < n_x-1; i++){
    future_u[i] = present_u[i] + (r*r/2.0) * (present_u[i+1] - 2.0 * present_u[i] + present_u[i-1]);
  }

  // Imprime la condicion inicial ( present_ u )
  for( i = 0; i < n_x-1; i++){
    fprintf(data, "%f ", (float) present_u[i]);
  }
  fprintf(data, "%f\n", (float) present_u[i]);

  // Calcula el siguiente valor de present_u y future_u
  for( j= 0; j < n_t; j++){
    updateFunc(present_u,future_u,x0,n_x,r);
    // Imprimir la funcion u
    for( i = 0; i < n_x-1; i++){
      fprintf(data, "%f ", (float) present_u[i]);
    }
    fprintf(data, "%f\n", (float) present_u[i]);
   }
  return 0;
}