Beispiel #1
0
int main(int argc, char* argv[])
{
	schd = create_scheduler();
	initialize_scheduler(schd, NULL);

	session_1 = create_session();
	initialize_session(session_1, "222.214.218.237", 6601, "1299880", 0);
	set_session_index(session_1, 0);
	add_session(schd, session_1);

	session_2 = create_session();
	initialize_session(session_2, "222.214.218.237", 6601, "1299880", 1);
	set_session_index(session_2, 1);
	add_session(schd, session_2);

	set_surface_mode(schd->surface, mode_2);

	scheduler_start(schd);
	session_start(session_1);
	session_start(session_2);

	scheduler_wait(schd);

	session_stop(session_1);
	session_stop(session_2);
	destroy_session(session_1);
	destroy_session(session_2);

	return 0;
}
Beispiel #2
0
/**
   The main(). It parses the command line, setup the parms, ask the scheduler
   for signal to proceed, and then starts skysim to do sky coverage.
 */
int main(int argc, const char *argv[]){
    dirstart=mygetcwd();
    char *scmd=argv2str(argc, argv, " ");
    ARG_S* arg=parse_args(argc,argv);
    /*In detach mode send to background and disable drawing*/
    if(arg->detach){
	daemonize();
    }else{
	redirect();
    }
    info2("%s\n", scmd);
    info2("Output folder is '%s'. %d threads\n",arg->dirout, arg->nthread);
    skyc_version();
    /*register signal handler */
    register_signal_handler(skyc_signal_handler);
    /*
      Ask job scheduler for permission to proceed. If no CPUs are available,
      will block until ones are available.  if arg->force==1, will run
      immediately.
    */
    scheduler_start(scmd,arg->nthread,0,!arg->force);
    /*setting up parameters before asking scheduler to check for any errors. */
    dirsetup=stradd("setup",NULL);
    PARMS_S * parms=setup_parms(arg);
    if(parms->skyc.dbg){
	mymkdir("%s",dirsetup);
    }
    if(!arg->force){
	info2("Waiting start signal from the scheduler ...\n");
	/*Failed to wait. fall back to own checking.*/
	int count=0;
	while(scheduler_wait()&& count<60){
	    warning_time("failed to get reply from scheduler. retry\n");
	    sleep(10);
	    count++;
	    scheduler_start(scmd,arg->nthread,0,!arg->force);
	}
	if(count>=60){
	    warning_time("fall back to own checker\n");
	    wait_cpu(arg->nthread);
	}
    }
    info2("Simulation started at %s in %s.\n",myasctime(),myhostname());
    free(scmd);
    free(arg->dirout);
    free(arg);
    THREAD_POOL_INIT(parms->skyc.nthread);
    /*Loads the main software*/
    OMPTASK_SINGLE skysim(parms);
    free_parms(parms);
    free(dirsetup);
    free(dirstart);
    rename_file(0);
    scheduler_finish(0);
    info2("End:\t%.2f MiB\n",get_job_mem()/1024.);
    info2("Simulation finished at %s in %s.\n",myasctime(),myhostname());
    return 0;
}
Beispiel #3
0
__public interrupt_stack_frame* semaphore_p(int sem_id, selector* ldt, selector* ss, dword* esp, interrupt_stack_frame* stack_frame)
{
	semaphore_list[sem_id].semaphore --;
	if(semaphore_list[sem_id].semaphore < 0)
	{
		scheduler_wait(&(semaphore_list[sem_id].waiting_queue_head), &(semaphore_list[sem_id].waiting_queue_tail),
			ldt, ss, esp, stack_frame);
	}
}
Beispiel #4
0
void send_receive(uint16_t to, uint16_t from)
{
    Thread *sender, *receiver, *current = scheduler_current();

    if (to)
    {
        receiver = thread_get(to);

        if (receiver->state != WAIT_RECEIVING ||
            !(receiver->waitingFor == (uint16_t)-1 ||
              receiver->waitingFor == current->tid))
        {
            if (from)
                return scheduler_wait(to, WAIT_SEND_RECV);
            else
                return scheduler_wait(to, WAIT_SENDING);
        }

        deliver(current, receiver);
        scheduler_unblock(receiver);
    }

    if (from)
    {
        if (!list_empty(&current->waitingList))
        {
            sender = list_item(list_pop(&current->waitingList), Thread, queueLink);
            deliver(sender, current);

            if (sender->state == WAIT_SENDING)
                scheduler_unblock(sender);
            else
                sender->state = WAIT_RECEIVING;
        }
        else
            scheduler_wait(from, WAIT_RECEIVING);
    }

    return;
}
Beispiel #5
0
void irq_wait(uint8_t irq)
{
    Thread* current = scheduler_current();
    if (irqThread[irq] != current->tid) return;

    if (irqPending[current->waitingIrq])
        irqPending[current->waitingIrq] = false;
    else
    {
        current->waitingIrq = irq;
        scheduler_wait(0, WAIT_RECEIVING);
    }
}
/// Get the value of the gathering, will wait if the phase is gathering.
static hpx_status_t _alltoall_getid(_alltoall_t *g, unsigned offset, int size,
                                    void *out) {
  hpx_status_t status = HPX_SUCCESS;
  lco_lock(&g->lco);

  // wait until we're reading, and watch for errors
  while ((g->phase != READING) && (status == HPX_SUCCESS)) {
    status = scheduler_wait(&g->lco.lock, &g->wait);
  }

  // if there was an error signal, unlock and return it
  if (status != HPX_SUCCESS) {
    goto unlock;
  }

  // We're in the reading phase, if the user wants data copy it out
  if (size && out) {
    memcpy(out, (char *)g->value + (offset * size), size);
  }

  // update the count, if I'm the last reader to arrive, switch the mode and
  // release all of the other readers, otherwise wait for the phase to change
  // back to gathering---this blocking behavior prevents gets from one "epoch"
  // to satisfy earlier READING epochs
  if (++g->count == g->participants) {
    g->phase = GATHERING;
    scheduler_signal_all(&g->wait);
  }
  else {
    while ((g->phase == READING) && (status == HPX_SUCCESS)) {
      status = scheduler_wait(&g->lco.lock, &g->wait);
    }
  }

 unlock:
  lco_unlock(&g->lco);
  return status;
}
static hpx_status_t _wait(_user_lco_t *u) {
  if (!lco_get_triggered(&u->lco))
    return scheduler_wait(&u->lco.lock, &u->cvar);

  return cvar_get_error(&u->cvar);
}
Beispiel #8
0
/**
   This is the standard entrance routine to the program.  It first calls
   setup_parms() to setup the simulation parameters and check for possible
   errors. It then waits for starting signal from the scheduler if in batch
   mode. Finally it hands the control to maos() to start the actual simulation.

   Call maos with overriding *.conf files or embed the overriding parameters in
   the command line to override the default parameters, e.g.

   <p><code>maos base.conf save.setup=1 'powfs.phystep=[0 100 100]'</code><p>

   Any duplicate parameters will override the pervious specified value. The
   configure file nfiraos.conf will be loaded as the master .conf unless a -c
   switch is used with another .conf file. For scao simulations, call maos with
   -c switch and the right base .conf file.
   
   <p><code>maos -c scao_ngs.conf override.conf</code><p>

   for scao NGS simulations 

   <p><code>maos -c scao_lgs.conf override.conf</code><p>

   for scao LGS simulations.  With -c switch, nfiraos.conf will not be read,
   instead scao_ngs.conf or scao_lgs.conf are read as the master config file.
   Do not specify any parameter that are not understood by the code, otherwise
   maos will complain and exit to prevent accidental mistakes.
       
   Generally you link the maos executable into a folder that is in your PATH
   evironment or into the folder where you run simulations.

   Other optional parameters:
   \verbatim
   -d          do detach from console and not exit when logged out
   -s 2 -s 4   set seeds to [2 4]
   -n 4        launch 4 threads.
   -f          To disable job scheduler and force proceed
   \endverbatim
   In detached mode, drawing is automatically disabled.
   \callgraph
*/
int main(int argc, const char *argv[]){
    char *scmd=argv2str(argc,argv," ");
    ARG_T* arg=parse_args(argc,argv);/*does chdir */
    if(arg->detach){
	daemonize();
    }else{
	redirect();
    }
    /*Launch the scheduler if it is not running and report about our process */
    int ngpu;
#if USE_CUDA
    ngpu=arg->ngpu;
    if(!ngpu) ngpu=0xFFFFFF;
#else
    ngpu=0;
#endif
    scheduler_start(scmd,NTHREAD,ngpu,!arg->force);
    info2("%s\n", scmd);
    info2("Output folder is '%s'. %d threads\n",arg->dirout, NTHREAD);
    maos_version();
    /*setting up parameters before asking scheduler to check for any errors. */
    PARMS_T *parms=setup_parms(arg->conf, arg->confcmd, arg->override);
    free(arg->conf); arg->conf=0;
    if(arg->confcmd){
	remove(arg->confcmd); free(arg->confcmd); arg->confcmd=0;
    }
    info2("After setup_parms:\t %.2f MiB\n",get_job_mem()/1024.);
    /*register signal handler */
    register_signal_handler(maos_signal_handler);
 
    if(!arg->force){
	/*
	  Ask job scheduler for permission to proceed. If no CPUs are
	  available, will block until ones are available.
	  if arg->force==1, will run immediately.
	*/
	info2("Waiting start signal from the scheduler ...\n");
	int count=0;
	while(scheduler_wait()&& count<60){
	    /*Failed to wait. fall back to own checking.*/
	    warning_time("failed to get reply from scheduler. retry\n");
	    sleep(10);
	    count++;
	    scheduler_start(scmd,NTHREAD,ngpu,!arg->force);
	}
	if(count>=60){
	    warning_time("fall back to own checker\n");
	    wait_cpu(NTHREAD);
	}
    }
    thread_new((thread_fun)scheduler_listen, maos_daemon);
    setup_parms_gpu(parms, arg->gpus, arg->ngpu);
    if(arg->server){
	while(maos_server_fd<0){
	    warning("Waiting for fd\n");
	    sleep(1);
	}
	maos_server(parms);
	EXIT;
    }
    free(scmd);
    free(arg->dirout);
    free(arg->gpus);
    free(arg);

    /*do not use prallel single in maos(). It causes blas to run single threaded
     * during preparation. Selective enable parallel for certain setup functions
     * that doesn't use blas*/
    maos(parms);
    rename_file(0);
    scheduler_finish(0);
    return 0;
}