testx_threads.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010-2011 Université de Bordeaux 1
  4. * Copyright (C) 2010 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. 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. fprintf(stderr,"need one or two size of vector\n");
  46. exit(EXIT_FAILURE);
  47. }
  48. if (argc == 2) {
  49. n = atoi(argv[1]);
  50. /* 1D */
  51. size = n;
  52. } else if (argc == 3) {
  53. n = atoi(argv[1]);
  54. m = atoi(argv[2]);
  55. /* 2D */
  56. size = n * m;
  57. } else {
  58. assert(0);
  59. }
  60. bytes = size * sizeof(_FFTW(complex));
  61. _FFTW(complex) *in = _FFTW(malloc)(size * sizeof(*in));
  62. starpu_srand48(0);
  63. for (i = 0; i < size; i++)
  64. in[i] = starpu_drand48() + I * starpu_drand48();
  65. _FFTW(complex) *out_fftw = _FFTW(malloc)(size * sizeof(*out_fftw));
  66. if (argc == 2) {
  67. fftw_plan = _FFTW(plan_dft_1d)(n, in, out_fftw, SIGN, FFTW_ESTIMATE);
  68. } else if (argc == 3) {
  69. fftw_plan = _FFTW(plan_dft_2d)(n, m, in, out_fftw, SIGN, FFTW_ESTIMATE);
  70. } else {
  71. assert(0);
  72. }
  73. gettimeofday(&begin, NULL);
  74. _FFTW(execute)(fftw_plan);
  75. gettimeofday(&end, NULL);
  76. _FFTW(destroy_plan)(fftw_plan);
  77. timing = (double)((end.tv_sec - begin.tv_sec)*1000000 + (end.tv_usec - begin.tv_usec));
  78. printf("FFTW with %d threads took %2.2f ms (%2.2f MB/s)\n\n", num_threads, timing/1000, bytes/(timing*num_threads));
  79. printf("\n");
  80. return EXIT_SUCCESS;
  81. }