testx_threads.c 2.4 KB

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