cholesky_and_lu.c 3.8 KB

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