Exemplo n.º 1
0
void plist_clear(PList* plist) {
  if (!plist) {
    return;
  }

  GMEM_DELARR(plist->data, PNode*, plist->alen, sizeof(PNode));
  plist_init(plist);
}
Exemplo n.º 2
0
PList* plist_create(void) {
  PList* p = 0;
  GMEM_NEW(p, PList*, sizeof(PList));
  if (!p) {
    return 0;
  }

  plist_init(p);
  return p;
}
Exemplo n.º 3
0
int main(void)
{
	bool ret = true;
	plist *cells = NULL;
	window *win = NULL;

	/* initialize random number generator */
	srand(time(NULL));

	/* initialize opengl window */
	win = window_init("brownian tree", WINDOW_W, WINDOW_H, 32);
	if (win == NULL) {
		fprintf(stderr, "FATAL: %s\n", strerror(errno));
		ret = false;
		goto cleanup;
	} else {
		win->refresh = update_screen;
	}

	/* initialize opengl stuff */
	glPointSize(POINTSIZE);
	glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
	glfwSetWindowSizeCallback(win->enable2d);

	win->enable2d(WINDOW_W, WINDOW_H);

	/* initialize cells list */
	cells = plist_init(particle_init());
	for (int i = 0; i < FREE_CELLS_NUMBER; i++) {
		particle *pt = particle_init();

		if (pt == NULL) {
			fprintf(stderr, "FATAL: %s\n", strerror(errno));
			ret = false;
			goto cleanup;
		}

		pt->x = (GLfloat) randint((WINDOW_W - 1));
		pt->y = (GLfloat) randint((WINDOW_H - 1));

		if (!plist_push(cells, pt)) {
			fprintf(stderr, "FATAL: %s\n", strerror(errno));
			ret = false;
			goto cleanup;
		}
	}

	/* initialize 2D grid */
	for (int y = 0; y < WINDOW_H; y++) {
		for (int x = 0; x < WINDOW_W; x++) {
			grid[y][x] = CELL_EMPTY;
		}
	}

	/* initialize random freezed cells */
	for (int i = 0; i < FREEZED_CELLS_NUMBER; i++) {
		int y = randint(WINDOW_H - 1);
		int x = (i * (WINDOW_W / FREEZED_CELLS_NUMBER))
			+ (FREEZED_CELLS_NUMBER / 2);
		grid[y][x] = CELL_FREEZED;
	}

	/* main loop */
	do {
		win->clear();
		win->refresh(win, &cells);
		move_cells(&cells);
	} while (
           glfwGetKey(GLFW_KEY_ESC) != GLFW_PRESS
        && glfwGetWindowParam(GLFW_OPENED)
	);

	goto cleanup;

cleanup:
	/* free resources */
	if (cells != NULL)
		plist_free(cells);
	if (win != NULL) {
		window_quit();
		window_free(win);
	}

	/* exit error */
	if (!ret)
		return EXIT_FAILURE;

	return EXIT_SUCCESS;
}
Exemplo n.º 4
0
/* This function is called at boot time (threads/init.c) to initialize
 * the process subsystem. */
void process_init(void)
{
  map_init(&process_list);
  plist_init();
}
Exemplo n.º 5
0
/** Server code. Server manages a queue of tasks to be executed in
this phase. Each task in the queue is scheduled to be executed
once. When all the tasks complete execution, the server populates the
queue again and repeats the process. The server terminates when all
populating a task queue returns an empty queue. */
void server_code() {
  task_list_t tlist;
  proc_list_t plist;
  req_list_t rlist;
  task_t *ptr;
  const char *pname = "server_code";
  const int world_me = GA_Nodeid();
  double e1, e2, e3, e4, f1, f2, f3, f4, f5, f6, f7;
  double t_pop_task=0, t_sig_start=0, t_poll=0, t_loop=0, t_loop1=0, t_poll2=0; 
  proc_t *procs;
  int default_grp;
/*   double util_wallsec_(); */
  t_ptask = 0.0;

  default_grp = GA_Pgroup_get_default();
/*   fprintf(stderr, "%d: 1 %s\n", world_me, pname); */

  e1 = util_wallsec_();
  plist_init(&plist);
/*   fprintf(stderr, "%d: 2 %s\n", world_me, pname); */
  task_list_init(&tlist);
/*   fprintf(stderr, "%d: 3 %s\n", world_me, pname); */
  
  e2 = util_wallsec_();
  while(1) {
    f1 = util_wallsec_();
    task_list_reset(&tlist);  
/*     fprintf(stderr, "%d: 4 %s\n", world_me, pname); */
    populate_tasks_((Integer *)&tlist);
/*     fprintf(stderr, "%d: 5. ntodo=%d nrunning=%d ndone=%d %s\n", */
/* 	    world_me, tlist.ntodo, tlist.nrunning, tlist.ndone, pname); */
    req_list_init(&rlist, &tlist);
    f2 = util_wallsec_();
    t_pop_task += (f2-f1);

    if(tlist.ntodo == 0) break;

    f2 = util_wallsec_();
    while(tlist.ntodo>0) {
#warning "Simple server implementation. To be optimized"
      
/*       int nproc = tlist.todo->nproc; */

      f3 = util_wallsec_();
      if(1 /*(tlist.nrunning==0)*/) {
	while(tlist.ntodo>0 &&
	      (procs=plist_assign_procs(&plist, tlist.todo->nproc))!=NULL) {
/* 	  	  fprintf(stderr, "%d:: Signalling start of a task\n", GA_Nodeid()); */
	  signal_task_start(tlist.todo, tlist.todo->nproc, procs, &rlist);
	  tlist.todo->proc_list = procs;
	  task_mark_running(&tlist, tlist.todo);

/* 	  	  fprintf(stderr, "%d: Started a task. ntodo=%d nrunning=%d ndone=%d %s\n", */
/* 	  		  world_me, tlist.ntodo, tlist.nrunning, tlist.ndone, pname); */
	}
      }
      f4 = util_wallsec_();
      t_sig_start += (f4-f3);
      /*       fprintf(stderr, "Polling for task completion notifies\n"); */

      if((ptr = wait_completion(&tlist,&plist,&rlist))!=NULL) {
	plist_reclaim_procs(&plist, ptr->nproc, ptr->proc_list);
	ptr->proc_list = NULL;
	task_mark_done(&tlist, ptr);
/* 	fprintf(stderr, "%d: Completed a task. ntodo=%d nrunning=%d ndone=%d %s\n", */
/* 		world_me, tlist.ntodo, tlist.nrunning, tlist.ndone, pname); */
      }
      f5 = util_wallsec_();
      t_poll += (f5-f3);
    }

    f6 = util_wallsec_();
    t_loop1 += (f6-f1);
    while(tlist.nrunning > 0) {
      if((ptr = wait_completion(&tlist, &plist,&rlist)) != NULL) {
	plist_reclaim_procs(&plist, ptr->nproc, ptr->proc_list);
	ptr->proc_list = NULL;
	task_mark_done(&tlist, ptr);
/*         fprintf(stderr, "%d: Completed a task. ntodo=%d nrunning=%d ndone=%d %s\n", */
/*                 world_me, tlist.ntodo, tlist.nrunning, tlist.ndone, pname); */
      }
    }
    req_list_destroy(&rlist);
    f7 = util_wallsec_();
    t_poll2 += (f7-f6);
    t_loop += (f7-f2);
  }
  e3 = util_wallsec_();
  plist_destroy(&plist);
  task_list_destroy(&tlist);
  /*  req_list_destroy(&rlist);*/
/*   fprintf(stderr, "%d:: Signalling termination\n", GA_Nodeid());  */
  signal_termination(SVR,GA_Pgroup_absolute_id(default_grp,SVR));
/*   fprintf(stderr, "%d:: Done signalling termination\n", GA_Nodeid());  */
  e4 = util_wallsec_();

/*   fprintf(stderr, "%d:: SERVER TOTAL time=%lf\n", ga_nodeid_(), e4-e1); */
/*   fprintf(stderr, "%d:: SERVER INIT time=%lf\n", ga_nodeid_(), e2-e1); */
/*   fprintf(stderr, "%d:: SERVER LOOP time=%lf\n", ga_nodeid_(), e3-e2); */
/*   fprintf(stderr, "%d:: SERVER TLOOP time=%lf\n", ga_nodeid_(), t_loop); */
/*   fprintf(stderr, "%d:: SERVER TLOOP1 time=%lf\n", ga_nodeid_(), t_loop1); */
/*   fprintf(stderr, "%d:: SERVER CLEANUP time=%lf\n", ga_nodeid_(), e4-e3); */
/*   fprintf(stderr, "%d:: SERVER POLLING time=%lf\n", ga_nodeid_(), t_poll); */
/*   fprintf(stderr, "%d:: SERVER POLLING2 time=%lf\n", ga_nodeid_(), t_poll2); */
/*   fprintf(stderr, "%d:: SERVER SIG_START time=%lf\n", ga_nodeid_(), t_sig_start); */
/*   fprintf(stderr, "%d:: SERVER POP_TASK time=%lf\n", ga_nodeid_(), t_pop_task); */
/*   fflush(stdout); */
}