cholesky_and_lu.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #include "cholesky/cholesky.h"
  2. #include <pthread.h>
  3. typedef struct {
  4. int argc;
  5. char **argv;
  6. } params;
  7. typedef struct {
  8. double flops;
  9. double avg_timing;
  10. } retvals;
  11. #define NSAMPLES 10
  12. struct starpu_sched_ctx sched_ctx;
  13. struct starpu_sched_ctx sched_ctx2;
  14. struct starpu_sched_ctx sched_ctx3;
  15. struct starpu_sched_ctx sched_ctx4;
  16. void* func_cholesky(void *val){
  17. params *p = (params*)val;
  18. int procs[] = {1, 3, 4, 5, 6, 7};
  19. starpu_create_sched_ctx(&sched_ctx, "heft", procs, 6, "cholesky1");
  20. int i;
  21. retvals *rv = (retvals*)malloc(sizeof(retvals));
  22. rv->flops = 0;
  23. rv->avg_timing = 0;
  24. double timing = 0;
  25. for(i = 0; i < NSAMPLES; i++)
  26. {
  27. rv->flops += run_cholesky_implicit(&sched_ctx, p->argc, p->argv, &timing);
  28. rv->avg_timing += timing;
  29. }
  30. rv->flops /= NSAMPLES;
  31. rv->avg_timing /= NSAMPLES;
  32. return (void*)rv;
  33. }
  34. void* func_cholesky2(void *val){
  35. params *p = (params*)val;
  36. int procs[] = {0, 8, 9, 10, 11, 12};
  37. starpu_create_sched_ctx(&sched_ctx2, "heft", procs, 6, "cholesky2");
  38. int i;
  39. retvals *rv = (retvals*)malloc(sizeof(retvals));
  40. rv->flops = 0;
  41. rv->avg_timing = 0;
  42. double timing = 0;
  43. for(i = 0; i < NSAMPLES; i++)
  44. {
  45. rv->flops += run_cholesky_implicit(&sched_ctx2, p->argc, p->argv, &timing);
  46. rv->avg_timing += timing;
  47. }
  48. rv->flops /= NSAMPLES;
  49. rv->avg_timing /= NSAMPLES;
  50. return (void*)rv;
  51. }
  52. void* func_cholesky3(void *val){
  53. params *p = (params*)val;
  54. int i;
  55. retvals *rv = (retvals*)malloc(sizeof(retvals));
  56. rv->flops = 0;
  57. rv->avg_timing = 0;
  58. double timing = 0;
  59. for(i = 0; i < NSAMPLES; i++)
  60. {
  61. rv->flops += run_cholesky_implicit(NULL, p->argc, p->argv, &timing);
  62. rv->avg_timing += timing;
  63. }
  64. rv->flops /= NSAMPLES;
  65. rv->avg_timing /= NSAMPLES;
  66. return (void*)rv;
  67. }
  68. void cholesky_vs_cholesky(params *p){
  69. /* 2 cholesky in different ctxs */
  70. starpu_init(NULL);
  71. starpu_helper_cublas_init();
  72. pthread_t tid[2];
  73. pthread_create(&tid[0], NULL, (void*)func_cholesky, (void*)p);
  74. pthread_create(&tid[1], NULL, (void*)func_cholesky2, (void*)p);
  75. void *gflops_cholesky1;
  76. void *gflops_cholesky2;
  77. pthread_join(tid[0], &gflops_cholesky1);
  78. pthread_join(tid[1], &gflops_cholesky2);
  79. starpu_helper_cublas_shutdown();
  80. starpu_shutdown();
  81. /* 1 cholesky all alone on the whole machine */
  82. starpu_init(NULL);
  83. starpu_helper_cublas_init();
  84. void *gflops_cholesky3 = func_cholesky3(p);
  85. starpu_helper_cublas_shutdown();
  86. starpu_shutdown();
  87. /* 2 cholesky in a single ctx */
  88. starpu_init(NULL);
  89. starpu_helper_cublas_init();
  90. pthread_t tid2[2];
  91. pthread_create(&tid2[0], NULL, (void*)func_cholesky3, (void*)p);
  92. pthread_create(&tid2[1], NULL, (void*)func_cholesky3, (void*)p);
  93. void *gflops_cholesky4;
  94. void *gflops_cholesky5;
  95. pthread_join(tid2[0], &gflops_cholesky4);
  96. pthread_join(tid2[1], &gflops_cholesky5);
  97. starpu_helper_cublas_shutdown();
  98. starpu_shutdown();
  99. printf("%2.2f %2.2f %2.2f %2.2f %2.2f ", ((retvals*)gflops_cholesky1)->flops, ((retvals*)gflops_cholesky2)->flops, ((retvals*)gflops_cholesky3)->flops, ((retvals*)gflops_cholesky4)->flops, ((retvals*)gflops_cholesky5)->flops);
  100. printf("%2.2f %2.2f %2.2f %2.2f %2.2f\n", ((retvals*)gflops_cholesky1)->avg_timing, ((retvals*)gflops_cholesky2)->avg_timing, ((retvals*)gflops_cholesky3)->avg_timing, ((retvals*)gflops_cholesky4)->avg_timing, ((retvals*)gflops_cholesky5)->avg_timing);
  101. free(gflops_cholesky1);
  102. free(gflops_cholesky2);
  103. free(gflops_cholesky3);
  104. free(gflops_cholesky4);
  105. free(gflops_cholesky5);
  106. }
  107. int main(int argc, char **argv)
  108. {
  109. params p;
  110. p.argc = argc;
  111. p.argv = argv;
  112. cholesky_vs_cholesky(&p);
  113. return 0;
  114. }