Example #1
0
int
main ()
{
  int x, y;
  char op;
  scanf ("%d%c%d", &x, &op, &y);	// 5+4  8*9 11-6
  switch (op)
    {
    case '+':
      printf ("%d+%d=%d\n", x, y, myadd (x, y));
      break;
    case '-':
      printf ("%d-%d=%d\n", x, y, mysub (x, y));
      break;
    case '*':
      printf ("%d*%d=%d\n", x, y, mymul (x, y));
      break;
    case '/':
      printf ("%d/%d=%d\n", x, y, mydiv (x, y));
      break;

    default:
      break;
    }
  return 0;
}
main()
{
    /* Parameters */    
#define NMAX    100
#define ITS     10000
    
    int      i, j;
    double   alpha, avg, t1, t2, tnotim;
    double   x[NMAX], y[NMAX];
    double   SuperLU_timer_();

    /* Initialize X and Y */
    for (i = 0; i < NMAX; ++i) {
	x[i] = 1.0 / (double)(i+1);
	y[i] = (double)(NMAX - i) / (double)NMAX;
    }
    alpha = 0.315;

    /* Time 1,000,000 DAXPY operations */
    t1 = SuperLU_timer_();
    for (j = 0; j < ITS; ++j) {
	for (i = 0; i < NMAX; ++i)
	    y[i] += alpha * x[i];
	alpha = -alpha;
    }
    t2 = SuperLU_timer_();
    printf("Time for 1,000,000 DAXPY ops  = %10.3g seconds\n", t2-t1);
    if ( t2-t1 > 0. ) 
	printf("DAXPY performance rate        = %10.3g mflops\n", 2./(t2-t1));
    else
	printf("*** Error:  Time for operations was zero\n");
	
    tnotim = t2 - t1;

    /* Time 1,000,000 DAXPY operations with SuperLU_timer_() 
       in the outer loop */
    t1 = SuperLU_timer_();
    for (j = 0; j < ITS; ++j) {
	for (i = 0; i < NMAX; ++i)
	    y[i] += alpha * x[i];
	alpha = -alpha;
	t2 = SuperLU_timer_();
    }

    /* Compute the time in milliseconds used by an average call to 
       SuperLU_timer_(). */
    printf("Including DSECND, time        = %10.3g seconds\n", t2-t1);
    avg = ( (t2 - t1) - tnotim )*1000. / (double)ITS;
    printf("Average time for DSECND       = %10.3g milliseconds\n", avg);

    /* Compute the equivalent number of floating point operations used
       by an average call to DSECND.    */
    if ( tnotim > 0. )
	printf("Equivalent floating point ops = %10.3g ops\n",
	       1000.*avg / tnotim);

    mysub(NMAX, x, y);
    return 0;
}
Example #3
0
int main(int argc, char *argv[])
{
  float *a;
  int i;
  int mydim = DIM;
  int last;

  printf("Insert last \n");
  scanf("%d",&last);
  for(i=0; i<last; i++)
    {
      mysub(&a, mydim);
      if( i == last -1)
	printf("a = %f \n", a[0]);
    free(a);
    }
/* por cada vez que llamo a malloc , libero la memoria correspondiente*/
/* el print lo hago en el ultimo paso del for para seguir con la idea de quedarme
 con el ultimo valor de a. */
  return(EXIT_SUCCESS);
}
Example #4
0
int main()
{
    /* Parameters */    
#define NMAX    1000
#define ITS     100000
    
    int      i, j, iters;
    double   alpha, avg, t1, t2, tnotim;
    double   x[NMAX], y[NMAX];
    double   SuperLU_timer_();

    /* Initialize X and Y */
    for (i = 0; i < NMAX; ++i) {
	x[i] = 1.0 / (double)(i+1);
	y[i] = (double)(NMAX - i) / (double)NMAX;
    }
    alpha = 0.315;

    /* Time DAXPY operations */
    iters = ITS; 
    tnotim = 0.0;
    while ( tnotim <= 0.0 ) {
      t1 = SuperLU_timer_();
      for (j = 0; j < iters; ++j) {
	for (i = 0; i < NMAX; ++i) y[i] += alpha * x[i];
	alpha = -alpha;
	_dummy = y[j%NMAX];
      }
      t2 = SuperLU_timer_();
      tnotim = t2 - t1;
      if ( tnotim > 0. ){
	float ops = 2.0 * iters * NMAX * 1e-9;
        printf("Time for %d DAXPYs = %10.6g seconds\n",
	       iters, tnotim);
	printf("DAXPY performance rate = %10.6g Gflops\n", ops/tnotim);
      } else {
        /* this makes sure we dont keep trying forever */
        if ( iters > 100000000 ) {
          printf("*** Error: Time for operations was zero.\n"
                 "\tThe timer may not be working correctly.\n");
          /*exit(9);*/
        }
        iters *= 10;
      }
    }

    /* Force gcc not to optimize away the previous loop (DCS) */
    printf("y[0]=%g\n", y[0]) ;
    
    t1 = SuperLU_timer_();
    for (j = 0; j < ITS; ++j) {
	for (i = 0; i < NMAX; ++i)
	    y[i] += alpha * x[i];
	alpha = -alpha;
    }
    t2 = SuperLU_timer_();
    tnotim = t2 - t1;

    /* Time 1,000,000 DAXPY operations with SuperLU_timer_() 
       in the outer loop */
    t1 = SuperLU_timer_();
    for (j = 0; j < ITS; ++j) {
	for (i = 0; i < NMAX; ++i)
	    y[i] += alpha * x[i];
	alpha = -alpha;
	t2 = SuperLU_timer_();
    }

    /* Compute the time in milliseconds used by an average call to 
       SuperLU_timer_(). */
    printf("Including DSECND, time        = %10.3g seconds\n", t2-t1);
    avg = ( (t2 - t1) - tnotim )*1000. / (double)ITS;
    printf("Average time for DSECND       = %10.3g milliseconds\n", avg);

    /* Compute the equivalent number of floating point operations used
       by an average call to DSECND.    */
    if ( tnotim > 0. )
	printf("Equivalent floating point ops = %10.3g ops\n",
	       1000.*avg / tnotim);

    mysub(NMAX, x, y);
    return 0;
}