Example #1
0
File: skyc.c Project: bitursa/maos
/**
   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;
}
Example #2
0
static void
test_make_absfilename_try (void)
{
  char *out;
  char *cwd = mygetcwd ();
  size_t cwdlen = strlen (cwd);

  out = make_absfilename_try ("foo", "bar", NULL);
  if (!out)
    fail (0);
  if (strlen (out) < cwdlen + 7)
    fail (0);
  if (strncmp (out, cwd, cwdlen))
    fail (0);
  if (strcmp (out+cwdlen, "/foo/bar"))
    fail (0);
  xfree (out);

  out = make_absfilename_try ("./foo", NULL);
  if (!out)
    fail (1);
  if (strlen (out) < cwdlen + 5)
    fail (1);
  if (strncmp (out, cwd, cwdlen))
    fail (1);
  if (strcmp (out+cwdlen, "/./foo"))
    fail (1);
  xfree (out);

  out = make_absfilename_try (".", NULL);
  if (!out)
    fail (2);
  if (strlen (out) < cwdlen)
    fail (2);
  if (strncmp (out, cwd, cwdlen))
    fail (2);
  if (strcmp (out+cwdlen, ""))
    fail (2);
  xfree (out);

  xfree (cwd);
}