コード例 #1
0
void tui::StatusLine::draw()
{
   glColor4f((GLfloat)1,(GLfloat)1,(GLfloat)1,(GLfloat)0.7);
   glEnable(GL_POLYGON_SMOOTH);   //- for solid fill
   glDisable(GL_POLYGON_STIPPLE);   //- for solid fill
   glRecti(_sb_TR.x(), _sb_TR.y(), _sb_BL.x(), _sb_BL.y());

   glColor4f(0,0,0,1);
   glPushMatrix();
   glTranslatef(_cY.x(), _cY.y(), 0);
   glScalef(_scaledpix, _scaledpix, 1);
   glfDrawSolidString("Y:");
   glPopMatrix();
   
   glPushMatrix();
   glTranslatef(_cX.x(), _cX.y(), 0);
   glScalef(_scaledpix, _scaledpix, 1);
   glfDrawSolidString("X:");
   glPopMatrix();

   glPushMatrix();
   glTranslatef(_dY.x(), _dY.y(), 0);
   glScalef(_scaledpix, _scaledpix, 1);
   glfDrawSolidString("dX:");
   glPopMatrix();
   
   glPushMatrix();
   glTranslatef(_dX.x(), _dX.y(), 0);
   glScalef(_scaledpix, _scaledpix, 1);
   glfDrawSolidString("dX:");
   glPopMatrix();
   
   update_coords(_cp);
}
コード例 #2
0
// Main from original file copied to best tested multiple times
double testmain(uint_fast32_t N, uint_fast32_t M) {

	uint_fast32_t object_size = N;
	uint_fast32_t iters = M;

	srand(object_size);

	double* x = generate_random_list(object_size, 1000);
	double* y = generate_random_list(object_size, 1000);
	double* z = generate_random_list(object_size, 1000);
	double* vx = generate_random_list(object_size, 1);
	double* vy = generate_random_list(object_size, 1);
	double* vz = generate_random_list(object_size, 1);

	struct timespec requestStart, requestEnd;
	clock_gettime(CLOCK_MONOTONIC, &requestStart);
	for (uint_fast32_t i=0; i < iters; i++) {
		for (uint_fast32_t j=0; j < object_size; j++) {
			update_coords(j,x,y,z,vx,vy,vz);
		}
	}
	clock_gettime(CLOCK_MONOTONIC, &requestEnd);


	double timeTaken = (requestEnd.tv_sec + (requestEnd.tv_nsec / 1000000000.)) - (requestStart.tv_sec + (requestStart.tv_nsec / 1000000000.));
	free(x);
    	free(y);	
   	free(z);
    	free(vx);
 	free(vy);
 	free(vz);
	return(((1000000. * timeTaken) / (object_size * iters)));

}
コード例 #3
0
int main(int argc, char *argv[]){
  const double bound = 1000.0;
  const double v_bound = 1.0;

  if (argc != 3){
    printf("Required arguments: vector_length(N) and iterations_num(M)");
    exit(EXIT_FAILURE);
  }

  // get command line args
  uint32_t size = (uint32_t)atoi(argv[1]);
  uint32_t iters = (uint32_t)atoi(argv[2]);

  // set seed
  srand(size);

  // initialize points
  double *x = generate_random_list(size, bound);
  double *y = generate_random_list(size, bound);
  double *z = generate_random_list(size, bound);

  // initialize velocities
  double *vx = generate_random_list(size, v_bound);
  double *vy = generate_random_list(size, v_bound);
  double *vz = generate_random_list(size, v_bound);

  // time while we update coodinates iters number of times
  struct timespec start, end;
  clock_gettime(&start);
  for(uint32_t i = 0; i < iters; i++){
    update_coords(size, x, y, z, vx, vy, vz);
  }
  clock_gettime(&end);

  //compute the checksum
  double chksum = 0;

  for (uint32_t i = 0; i < size; i++){
    chksum += *(x + i) + *(y + i) + *(z + i);
    //printf("x: %f y: %f z: %f, vx: %f vy: %f vz: %f checksum: %f iters: %u\n", *(x + i), *(y + i), *(z + i), *(vx + i), *(vy + i), *(vz + i), chksum, iters);
  }

  free(x);
  free(y);
  free(z);
  free(vx);
  free(vy);
  free(vz);

  // output
  //convert nanoseconds to microseconds
  //convert seconds to microseconds
  double micro_sec =  SEC_TO_MICRO * (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / NANO_TO_MICRO;
  double mean_time = micro_sec/(size * iters);
  printf("Mean time per coordinate: %f us\n", mean_time);
  printf("Final checksum is: %f", chksum);

  exit(EXIT_SUCCESS);
}
コード例 #4
0
ファイル: server.C プロジェクト: Amit-DU/dht
void
vnode_impl::doRPC_cb (ptr<location> l, xdrproc_t proc,
		      void *out, aclnt_cb cb,
		      ref<dorpc_res> res, clnt_stat err)
{
  if (err) {
    ptr<location> reall = locations->lookup (l->id ());
    if (reall && reall->alive ()) {
      warn << "got error " << err << ", but " << l
	   << " is still marked alive\n";
      reall->set_alive (false);
    } else if (!reall) {
      locations->insert (l);
      l->set_alive (false);
    }
    if (!l->alive () && checkdead_int > 0) {
      // benjie: no longer alive, put it on the dead_nodes list so
      // we can try to contact it periodically
      unsigned i=0;
      for (i=0; i<dead_nodes.size (); i++)
	if (dead_nodes[i]->id () == l->id ())
          break;
      if (i == dead_nodes.size ()) {
        dead_nodes.push_back (l);
	delaycb (checkdead_int, wrap (this, &vnode_impl::check_dead_node, l, checkdead_int));
      }
    }
    cb (err);
  }
  else if (res->status != DORPC_OK)
    cb (RPC_CANTRECV);
  else {
    float distance = l->distance ();

    chord_node n = make_chord_node (res->resok->src);

    l->set_coords (n);
    Coord u_coords (n);
    update_coords (u_coords, distance);

    // This should reset the age of the node to zero because
    // remote side always provides an age of zero for self
    // and locationtable will pull in updates that are younger.
    if (me_->id () != n.x)
      locations->insert (n);

    //unmarshall the result and copy to out
    xdrmem x ((char *)res->resok->results.base (),
	      res->resok->results.size (), XDR_DECODE);

    assert (proc);
    if (!proc (x.xdrp (), out)) {
      fatal << "failed to unmarshall result\n";
      cb (RPC_CANTSEND);
    } else
      cb (err);
  }
}
コード例 #5
0
// Main:
int main(int argc, char* argv[]) {

	if (argc != 3) {
		printf("Required arguments: vector_length(N) and iterations_num(M)\n");
		exit(-1);
	}
	uint_fast32_t object_size = atoi(argv[1]);
	uint_fast32_t iters = atoi(argv[2]);
	srand(object_size);

	float* x = generate_random_list(object_size, 1000);
	float* y = generate_random_list(object_size, 1000);
	float* z = generate_random_list(object_size, 1000);
	float* vx = generate_random_list(object_size, 1);
	float* vy = generate_random_list(object_size, 1);
	float* vz = generate_random_list(object_size, 1);
	struct timespec requestStart, requestEnd;
	clock_gettime(CLOCK_MONOTONIC, &requestStart);
	for (uint_fast32_t i=0; i < iters; i++) {
		for (uint_fast32_t j=0; j < object_size; j++) {
			update_coords(j,x,y,z,vx,vy,vz);
		}
	}
	clock_gettime(CLOCK_MONOTONIC, &requestEnd);

	float chksum = (float)sum(x,object_size) + (float)sum(y,object_size) + (float)sum(z,object_size);
	float timeTaken = (requestEnd.tv_sec + (requestEnd.tv_nsec / 1000000000.)) - (requestStart.tv_sec + (requestStart.tv_nsec / 1000000000.));
	printf(" (1000000 * %f) / (%lu * %lu))\n",timeTaken,object_size,iters);
	printf("Mean time per coordinate: %f us\n", ((1000000. * timeTaken) / (object_size * iters)));
	printf("Final checksum is: %f\n", chksum);
	_mm_free(x);
	_mm_free(y);
	_mm_free(z);
	_mm_free(vx);
	_mm_free(vy);
	_mm_free(vz);

	return(0);
}
コード例 #6
0
int main(int argc, char** argv){
  if(argc < 3){
    printf("args: <size> <iters>\n");
    return -1;
  }
  uint64_t size = 1 << atoi(argv[1]);
  uint64_t iters = 1 << atoi(argv[2]);

  srand(size);


  float* x = generate_random_list(size,1000.);
  float* y = generate_random_list(size,1000.);
  float* z = generate_random_list(size,1.);
  float* vx = generate_random_list(size,1.);
  float* vy = generate_random_list(size,1.);
  float* vz = generate_random_list(size,1.);

  struct timespec start,end;
  clock_gettime(CLOCK_MONOTONIC, &start);

  for (uint64_t i=0; i < iters; i++) update_coords(size,x,y,z,vx,vy,vz);
  
  clock_gettime(CLOCK_MONOTONIC, &end);

  float elapsed = (end.tv_sec * BILLION + end.tv_nsec) - (start.tv_sec * BILLION + start.tv_nsec);
  float avg = elapsed/(size * iters);
  int checksum = 0;
  for (uint64_t i=0; i<size; i++){
    checksum += x[i] + y[i] + z[i];
  }

  fileout = fopen(outputFilename, "a"); 
  fprintf(fileout, "%f\n",avg);
  fclose(fileout);
  printf("checksum is %d\n",checksum);
  printf("Average Elapsed Time: %fns\n",avg);
  return 0;
}
コード例 #7
0
ファイル: drive.c プロジェクト: Jheengut/gmerlin
static void draw_drive(lemuria_engine_t * e, void * user_data)
  {
  int index_1;
  int index_2;
  int i;
  float delta_phi;
  float angle;
  float speed;
  float speed_norm;
  
  drive_data * d = (drive_data*)(user_data);

  lemuria_range_update(&(d->curvature_range));
  lemuria_range_update(&(d->speed_range));

  /* Change stuff */

  lemuria_range_get(&(d->speed_range),
                    &(d->speed_start),
                    &(d->speed_end),
                    &speed);
  speed_norm = speed / SPEED_MAX;
  //  fprintf(stderr, "Speed: %f speed_max: %f (Speed/speed_max)^2: %f\n",
  //          speed, SPEED_MAX, speed_norm * speed_norm);
  
  //  fprintf(stderr, "Speed: %f %f\n", speed, SPEED_MAX);

  if(e->quiet)
    {
    d->speed_start = speed;
    d->speed_end = SPEED_MIN;
    lemuria_range_init(e, &(d->speed_range),
                       1, 100, 200);
    }
  else if(e->beat_detected)
    {
    if(lemuria_range_done(&(d->speed_range)) &&
       lemuria_decide(e, 0.2))
      {
      d->speed_start = d->speed_end;
      d->speed_end =
        SPEED_MIN + (lemuria_random(e, 0.0, 0.5) +
                     0.5 * (float)e->loudness/32768.0)*(SPEED_MAX - SPEED_MIN);
      lemuria_range_init(e, &(d->speed_range),
                         1, 100, 200);
      }
    
    if(lemuria_range_done(&(d->curvature_range)) &&
       lemuria_decide(e, 0.2))
      {
      d->delta_phi_start = d->delta_phi_end;

      //      if(d->delta_phi_end > 0.0)

      if(lemuria_decide(e, 0.3))
        d->delta_phi_end = 0.0;
      else
        {
        // d->delta_phi_end = lemuria_random(DELTA_PHI_MIN, DELTA_PHI_MAX);
        d->delta_phi_end =
          DELTA_PHI_MIN +
          (lemuria_random(e, 0.0, 0.5) +
           0.5 * (float)e->loudness / 32768.0)*(DELTA_PHI_MAX - DELTA_PHI_MIN);
        if(lemuria_decide(e, 0.5))
          d->delta_phi_end *= -1.0;
        }
      //  fprintf(stderr, "New phi: %f\n", d->delta_phi_end * 180.0 / M_PI);
        lemuria_range_init(e, &(d->curvature_range), 2, 50, 100);
      }
    }
  
  /* Create new rings if necessary */

  
  d->z_start += speed;

  lemuria_range_get(&(d->curvature_range),
                    &(d->delta_phi_start),
                    &(d->delta_phi_end),
                    &delta_phi);
  
  if(fabs(delta_phi) < DELTA_PHI_MIN)
    delta_phi = 0.0;
  
  while(d->z_start >= DELTA_Z)
    {
    d->segments[d->start_segment].delta_phi = delta_phi;
    d->texture_y += TEXTURE_DELTA_Y;
    d->segments[d->start_segment].texture_y_before = d->texture_y;
    if(d->texture_y > 1.0)
      d->texture_y -= 1.0;
    d->segments[d->start_segment].texture_y_after = d->texture_y;
    
    d->start_segment++;
    if(d->start_segment >= NUM_SEGMENTS)
      d->start_segment = 0;
    d->z_start -= DELTA_Z;
    }
  update_coords(d);
  
  /* Set up Opengl */

  glClearColor(0.0, 0.0, 0.0, 0.0);
  //  glDisable(GL_DEPTH_TEST);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
  lemuria_set_perspective(e, 1, 1000.0);

  /* Set up light and materials */
#ifndef DRAW_MESH
  glShadeModel(GL_SMOOTH);
#endif
  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();

  index_1 = d->start_segment;
  index_2 = index_1 + 1;
  if(index_2 >= NUM_SEGMENTS)
    index_2 = 0;
  
  /* Do curvature transformation */
  
  angle =
    atan2(20.0 * (speed_norm * speed_norm) * d->segments[d->start_segment].delta_phi,
          DELTA_PHI_MAX);

  /*  / (SPEED_MAX * SPEED_MAX) */
  
  
  d->angle = 0.8 * d->angle + 0.2 * angle;
  
  /* */
  
  glTranslatef(0.0, SEGMENT_RADIUS - CAMERA_HEIGHT, 0.0);

  glRotatef(d->angle * 180.0 / M_PI, 0.0, 0.0, 1.0);

  glTranslatef(0.0, CAMERA_HEIGHT - SEGMENT_RADIUS, 0.0);

#ifndef DRAW_MESH
  draw_sky(d, 0.0);
  glFogi(GL_FOG_MODE, GL_LINEAR );
  glFogfv(GL_FOG_COLOR, fog_color);
  glFogf(GL_FOG_START, FOG_START);
  glFogf(GL_FOG_END,   FOG_END);
  
  glEnable(GL_FOG);

  /* We set the light after we rotated stuff */
  lemuria_set_material(&material, GL_FRONT);
  glEnable(GL_LIGHTING);
  lemuria_background_set(&(d->drive_background));

  lemuria_set_light(&light_0, GL_LIGHT0);
  glEnable(GL_LIGHT0);
  glEnable(GL_TEXTURE_2D);
#endif

  //  lemuria_set_light(&light_1, GL_LIGHT1);
  //  glEnable(GL_LIGHT1);
  
  //  fprintf(stderr, "Segments: %d %d\n", d->start_segment, d->end_segment);
  
  for(i = 0; i < NUM_SEGMENTS-1; i++)
    {
    draw_segment(d, index_1, index_2);
    
    if(index_2 == d->end_segment)
      break;
    
    index_1++;
    if(index_1 >= NUM_SEGMENTS)
      index_1 = 0;

    index_2++;
    if(index_2 >= NUM_SEGMENTS)
      index_2 = 0;
    
    }
  glPopMatrix();

  glDisable(GL_TEXTURE_2D);
  glDisable(GL_LIGHTING);
  glDisable(GL_LIGHT0);
  glDisable(GL_LIGHT1);
  glDisable(GL_FOG);
  
  }
コード例 #8
0
/* An explicit control evaluator, taken almost directly from SICP, section
 * 5.2.  list is a flat list of expressions to evaluate.  where is a label to
 * begin at.  Return value depends on where.
 */ 
NODE *evaluator(NODE *list, enum labels where) {

    /* registers */
    NODE    *exp    = NIL,  /* the current expression */
	    *val    = NIL,  /* the value of the last expression */
	    *proc   = NIL,  /* the procedure definition */
	    *argl   = NIL,  /* evaluated argument list */
	    *unev   = NIL,  /* list of unevaluated expressions */
	    *stack  = NIL,  /* register stack */
	    *parm   = NIL,  /* the current formal */
	    *catch_tag = NIL,
	    *arg    = NIL;  /* the current actual */

/* registers that don't get reference counted, so we pretend they're ints */
FIXNUM	    vsp    = 0,		/* temp ptr into var_stack */
	    cont   = 0,		/* where to go next */
	    formals = (FIXNUM)NIL; /* list of formal parameters */

    int i, nargs;
    BOOLEAN tracing;	    /* are we tracing the current procedure? */
    FIXNUM oldtailcall;	    /* in case of reentrant use of evaluator */
    FIXNUM repcount;	    /* count for repeat */
    FIXNUM old_ift_iff;

    oldtailcall = tailcall;
    old_ift_iff = ift_iff_flag;
    save2(var,this_line);
    assign(var, var_stack);
    save2(fun,ufun);
    cont = (FIXNUM)all_done;
    numsave((FIXNUM)cont);
    newcont(where);
    goto fetch_cont;
    
begin_line:
    ref(list);
    assign(this_line, list);
    newcont(end_line);
begin_seq:
    make_tree(list);
    if (!is_tree(list)) {
	assign(val, UNBOUND);
	goto fetch_cont;
    }
    assign(unev, tree__tree(list));
    assign(val, UNBOUND);
    goto eval_sequence;

end_line:
    if (val != UNBOUND) {
	if (NOT_THROWING) err_logo(DK_WHAT, val);
	deref(val);
    }
    val = NIL;
    deref(list);
    goto fetch_cont;


/* ----------------- EVAL ---------------------------------- */

tail_eval_dispatch:
    tailcall = 1;
eval_dispatch:
    switch (nodetype(exp)) {
	case QUOTE:			/* quoted literal */
	    assign(val, node__quote(exp));
	    goto fetch_cont;
	case COLON:			/* variable */
	    assign(val, valnode__colon(exp));
	    while (val == UNBOUND && NOT_THROWING)
		assign(val, err_logo(NO_VALUE, node__colon(exp)));
	    goto fetch_cont;
	case CONS:			/* procedure application */
	    if (tailcall == 1 && is_macro(car(exp)) &&
				 is_list(procnode__caseobj(car(exp)))) {
		/* tail call to user-defined macro must be treated as non-tail
		 * because the expression returned by the macro
		 * remains to be evaluated in the caller's context */
		assign(unev, NIL);
		goto non_tail_eval;
	    }
	    assign(fun, car(exp));
	    if (cdr(exp) != NIL)
		goto ev_application;
	    else
		goto ev_no_args;
	default:
	    assign(val, exp);		/* self-evaluating */
	    goto fetch_cont;
    }

ev_no_args:
    /* Evaluate an application of a procedure with no arguments. */
    assign(argl, NIL);
    goto apply_dispatch;    /* apply the procedure */

ev_application:
    /* Evaluate an application of a procedure with arguments. */
    assign(unev, cdr(exp));
    assign(argl, NIL);
    mixsave(tailcall,var);
    num2save(val_status,ift_iff_flag);
    save2(didnt_get_output,didnt_output_name);
eval_arg_loop:
    if (unev == NIL) goto eval_args_done;
    assign(exp, car(unev));
    if (exp == Not_Enough_Node) {
	if (NOT_THROWING)
	    err_logo(NOT_ENOUGH, NIL);
	goto eval_args_done;
    }
    save(argl);
    save2(unev,fun);
    save2(ufun,last_ufun);
    save2(this_line,last_line);
    assign(var, var_stack);
    tailcall = -1;
    val_status = 1;
    assign(didnt_get_output,
	   cons_list(0,fun,ufun,this_line,END_OF_LIST));
    assign(didnt_output_name, NIL);
    newcont(accumulate_arg);
    goto eval_dispatch;	    /* evaluate the current argument */

accumulate_arg:
    /* Put the evaluated argument into the argl list. */
    reset_args(var);
    restore2(this_line,last_line);
    restore2(ufun,last_ufun);
    assign(last_call, fun);
    restore2(unev,fun);
    restore(argl);
    while (NOT_THROWING && val == UNBOUND) {
	assign(val, err_logo(DIDNT_OUTPUT, NIL));
    }
    push(val, argl);
    pop(unev);
    goto eval_arg_loop;

eval_args_done:
    restore2(didnt_get_output,didnt_output_name);
    num2restore(val_status,ift_iff_flag);
    mixrestore(tailcall,var);
    if (stopping_flag == THROWING) {
	assign(val, UNBOUND);
	goto fetch_cont;
    }
    assign(argl, reverse(argl));
/* --------------------- APPLY ---------------------------- */
apply_dispatch:
    /* Load in the procedure's definition and decide whether it's a compound
     * procedure or a primitive procedure.
     */
    proc = procnode__caseobj(fun);
    if (is_macro(fun)) {
	num2save(val_status,tailcall);
	val_status = 1;
	newcont(macro_return);
    }
    if (proc == UNDEFINED) {
	if (ufun != NIL) {
	    untreeify_proc(ufun);
	}
	if (NOT_THROWING)
	    assign(val, err_logo(DK_HOW, fun));
	else
	    assign(val, UNBOUND);
	goto fetch_cont;
    }
    if (is_list(proc)) goto compound_apply;
    /* primitive_apply */
    if (NOT_THROWING)
	assign(val, (*getprimfun(proc))(argl));
    else
	assign(val, UNBOUND);
#define do_case(x) case x: goto x;
fetch_cont:
    {
	enum labels x = (enum labels)cont;
	cont = (FIXNUM)car(stack);
	numpop(&stack);
	switch (x) {
	    do_list(do_case)
	    default: abort();
	}
    }

compound_apply:
#ifdef mac
    check_mac_stop();
#endif
#ifdef ibm
    check_ibm_stop();
#endif
    if (tracing = flag__caseobj(fun, PROC_TRACED)) {
	for (i = 0; i < trace_level; i++) print_space(writestream);
	trace_level++;
	ndprintf(writestream, "( %s ", fun);
    }
/* Bind the actuals to the formals */
    vsp = (FIXNUM)var_stack;	/* remember where we came in */
    for (formals = (FIXNUM)formals__procnode(proc);
    	 formals != (FIXNUM)NIL;
	 formals = (FIXNUM)cdr((NODE *)formals)) {
	    parm = car((NODE *)formals);
	    if (nodetype(parm) == INT) break;	/* default # args */
	    if (argl != NIL) {
		arg = car(argl);
		if (tracing) {
		    print_node(writestream, maybe_quote(arg));
		    print_space(writestream);
		}
	    } else
		arg = UNBOUND;
	    if (nodetype(parm) == CASEOBJ) {
		if (not_local(parm,(NODE *)vsp)) {
		    push(parm, var_stack);
		    setobject(var_stack, valnode__caseobj(parm));
		}
		tell_shadow(parm);
		setvalnode__caseobj(parm, arg);
	    } else if (nodetype(parm) == CONS) {
		/* parm is optional or rest */
		if (not_local(car(parm),(NODE *)vsp)) {
		    push(car(parm), var_stack);
		    setobject(var_stack, valnode__caseobj(car(parm)));
		}
		tell_shadow(car(parm));
		if (cdr(parm) == NIL) {		    /* parm is rest */
		    setvalnode__caseobj(car(parm), argl);
		    break;
		}
		if (arg == UNBOUND) {		    /* use default */
		    save2(fun,var);
		    save2(ufun,last_ufun);
		    save2(this_line,last_line);
		    save2(didnt_output_name,didnt_get_output);
		    num2save(ift_iff_flag,val_status);
		    assign(var, var_stack);
		    tailcall = -1;
		    val_status = 1;
		    mixsave(formals,argl);
		    numsave(vsp);
		    assign(list, cdr(parm));
		    if (NOT_THROWING)
			make_tree(list);
		    else
			assign(list, NIL);
		    if (!is_tree(list)) {
			assign(val, UNBOUND);
			goto set_args_continue;
		    }
		    assign(unev, tree__tree(list));
		    assign(val, UNBOUND);
		    newcont(set_args_continue);
		    goto eval_sequence;

set_args_continue:
		    numrestore(vsp);
		    mixrestore(formals,argl);
		    parm = car((NODE *)formals);
		    reset_args(var);
		    num2restore(ift_iff_flag,val_status);
		    restore2(didnt_output_name,didnt_get_output);
		    restore2(this_line,last_line);
		    restore2(ufun,last_ufun);
		    restore2(fun,var);
		    arg = val;
		}
		setvalnode__caseobj(car(parm), arg);
	    }
	    if (argl != NIL) pop(argl);
    }
    if (check_throwing) {
	assign(val, UNBOUND);
	goto fetch_cont;
    }
    vsp = 0;
    if (tracing = flag__caseobj(fun, PROC_TRACED)) {
	if (NOT_THROWING) print_char(writestream, ')');
	new_line(writestream);
	save(fun);
	newcont(compound_apply_continue);
    }
    assign(val, UNBOUND);
    assign(last_ufun, ufun);
    assign(ufun, fun);
    assign(last_line, this_line);
    assign(this_line, NIL);
    proc = procnode__caseobj(fun);
    assign(list, bodylist__procnode(proc));	/* get the body ... */
    make_tree_from_body(list);
    if (!is_tree(list)) {
	goto fetch_cont;
    }
    assign(unev, tree__tree(list));
    if (NOT_THROWING) stopping_flag = RUN;
    assign(output_node, UNBOUND);
    if (val_status == 1) val_status = 2;
    else if (val_status == 5) val_status = 3;
    else val_status = 0;
eval_sequence:
    /* Evaluate each expression in the sequence.  Stop as soon as
     * val != UNBOUND.
     */
    if (!RUNNING || val != UNBOUND) {
	goto fetch_cont;
    }
    if (nodetype(unev) == LINE) {
	assign(this_line, unparsed__line(unev));
	if (flag__caseobj(ufun, PROC_STEPPED)) {
	    char junk[20];

	    if (tracing) {
		int i = 1;
		while (i++ < trace_level) print_space(stdout);
	    }
	    print_node(stdout, this_line);
	    ndprintf(stdout, " >>> ");
	    input_blocking++;
#ifndef TIOCSTI
	    if (!setjmp(iblk_buf))
#endif
#ifdef __ZTC__
		ztc_getcr();
#else
		fgets(junk, 19, stdin);
#endif
	    input_blocking = 0;
	    update_coords('\n');
	}
    }
    assign(exp, car(unev));
    pop(unev);
    if (is_list(exp) && (is_tailform(procnode__caseobj(car(exp))))) {
      if (nameis(car(exp),Output) || nameis(car(exp),Op)) {
	assign(didnt_get_output,
	       cons_list(0,car(exp),ufun,this_line,END_OF_LIST));
	assign(didnt_output_name, NIL);
	if (val_status == 2 || val_status == 3) {
	    val_status = 1;
	    assign(exp, cadr(exp));
	    goto tail_eval_dispatch;
	} else if (ufun == NIL) {
	    err_logo(AT_TOPLEVEL,car(exp));
	    assign(val, UNBOUND);
	    goto fetch_cont;
	} else if (val_status < 4) {
	    val_status = 1;
	    assign(exp, cadr(exp));
	    assign(unev, NIL);
	    goto non_tail_eval;	    /* compute value then give error */
	}
      } else if (nameis(car(exp),Stop)) {
	if (ufun == NIL) {
	    err_logo(AT_TOPLEVEL,car(exp));
	    assign(val, UNBOUND);
	    goto fetch_cont;
	} else if (val_status == 0 || val_status == 3) {
	    assign(val, UNBOUND);
	    goto fetch_cont;
	} else if (val_status < 4) {
	    assign(didnt_output_name, fun);
	    assign(val, UNBOUND);
	    goto fetch_cont;
	}
      } else { /* maybeoutput */
	assign(exp, cadr(exp));
	val_status = 5;
	goto tail_eval_dispatch;
      }
    }
    if (unev == NIL) {
	if (val_status == 2 || val_status == 4) {
	    assign(didnt_output_name, fun);
	    assign(unev, UNBOUND);
	    goto non_tail_eval;
	} else {
	    goto tail_eval_dispatch;
	}
    }
    if (is_list(car(unev)) && nameis(car(car(unev)),Stop)) {
	if ((val_status == 0 || val_status == 3) && ufun != NIL) {
	    goto tail_eval_dispatch;
	} else if (val_status < 4) {
	    assign(didnt_output_name, fun);
	    goto tail_eval_dispatch;
	}
    }
non_tail_eval:
    save2(unev,fun);
    num2save(ift_iff_flag,val_status);
    save2(ufun,last_ufun);
    save2(this_line,last_line);
    save(var);
    assign(var, var_stack);
    tailcall = 0;
    newcont(eval_sequence_continue);
    goto eval_dispatch;

eval_sequence_continue:
    reset_args(var);
    restore(var);
    restore2(this_line,last_line);
    restore2(ufun,last_ufun);
    if (dont_fix_ift) {
	num2restore(dont_fix_ift,val_status);
	dont_fix_ift = 0;
    } else
	num2restore(ift_iff_flag,val_status);
    restore2(unev,fun);
    if (stopping_flag == MACRO_RETURN) {
	if (unev == UNBOUND) assign(unev, NIL);
	assign(unev, append(val, unev));
	assign(val, UNBOUND);
	stopping_flag = RUN;
	if (unev == NIL) goto fetch_cont;
    } else if (val_status < 4) {
	if (STOPPING || RUNNING) assign(output_node, UNBOUND);
	if (stopping_flag == OUTPUT || STOPPING) {
	    stopping_flag = RUN;
	    assign(val, output_node);
	    if (val != UNBOUND && val_status < 2 && NOT_THROWING) {
		assign(didnt_output_name,Output);
		err_logo(DIDNT_OUTPUT,Output);
	    }
	    if (val == UNBOUND && val_status == 1 && NOT_THROWING) {
		assign(didnt_output_name,Stop);
		err_logo(DIDNT_OUTPUT,Output);
	    }
	    goto fetch_cont;
	}
    }
    if (val != UNBOUND) {
	err_logo((unev == NIL ? DK_WHAT_UP : DK_WHAT), val);
	assign(val, UNBOUND);
    }
    if (NOT_THROWING && (unev == NIL || unev == UNBOUND)) {
	if (val_status != 4)  err_logo(DIDNT_OUTPUT,NIL);
	goto fetch_cont;
    }
    goto eval_sequence;

compound_apply_continue:
    /* Only get here if tracing */
    restore(fun);
    --trace_level;
    if (NOT_THROWING) {
	for (i = 0; i < trace_level; i++) print_space(writestream);
	print_node(writestream, fun);
	if (val == UNBOUND)
	    ndprintf(writestream, " stops\n");
	else {
	    ref(val);
	    ndprintf(writestream, " outputs %s\n", maybe_quote(val));
	    deref(val);
	}
    }
    goto fetch_cont;

/* --------------------- MACROS ---------------------------- */

macro_return:
    num2restore(val_status,tailcall);
    while (!is_list(val) && NOT_THROWING) {
	assign(val,err_logo(ERR_MACRO,val));
    }
    if (NOT_THROWING) {
	if (is_cont(val)) {
	    newcont(cont__cont(val));
	    val->n_car = NIL;
	    assign(val, val__cont(val));
	    goto fetch_cont;
	}
macro_reval:
	if (tailcall == 0) {
	    make_tree(val);
	    stopping_flag = MACRO_RETURN;
	    if (!is_tree(val)) assign(val, NIL);
	    else assign(val, tree__tree(val));
	    goto fetch_cont;
	}
	assign(list,val);
	goto begin_seq;
    }
    assign(val, UNBOUND);
    goto fetch_cont;

runresult_continuation:
    assign(list, val);
    newcont(runresult_followup);
    val_status = 5;
    goto begin_seq;

runresult_followup:
    if (val == UNBOUND) {
	assign(val, NIL);
    } else {
	assign(val, cons(val, NIL));
    }
    goto fetch_cont;

repeat_continuation:
    assign(list, cdr(val));
    repcount = getint(car(val));
repeat_again:
    assign(val, UNBOUND);
    if (repcount == 0) goto fetch_cont;
    mixsave(repcount,list);
    num2save(val_status,tailcall);
    val_status = 4;
    newcont(repeat_followup);
    goto begin_seq;

repeat_followup:
    if (val != UNBOUND && NOT_THROWING) {
	ref(val);
	err_logo(DK_WHAT, val);
	unref(val);
    }
    num2restore(val_status,tailcall);
    mixrestore(repcount,list);
    if (val_status < 4 && tailcall != 0) {
	if (STOPPING || RUNNING) assign(output_node, UNBOUND);
	if (stopping_flag == OUTPUT || STOPPING) {
	    stopping_flag = RUN;
	    assign(val, output_node);
	    if (val != UNBOUND && val_status < 2) {
		err_logo(DK_WHAT_UP,val);
	    }
	    goto fetch_cont;
	}
    }
    if (repcount > 0)    /* negative means forever */
	--repcount;
#ifdef mac
    check_mac_stop();
#endif
#ifdef ibm
    check_ibm_stop();
#endif
    if (RUNNING) goto repeat_again;
    assign(val, UNBOUND);
    goto fetch_cont;

catch_continuation:
    assign(list, cdr(val));
    assign(catch_tag, car(val));
    if (compare_node(catch_tag,Error,TRUE) == 0) {
	push(Erract, var_stack);
	setobject(var_stack, valnode__caseobj(Erract));
	setvalnode__caseobj(Erract, UNBOUND);
    }
    save(catch_tag);
    save2(didnt_output_name,didnt_get_output);
    num2save(val_status,tailcall);
    newcont(catch_followup);
    val_status = 5;
    goto begin_seq;

catch_followup:
    num2restore(val_status,tailcall);
    restore2(didnt_output_name,didnt_get_output);
    restore(catch_tag);
    if (val_status < 4 && tailcall != 0) {
	if (STOPPING || RUNNING) assign(output_node, UNBOUND);
	if (stopping_flag == OUTPUT || STOPPING) {
	    stopping_flag = RUN;
	    assign(val, output_node);
	    if (val != UNBOUND && val_status < 2) {
		err_logo(DK_WHAT_UP,val);
	    }
	}
    }
    if (stopping_flag == THROWING &&
	compare_node(throw_node, catch_tag, TRUE) == 0) {
	    throw_node = reref(throw_node, UNBOUND);
	    stopping_flag = RUN;
	    assign(val, output_node);
    }
    goto fetch_cont;

begin_apply:
    /* This is for lapply. */
    assign(fun, car(val));
    while (nodetype(fun) == ARRAY && NOT_THROWING)
	assign(fun, err_logo(APPLY_BAD_DATA, fun));
    assign(argl, cadr(val));
    assign(val, UNBOUND);
    while (!is_list(argl) && NOT_THROWING)
	assign(argl, err_logo(APPLY_BAD_DATA, argl));
    if (NOT_THROWING && fun != NIL) {
	if (is_list(fun)) {		    /* template */
	    if (is_list(car(fun)) && cdr(fun) != NIL) {
		/* lambda form */
		formals = (FIXNUM)car(fun);
		numsave(tailcall);
		tailcall = 0;
		llocal((NODE *)formals);    /* bind the formals locally */
		numrestore(tailcall);
		for ( ;
		     formals && argl && NOT_THROWING;
		     formals = (FIXNUM)cdr((NODE *)formals),
		     assign(argl, cdr(argl)))
			setvalnode__caseobj(car((NODE *)formals), car(argl));
		assign(val, cdr(fun));
		goto macro_reval;
	    } else {		/* question-mark form */
		save(qm_list);
		assign(qm_list, argl);
		assign(list, fun);
		make_tree(list);
		if (list == NIL || !is_tree(list)) {
		    goto qm_failed;
		}
		assign(unev, tree__tree(list));
		save2(didnt_output_name,didnt_get_output);
		num2save(val_status,tailcall);
		newcont(qm_continue);
		val_status = 5;
		goto eval_sequence;

qm_continue:
		num2restore(val_status,tailcall);
		restore2(didnt_output_name,didnt_get_output);
		if (val_status < 4 && tailcall != 0) {
		    if (STOPPING || RUNNING) assign(output_node, UNBOUND);
		    if (stopping_flag == OUTPUT || STOPPING) {
			stopping_flag = RUN;
			assign(val, output_node);
			if (val != UNBOUND && val_status < 2) {
			    err_logo(DK_WHAT_UP,val);
			}
		    }
		}
qm_failed:
		restore(qm_list);
		goto fetch_cont;
	    }
	} else {    /* name of procedure to apply */
	    int min, max, n;
	    NODE *arg;
	    assign(fun, intern(fun));
	    if (procnode__caseobj(fun) == UNDEFINED && NOT_THROWING &&
		fun != Null_Word)
		    silent_load(fun, NULL);    /* try ./<fun>.lg */
	    if (procnode__caseobj(fun) == UNDEFINED && NOT_THROWING &&
		fun != Null_Word)
		    silent_load(fun, logolib); /* try <logolib>/<fun> */
	    proc = procnode__caseobj(fun);
	    while (proc == UNDEFINED && NOT_THROWING) {
		assign(val, err_logo(DK_HOW_UNREC, fun));
	    }
	    if (NOT_THROWING) {
		if (nodetype(proc) == CONS) {
		    min = getint(minargs__procnode(proc));
		    max = getint(maxargs__procnode(proc));
		} else {
		    if (getprimdflt(proc) < 0) {	    /* special form */
			err_logo(DK_HOW_UNREC, fun);    /* can't apply */
			goto fetch_cont;
		    } else {
			min = getprimmin(proc);
			max = getprimmax(proc);
		    }
		}
		for (n = 0, arg = argl; arg != NIL; n++, arg = cdr(arg));
		if (n < min) {
		    err_logo(NOT_ENOUGH, NIL);
		} else if (n > max && max >= 0) {
		    err_logo(TOO_MUCH, NIL);
		} else {
		    goto apply_dispatch;
		}
	    }
	}
    }
    goto fetch_cont;

all_done:
    tailcall = oldtailcall;
    ift_iff_flag = old_ift_iff;
    restore2(fun,ufun);
    reset_args(var);
    restore2(var,this_line);
    deref(argl);deref(unev);deref(stack);deref(catch_tag);deref(exp);
    return(val);
}
コード例 #9
0
int main(){
	
	uint32_t size = 0;
	uint32_t iters = 0;

	FILE * fp;
	FILE * fp2;
	FILE * fp3;
    char * line = NULL;
	size_t len = 0;
    ssize_t read;


    fp = fopen("HW1_P2.in", "r");
   	fp2 = fopen("HW1_P3.out","w");
	fp3 = fopen("HW1_P3_DataToPlot.in", "w");

    //Check if the file exists
    if (fp == NULL)
        exit(EXIT_FAILURE);

	while ((read = getline(&line, &len, fp)) != -1) {
		char *token;
		char *rest = line;
		token = strtok_r(rest, ",", &rest);
    	size = (uint32_t)atoi(token);
    	token = strtok_r(rest, ",", &rest);
    	iters = (uint32_t)atoi(token);



    	//printf("size:%u\n",size);
    	//printf("iters:%u\n",iters);		 
    	//Initialize pointers to arrays
    	double avg_avgtimes = 0;
	    double avgtimes[TIMES_PER_MEASUREMENTS] = {0};

	    for (uint32_t i=0;i<TIMES_PER_MEASUREMENTS;++i){
			
			srand(size);
	    	//Initialize arrays to zero
			Float * x = calloc(size,sizeof(Float));
			Float * y = calloc(size,sizeof(Float));
			Float * z = calloc(size,sizeof(Float));
			Float * vx = calloc(size,sizeof(Float));
			Float * vy = calloc(size,sizeof(Float));
			Float * vz = calloc(size,sizeof(Float));

			//Generate our random arrays
			generate_random_list(size,coord_bound,x);
			generate_random_list(size,coord_bound,x);
			generate_random_list(size,coord_bound,y);
			generate_random_list(size,coord_bound,z);
			generate_random_list(size,move_bound,vx);
			generate_random_list(size,move_bound,vy);
			generate_random_list(size,move_bound,vz);

			clock_t begin, end;
			double time_spent;

			begin = clock();
			for (uint32_t i=0;i<iters;++i){
				update_coords(x,y,z,vx,vy,vz,size);
			}
			end = clock();
			time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
			Float chksum = sum_array(x,size) + sum_array(y,size) + sum_array(z,size);
            double avgtime  = 1000000 * time_spent / (size * iters); 
            avgtimes[i] = avgtime;
			

            //write detailed ouput
            fprintf(fp2,"size: %u, iters: %u\n",size,iters);
			fprintf(fp2,"total time:%f\n",time_spent);
			fprintf(fp2,"Mean time per coordinate: %f\n",avgtime);
			fprintf(fp2,"Final checksum is: %f\n",chksum);
			
			//free memory
			free(x);
			free(y);
			free(z);
			free(vx);
			free(vy);
			free(vz);
		}
		//write output for the purpose of drawing a graph
		avg_avgtimes = sum_array(avgtimes,TIMES_PER_MEASUREMENTS)/TIMES_PER_MEASUREMENTS;
		fprintf(fp3,"%u,%f\n",size,avg_avgtimes);
	}
	//close files
    fclose(fp);
    fclose(fp2);
    fclose(fp3);
    if (line)
        free(line);
    return 0;
}
コード例 #10
0
ファイル: parse.c プロジェクト: Distrotech/ucblogo
int rd_getc(FILE *strm) {
    int c;
#ifdef WIN32
    MSG msg;
#endif

#ifndef WIN32 /* skip this section ... */
#ifdef __RZTC__
    if (strm == stdin) zflush();
    c = ztc_getc(strm);
#else
    c = getc(strm);
#endif
    if (strm == stdin && c != EOF) update_coords(c);
#ifndef mac
    if (c == '\r') return rd_getc(strm);
#endif
#ifdef ibm
    if (c == 17 && interactive && strm==stdin) { /* control-q */
	to_pending = 0;
	err_logo(STOP_ERROR,NIL);
	if (input_blocking) {
#ifdef SIG_TAKES_ARG
	    logo_stop(0);
#else
	    logo_stop();
#endif
	}
    }
    if (c == 23 && interactive && strm==stdin) { /* control-w */
#ifndef __RZTC__
	getc(strm); /* eat up the return */
#endif

#ifdef SIG_TAKES_ARG
	logo_pause(0);
#else
	logo_pause();
#endif

	return(rd_getc(strm));
    }
#endif
#else /* WIN32 */
    if (strm == stdin) {
	if (winPasteText && !line_avail) winDoPaste();
	if (!line_avail) {
	    win32_text_cursor();
	    while (GetMessage(&msg, NULL, 0, 0)) {
		TranslateMessage(&msg);
		DispatchMessage(&msg);
		if (line_avail)
		    break;
		}
	    }
      c = read_line[read_index++];
      if (c == 17 && interactive && strm==stdin) { /* control-q */
	to_pending = 0;
	err_logo(STOP_ERROR,NIL);
	line_avail = 0;
	free(read_line);
	if (input_blocking) logo_stop(0);
	return('\n');
    }
    if (c == 23 && interactive && strm==stdin) { /* control-w */
	line_avail = 0;
	free(read_line);
	logo_pause(0);
	return(rd_getc(strm));
    }
      if (c == '\n') {
	line_avail = 0;
	free(read_line);
      }
    }
    else /* reading from a file */
      c = getc(strm);
#endif /* WIN32 */

#ifdef ecma
    return((c == EOF) ? c : ecma_clear(c));
#else
    return(c);
#endif
}