testx_threads.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010-2011 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <complex.h>
  18. #include <math.h>
  19. #include <unistd.h>
  20. #include <stdlib.h>
  21. #include <assert.h>
  22. #include <sys/time.h>
  23. #include <starpu.h>
  24. #include <starpu_config.h>
  25. #include "starpufft.h"
  26. #include <fftw3.h>
  27. #define SIGN (-1)
  28. /* #define SIGN (1) */
  29. int main(int argc, char *argv[])
  30. {
  31. int i;
  32. struct timeval begin, end;
  33. int size;
  34. size_t bytes;
  35. int n = 0, m = 0;
  36. _FFTW(plan) fftw_plan;
  37. double timing;
  38. char *num;
  39. int num_threads = 1;
  40. _FFTW(init_threads)();
  41. num = getenv("NUM_THREADS");
  42. if (num)
  43. num_threads = atoi(num);
  44. _FFTW(plan_with_nthreads)(num_threads);
  45. if (argc < 2 || argc > 3)
  46. {
  47. fprintf(stderr,"need one or two size of vector\n");
  48. exit(EXIT_FAILURE);
  49. }
  50. if (argc == 2)
  51. {
  52. n = atoi(argv[1]);
  53. /* 1D */
  54. size = n;
  55. }
  56. else if (argc == 3)
  57. {
  58. n = atoi(argv[1]);
  59. m = atoi(argv[2]);
  60. /* 2D */
  61. size = n * m;
  62. }
  63. else
  64. {
  65. assert(0);
  66. }
  67. bytes = size * sizeof(_FFTW(complex));
  68. _FFTW(complex) *in = _FFTW(malloc)(size * sizeof(*in));
  69. starpu_srand48(0);
  70. for (i = 0; i < size; i++)
  71. in[i] = starpu_drand48() + I * starpu_drand48();
  72. _FFTW(complex) *out_fftw = _FFTW(malloc)(size * sizeof(*out_fftw));
  73. if (argc == 2)
  74. {
  75. fftw_plan = _FFTW(plan_dft_1d)(n, in, out_fftw, SIGN, FFTW_ESTIMATE);
  76. }
  77. else if (argc == 3)
  78. {
  79. fftw_plan = _FFTW(plan_dft_2d)(n, m, in, out_fftw, SIGN, FFTW_ESTIMATE);
  80. }
  81. else
  82. {
  83. assert(0);
  84. }
  85. gettimeofday(&begin, NULL);
  86. _FFTW(execute)(fftw_plan);
  87. gettimeofday(&end, NULL);
  88. _FFTW(destroy_plan)(fftw_plan);
  89. timing = (double)((end.tv_sec - begin.tv_sec)*1000000 + (end.tv_usec - begin.tv_usec));
  90. printf("FFTW with %d threads took %2.2f ms (%2.2f MB/s)\n\n", num_threads, timing/1000, bytes/(timing*num_threads));
  91. printf("\n");
  92. return EXIT_SUCCESS;
  93. }