spir_test.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <sys/time.h>
  4. #include <unistd.h>
  5. #include "spir.hpp"
  6. using std::cout;
  7. using std::cerr;
  8. static inline size_t elapsed_us(const struct timeval *start)
  9. {
  10. struct timeval end;
  11. gettimeofday(&end, NULL);
  12. return (end.tv_sec-start->tv_sec)*1000000 + end.tv_usec - start->tv_usec;
  13. }
  14. int main(int argc, char **argv)
  15. {
  16. if (argc < 2 || argc > 5) {
  17. cerr << "Usage: " << argv[0] << " r [num_threads [num_preproc [num_pirs]]]\n";
  18. cerr << "r = log_2(num_records)\n";
  19. exit(1);
  20. }
  21. uint32_t r, num_threads = 1, num_preproc = 1, num_pirs = 1;
  22. r = strtoul(argv[1], NULL, 10);
  23. if (argc > 2) {
  24. num_threads = strtoul(argv[2], NULL, 10);
  25. }
  26. if (argc > 3) {
  27. num_preproc = strtoul(argv[3], NULL, 10);
  28. }
  29. if (argc > 4) {
  30. num_pirs = strtoul(argv[4], NULL, 10);
  31. } else {
  32. num_pirs = num_preproc;
  33. }
  34. cout << "===== ONE-TIME SETUP =====\n\n";
  35. struct timeval otsetup_start;
  36. gettimeofday(&otsetup_start, NULL);
  37. SPIR::init(num_threads);
  38. string pub_params;
  39. SPIR_Client client(r, pub_params);
  40. cout << "pub_params len = " << pub_params.length() << "\n";
  41. SPIR_Server server(r, pub_params);
  42. size_t otsetup_us = elapsed_us(&otsetup_start);
  43. cout << "One-time setup: " << otsetup_us << " µs\n";
  44. return 0;
  45. }