laplacien_omp.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // g++ -std=c++11 -Wall -Wextra -o laplacien_omp.out laplacien_omp.cpp
  2. // OMP_NUM_THREADS=4 ./laplacien_omp.out canyon.pgm canyon_omp.pgm
  3. // mix master code and slave code
  4. #include "image.hpp"
  5. #include <algorithm>
  6. #include <omp.h>
  7. int main(int argc, char ** argv)
  8. {
  9. if (argc != 5)
  10. {
  11. std::cout << "usage: " << argv[0]
  12. << " <input> <output> <scaling> <nb fakes>\n";
  13. exit(-1);
  14. }
  15. const char * INPUT = argv[1];
  16. const char * OUTPUT = argv[2];
  17. const float SCALING = atof(argv[3]);
  18. const int NB_FAKES = atoi(argv[4]);
  19. double t0 = omp_get_wtime();
  20. // read image
  21. image_t data0;
  22. int width, height;
  23. std::string readError = readPgm(INPUT, width, height, data0);
  24. if (readError != "")
  25. {
  26. std::cout << readError << std::endl;
  27. exit(-1);
  28. }
  29. // compute whole image
  30. image_t data2 = computeLaplacianOmp(data0, width, height, SCALING);
  31. for (int k=0; k<NB_FAKES; ++k)
  32. data2 = computeLaplacianOmp(data0, width, height, SCALING);
  33. // write output image
  34. writePgm(OUTPUT, width, height, data2);
  35. double t1 = omp_get_wtime();
  36. std::cout << t1 - t0;
  37. return 0;
  38. }