cholesky_and_lu.c 3.5 KB

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