示例#1
0
void main(int argc, char** argv)
{ initData();

  clock_gettime(CLOCK_REALTIME, &start);
  int i;
  for(i=0; i < ITERATIONS; i++)
  { add_arrays(); }
  clock_gettime(CLOCK_REALTIME, &finish);

  printf("%i\n", a[500]);
  fprintf (stderr, "Total time: %03li\n", xelapsed (finish, start));
}
示例#2
0
int main(void)
{
  int a[] = {1, 2, 3, 4, 5, 6, 7, 8};
  int b[] = {4, 6, 8, 2, 4, 3, 5, 8};
  int c[8];
  int size = sizeof(a) / sizeof(a[0]);

  int v1[] = {1, 2, 3};
  int v2[] = {3, 4, 7};
  int vsize = sizeof(v1) / sizeof(v1[0]);
  int v3[sizeof(v1) / sizeof(v1[0])];
  int product;

    /* reverse an array */
  printf("Array a:\n");
  print_array(a, size);
  reverse_array(a, size);
  printf("Array a reversed:\n");
  print_array(a, size);
  printf("\n");

    /* add two arrays into a third array */
  printf("Array b:\n");
  print_array(b, size);
  add_arrays(a, b, c, size);
  printf("Array c (sum of array a and array b):\n");
  print_array(c, size);
  printf("\n");

    /* multiply each element by 10 */
  scalar_multiply(c, size, 10);
  printf("All values of c multiplied by 10:\n");
  print_array(c, size);  
  printf("\n");

    /* multiply two arrays (dot product) */
  printf("Array v1:");
  print_array(v1, vsize);
  printf("Array v2:");
  print_array(v2, vsize);
  product = dot_product(v1, v2, vsize);
  printf("The dot product of v1 * v2 is %i\n", product);
  printf("\n");

    /* multiply two arrays (cross product) */
  printf("Array v1:");
  print_array(v1, vsize);
  printf("Array v2:");
  print_array(v2, vsize);
  cross_product(v1, v2, v3);
  printf("The cross product of v1 x v2 is:");
  print_array(v3, 3);
  printf("\n");

    /* more tests */
  test1();
  test2();
  printf("\n");

  return 0;
}