Exemple #1
0
/* Build our triangle mesh from recorded RBFs */
void
build_mesh(void)
{
	int		nrbfs = 0, nmigs = 0;
	double		best2 = M_PI*M_PI;
	RBFNODE		*shrt_edj[2];
	RBFNODE		*rbf0, *rbf1;
	const MIGRATION	*ej;
						/* average specular peak */
	comp_bsdf_spec();
						/* add normal if needed */
	check_normal_incidence();
						/* check if isotropic */
	if (single_plane_incident) {
		for (rbf0 = dsf_list; rbf0 != NULL; rbf0 = rbf0->next)
			if (rbf0->next != NULL)
				create_migration(rbf0, rbf0->next);
		await_children(nchild);
		return;
	}
	shrt_edj[0] = shrt_edj[1] = NULL;	/* start w/ shortest edge */
	for (rbf0 = dsf_list; rbf0 != NULL; rbf0 = rbf0->next) {
	    for (rbf1 = rbf0->next; rbf1 != NULL; rbf1 = rbf1->next) {
		double	dist2 = 2. - 2.*DOT(rbf0->invec,rbf1->invec);
		if (dist2 < best2) {
			shrt_edj[0] = rbf0;
			shrt_edj[1] = rbf1;
			best2 = dist2;
		}
	    }
	    ++nrbfs;
	}
	if (shrt_edj[0] == NULL) {
		fprintf(stderr, "%s: Cannot find shortest edge\n", progname);
		exit(1);
	}
						/* build mesh from this edge */
	if (shrt_edj[0]->ord < shrt_edj[1]->ord)
		mesh_from_edge(create_migration(shrt_edj[0], shrt_edj[1]));
	else
		mesh_from_edge(create_migration(shrt_edj[1], shrt_edj[0]));
						/* count up edges */
	for (ej = mig_list; ej != NULL; ej = ej->next)
		++nmigs;
	if (nmigs < nrbfs-1)			/* did meshing fail? */
		fprintf(stderr,
	    "%s: warning - %d incident directions but only %d interpolant(s)\n",
				progname, nrbfs, nmigs);
						/* complete migrations */
	await_children(nchild);
}
/* Build our triangle mesh from recorded RBFs */
void
build_mesh(void)
{
	double		best2 = M_PI*M_PI;
	RBFNODE		*shrt_edj[2];
	RBFNODE		*rbf0, *rbf1;
						/* average specular peak */
	comp_bsdf_spec();
						/* add normal if needed */
	check_normal_incidence();
						/* check if isotropic */
	if (single_plane_incident) {
		for (rbf0 = dsf_list; rbf0 != NULL; rbf0 = rbf0->next)
			if (rbf0->next != NULL)
				create_migration(rbf0, rbf0->next);
		await_children(nchild);
		return;
	}
	shrt_edj[0] = shrt_edj[1] = NULL;	/* start w/ shortest edge */
	for (rbf0 = dsf_list; rbf0 != NULL; rbf0 = rbf0->next)
	    for (rbf1 = rbf0->next; rbf1 != NULL; rbf1 = rbf1->next) {
		double	dist2 = 2. - 2.*DOT(rbf0->invec,rbf1->invec);
		if (dist2 < best2) {
			shrt_edj[0] = rbf0;
			shrt_edj[1] = rbf1;
			best2 = dist2;
		}
	}
	if (shrt_edj[0] == NULL) {
		fprintf(stderr, "%s: Cannot find shortest edge\n", progname);
		exit(1);
	}
						/* build mesh from this edge */
	if (shrt_edj[0]->ord < shrt_edj[1]->ord)
		mesh_from_edge(create_migration(shrt_edj[0], shrt_edj[1]));
	else
		mesh_from_edge(create_migration(shrt_edj[1], shrt_edj[0]));
						/* complete migrations */
	await_children(nchild);
}
Exemple #3
0
int main(int argc, char** argv) {

  int fd; /* fifo pipe fd */
  int i;
  int num_reported;
  pid_t pids[NUM_CHILDREN]; /* array of child pids */ 

  /* 
   * open up our pipe for status messages from child processes
   */ 
  if( (fd = open_pipe(FIFO_NAME)) < 0) {
    exit(-1);
  }
  
   /*
   * start up the children, and hang on to the pids
   */
  for (i = 0; i < NUM_CHILDREN; ++i) {
    pid_t pid = fork();
    pids[i] = pid;

    if(pid == -1) {
      perror("Error forking child process");
      exit(-1);
    }
    else if(pids[i] == 0) {
      run_child();
    }
  }

  /*
   * wait for the child processes to complete their task
   */
  if(await_children(pids, NUM_CHILDREN) != NUM_CHILDREN) {
    fprintf(stderr, "Child count doesn't match number forked\n");
  }

  /*
   * read the results from the pipe
   */

  num_reported = read_and_print_results(fd, pids, NUM_CHILDREN);
  if(num_reported != NUM_CHILDREN) {
    fprintf(stderr, "Not all children reported results\n");
  }

  /* done with the pipe. close and unlink it. */
  close(fd);
  unlink(FIFO_NAME);

  return 0;
}
Exemple #4
0
/* Start child process if multiprocessing selected */
static pid_t
run_subprocess(void)
{
	int	status;
	pid_t	pid;

	if (nprocs <= 1)			/* any children requested? */
		return(0);
	await_children(nchild + 1 - nprocs);	/* free up child process */
	if ((pid = fork())) {
		if (pid < 0) {
			fprintf(stderr, "%s: cannot fork subprocess\n",
					progname);
			await_children(nchild);
			exit(1);
		}
		++nchild;			/* subprocess started */
		return(pid);
	}
	nchild = -1;
	return(0);				/* put child to work */
}