mt-vvadd.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // See LICENSE for license details.
  2. //**************************************************************************
  3. // Vector-vector add benchmark
  4. //--------------------------------------------------------------------------
  5. // Author : Andrew Waterman
  6. // TA : Christopher Celio
  7. // Student :
  8. //
  9. // This benchmark adds two vectors and writes the results to a
  10. // third vector. The input data (and reference data) should be
  11. // generated using the vvadd_gendata.pl perl script and dumped
  12. // to a file named dataset.h
  13. // to print out arrays, etc.
  14. //#define DEBUG
  15. //--------------------------------------------------------------------------
  16. // Includes
  17. #include <string.h>
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. //--------------------------------------------------------------------------
  21. // Input/Reference Data
  22. #include "dataset.h"
  23. //--------------------------------------------------------------------------
  24. // Basic Utilities and Multi-thread Support
  25. #include "util.h"
  26. //--------------------------------------------------------------------------
  27. // vvadd function
  28. extern void __attribute__((noinline)) vvadd(int coreid, int ncores, size_t n, const data_t* x, const data_t* y, data_t* z);
  29. //--------------------------------------------------------------------------
  30. // Main
  31. //
  32. // all threads start executing thread_entry(). Use their "coreid" to
  33. // differentiate between threads (each thread is running on a separate core).
  34. void thread_entry(int cid, int nc)
  35. {
  36. // static allocates data in the binary, which is visible to both threads
  37. static data_t results_data[DATA_SIZE];
  38. // First do out-of-place vvadd
  39. barrier(nc);
  40. stats(vvadd(cid, nc, DATA_SIZE, input1_data, input2_data, results_data); barrier(nc), DATA_SIZE);
  41. if(cid == 0) {
  42. #ifdef DEBUG
  43. printDoubleArray("out-of-place results: ", DATA_SIZE, results_data);
  44. printDoubleArray("out-of-place verify : ", DATA_SIZE, verify_data);
  45. #endif
  46. int res = verifyDouble(DATA_SIZE, results_data, verify_data);
  47. if(res) exit(res);
  48. }
  49. // Second do in-place vvadd
  50. // Copying input
  51. size_t i;
  52. if(cid == 0) {
  53. for (i = 0; i < DATA_SIZE; i++)
  54. results_data[i] = input1_data[i];
  55. }
  56. barrier(nc);
  57. stats(vvadd(cid, nc, DATA_SIZE, results_data, input2_data, results_data); barrier(nc), DATA_SIZE);
  58. if(cid == 0) {
  59. #ifdef DEBUG
  60. printDoubleArray("in-place results: ", DATA_SIZE, results_data);
  61. printDoubleArray("in-place verify : ", DATA_SIZE, verify_data);
  62. #endif
  63. int res = verifyDouble(DATA_SIZE, results_data, verify_data);
  64. if(res) exit(res);
  65. }
  66. barrier(nc);
  67. exit(0);
  68. }