testx_threads.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * StarPU
  3. * Copyright (C) Université Bordeaux 1, CNRS 2009 (see AUTHORS file)
  4. *
  5. * This program 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. * This program 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 in 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. int i;
  30. struct timeval begin, end;
  31. int size;
  32. size_t bytes;
  33. int n = 0, m = 0;
  34. _FFTW(plan) fftw_plan;
  35. double timing;
  36. char *num;
  37. int num_threads = 1;
  38. _FFTW(init_threads)();
  39. num = getenv("NUM_THREADS");
  40. if (num)
  41. num_threads = atoi(num);
  42. _FFTW(plan_with_nthreads)(num_threads);
  43. if (argc < 2 || argc > 3) {
  44. fprintf(stderr,"need one or two size of vector\n");
  45. exit(EXIT_FAILURE);
  46. }
  47. if (argc == 2) {
  48. n = atoi(argv[1]);
  49. /* 1D */
  50. size = n;
  51. } else if (argc == 3) {
  52. n = atoi(argv[1]);
  53. m = atoi(argv[2]);
  54. /* 2D */
  55. size = n * m;
  56. } else {
  57. assert(0);
  58. }
  59. bytes = size * sizeof(_FFTW(complex));
  60. _FFTW(complex) *in = _FFTW(malloc)(size * sizeof(*in));
  61. starpu_srand48(0);
  62. for (i = 0; i < size; i++)
  63. in[i] = starpu_drand48() + I * starpu_drand48();
  64. _FFTW(complex) *out_fftw = _FFTW(malloc)(size * sizeof(*out_fftw));
  65. if (argc == 2) {
  66. fftw_plan = _FFTW(plan_dft_1d)(n, in, out_fftw, SIGN, FFTW_ESTIMATE);
  67. } else if (argc == 3) {
  68. fftw_plan = _FFTW(plan_dft_2d)(n, m, in, out_fftw, SIGN, FFTW_ESTIMATE);
  69. } else {
  70. assert(0);
  71. }
  72. gettimeofday(&begin, NULL);
  73. _FFTW(execute)(fftw_plan);
  74. gettimeofday(&end, NULL);
  75. _FFTW(destroy_plan)(fftw_plan);
  76. timing = (double)((end.tv_sec - begin.tv_sec)*1000000 + (end.tv_usec - begin.tv_usec));
  77. printf("FFTW with %d threads took %2.2f ms (%2.2f MB/s)\n\n", num_threads, timing/1000, bytes/(timing*num_threads));
  78. printf("\n");
  79. return EXIT_SUCCESS;
  80. }