Esempio n. 1
0
Extern void EXPORT(Vegas)(ccount ndim, ccount ncomp,
                          Integrand integrand, void *userdata, cnumber nvec,
                          creal epsrel, creal epsabs, cint flags, cint seed,
                          cnumber mineval, cnumber maxeval,
                          cnumber nstart, cnumber nincrease,
                          cnumber nbatch, cint gridno,
                          cchar *statefile, Spin **pspin,
                          number *pneval, int *pfail,
                          real *integral, real *error, real *prob)
{
    This t;

    VerboseInit();

    t.ndim = ndim;
    t.ncomp = ncomp;
    t.integrand = integrand;
    t.userdata = userdata;
    t.nvec = nvec;
    t.epsrel = epsrel;
    t.epsabs = epsabs;
    t.flags = MaxVerbose(flags);
    t.seed = seed;
    t.mineval = mineval;
    t.maxeval = maxeval;
    t.nstart = nstart;
    t.nincrease = nincrease;
    t.nbatch = nbatch;
    t.gridno = gridno;
    t.statefile = statefile;
    FORK_ONLY(t.spin = Invalid(pspin) ? NULL : *pspin;)
Esempio n. 2
0
Extern void SUFFIX(cubafork)(Spin **pspin)
{
  char out[128];
  int cores, core;
  fdpid *pfp;
  Spin *spin;

  VerboseInit();

  EnvInit(cubaworkers_.paccel, "CUBAACCELMAX", 1000);
  EnvInit(cubaworkers_.pcores, "CUBACORESMAX", 10000);
  EnvInit(cubaworkers_.naccel, "CUBAACCEL", 0);
  EnvInit(cubaworkers_.ncores, "CUBACORES", -sysconf(_SC_NPROCESSORS_ONLN));

#ifdef HAVE_GETLOADAVG
  if( cubaworkers_.ncores < 0 ) {
    static int load = uninitialized;
    if( load == uninitialized ) {
      double loadavg;
      getloadavg(&loadavg, 1);
      load = floor(loadavg);
    }
    cubaworkers_.ncores = IMax(-cubaworkers_.ncores - load, 0);
  }
#else
  cubaworkers_.ncores = abs(cubaworkers_.ncores);
#endif

  cores = cubaworkers_.naccel + cubaworkers_.ncores;
  if( cores < MINCORES ) {
    *pspin = NULL;
    return;
  }

  if( cubaverb_ ) {
    sprintf(out, "using %d cores %d accelerators via "
#ifdef HAVE_SHMGET
      "shared memory",
#else
      "pipes",
#endif
      cubaworkers_.ncores, cubaworkers_.naccel);
    Print(out);
  }

  fflush(NULL);		/* make sure all buffers are flushed,
			   or else buffered content will be written
			   out multiply, at each child's exit(0) */

  MemAlloc(spin, sizeof *spin + cores*sizeof *spin->fp);
  spin->spec = cubaworkers_;
  pfp = spin->fp;
  for( core = -spin->spec.naccel; core < spin->spec.ncores; ++core ) {
    int fd[2];
    pid_t pid;
    assert(
      socketpair(AF_LOCAL, SOCK_STREAM, 0, fd) != -1 &&
      (pid = fork()) != -1 );
    if( pid == 0 ) {
      close(fd[0]);
      free(spin);
      Child(fd[1], core);
      exit(0);
    }
    MASTER("forked pid %d pipe %d(master) -> %d(worker)",
      pid, fd[0], fd[1]);
    close(fd[1]);
    pfp->fd = fd[0];
    pfp->pid = pid;
    ++pfp;
  }

  *pspin = spin;
}