testx_threads.c 2.5 KB

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