plu_example.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. * Copyright (C) 2013 Thibaut Lambert
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include "helper.h"
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <time.h>
  22. #include <math.h>
  23. #include <starpu.h>
  24. #include "pxlu.h"
  25. //#include "pxlu_kernels.h"
  26. #ifdef STARPU_HAVE_LIBNUMA
  27. #include <numaif.h>
  28. #endif
  29. #ifdef STARPU_HAVE_VALGRIND_H
  30. #include <valgrind/valgrind.h>
  31. #endif
  32. static unsigned long size = 4096;
  33. static unsigned nblocks = 16;
  34. static unsigned check = 0;
  35. static int p = -1;
  36. static int q = -1;
  37. static unsigned display = 0;
  38. static unsigned no_prio = 0;
  39. #ifdef STARPU_HAVE_LIBNUMA
  40. static unsigned numa = 0;
  41. #endif
  42. static size_t allocated_memory = 0;
  43. static size_t allocated_memory_extra = 0;
  44. static starpu_data_handle_t *dataA_handles;
  45. static TYPE **dataA;
  46. /* In order to implement the distributed LU decomposition, we allocate
  47. * temporary buffers */
  48. #ifdef SINGLE_TMP11
  49. static starpu_data_handle_t tmp_11_block_handle;
  50. static TYPE *tmp_11_block;
  51. #else
  52. static starpu_data_handle_t *tmp_11_block_handles;
  53. static TYPE **tmp_11_block;
  54. #endif
  55. #ifdef SINGLE_TMP1221
  56. static starpu_data_handle_t *tmp_12_block_handles;
  57. static TYPE **tmp_12_block;
  58. static starpu_data_handle_t *tmp_21_block_handles;
  59. static TYPE **tmp_21_block;
  60. #else
  61. static starpu_data_handle_t *(tmp_12_block_handles[2]);
  62. static TYPE **(tmp_12_block[2]);
  63. static starpu_data_handle_t *(tmp_21_block_handles[2]);
  64. static TYPE **(tmp_21_block[2]);
  65. #endif
  66. static void parse_args(int rank, int argc, char **argv)
  67. {
  68. (void)rank;
  69. int i;
  70. for (i = 1; i < argc; i++)
  71. {
  72. if (strcmp(argv[i], "-size") == 0)
  73. {
  74. char *argptr;
  75. size = strtol(argv[++i], &argptr, 10);
  76. }
  77. if (strcmp(argv[i], "-nblocks") == 0)
  78. {
  79. char *argptr;
  80. nblocks = strtol(argv[++i], &argptr, 10);
  81. }
  82. if (strcmp(argv[i], "-check") == 0)
  83. {
  84. check = 1;
  85. }
  86. if (strcmp(argv[i], "-display") == 0)
  87. {
  88. display = 1;
  89. }
  90. if (strcmp(argv[i], "-numa") == 0)
  91. {
  92. #ifdef STARPU_HAVE_LIBNUMA
  93. numa = 1;
  94. #else
  95. if (rank == 0)
  96. fprintf(stderr, "Warning: libnuma is not available\n");
  97. #endif
  98. }
  99. if (strcmp(argv[i], "-p") == 0)
  100. {
  101. char *argptr;
  102. p = strtol(argv[++i], &argptr, 10);
  103. }
  104. if (strcmp(argv[i], "-q") == 0)
  105. {
  106. char *argptr;
  107. q = strtol(argv[++i], &argptr, 10);
  108. }
  109. if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "--help") == 0)
  110. {
  111. fprintf(stderr,"usage: %s [-size n] [-nblocks b] [-check] [-display] [-numa] [-p p] [-q q]\n", argv[0]);
  112. fprintf(stderr,"\np * q must be equal to the number of MPI nodes\n");
  113. exit(0);
  114. }
  115. }
  116. #ifdef STARPU_HAVE_VALGRIND_H
  117. if (RUNNING_ON_VALGRIND)
  118. {
  119. size = 4;
  120. nblocks = 4;
  121. }
  122. #endif
  123. }
  124. unsigned STARPU_PLU(display_flag)(void)
  125. {
  126. return display;
  127. }
  128. static void fill_block_with_random(TYPE *blockptr, unsigned psize, unsigned pnblocks)
  129. {
  130. const unsigned block_size = (psize/pnblocks);
  131. unsigned i, j;
  132. for (i = 0; i < block_size; i++)
  133. for (j = 0; j < block_size; j++)
  134. {
  135. blockptr[j+i*block_size] = (TYPE)starpu_drand48();
  136. }
  137. }
  138. #ifdef SINGLE_TMP11
  139. starpu_data_handle_t STARPU_PLU(get_tmp_11_block_handle)(void)
  140. {
  141. return tmp_11_block_handle;
  142. }
  143. #else
  144. starpu_data_handle_t STARPU_PLU(get_tmp_11_block_handle)(unsigned k)
  145. {
  146. return tmp_11_block_handles[k];
  147. }
  148. #endif
  149. #ifdef SINGLE_TMP1221
  150. starpu_data_handle_t STARPU_PLU(get_tmp_12_block_handle)(unsigned j)
  151. {
  152. return tmp_12_block_handles[j];
  153. }
  154. starpu_data_handle_t STARPU_PLU(get_tmp_21_block_handle)(unsigned i)
  155. {
  156. return tmp_21_block_handles[i];
  157. }
  158. #else
  159. starpu_data_handle_t STARPU_PLU(get_tmp_12_block_handle)(unsigned j, unsigned k)
  160. {
  161. return tmp_12_block_handles[k%2][j];
  162. }
  163. starpu_data_handle_t STARPU_PLU(get_tmp_21_block_handle)(unsigned i, unsigned k)
  164. {
  165. return tmp_21_block_handles[k%2][i];
  166. }
  167. #endif
  168. static unsigned tmp_11_block_is_needed(int rank, unsigned pnblocks, unsigned k)
  169. {
  170. (void)rank;
  171. (void)pnblocks;
  172. (void)k;
  173. return 1;
  174. }
  175. static unsigned tmp_12_block_is_needed(int rank, unsigned pnblocks, unsigned j)
  176. {
  177. unsigned i;
  178. for (i = 1; i < pnblocks; i++)
  179. {
  180. if (get_block_rank(i, j) == rank)
  181. return 1;
  182. }
  183. return 0;
  184. }
  185. static unsigned tmp_21_block_is_needed(int rank, unsigned pnblocks, unsigned i)
  186. {
  187. unsigned j;
  188. for (j = 1; j < pnblocks; j++)
  189. {
  190. if (get_block_rank(i, j) == rank)
  191. return 1;
  192. }
  193. return 0;
  194. }
  195. static void init_matrix(int rank)
  196. {
  197. #ifdef STARPU_HAVE_LIBNUMA
  198. if (numa)
  199. {
  200. fprintf(stderr, "Using INTERLEAVE policy\n");
  201. unsigned long nodemask = ((1<<0)|(1<<1));
  202. int ret = set_mempolicy(MPOL_INTERLEAVE, &nodemask, 3);
  203. if (ret)
  204. perror("set_mempolicy failed");
  205. }
  206. #endif
  207. /* Allocate a grid of data handles, not all of them have to be allocated later on */
  208. dataA_handles = calloc(nblocks*nblocks, sizeof(starpu_data_handle_t));
  209. dataA = calloc(nblocks*nblocks, sizeof(TYPE *));
  210. allocated_memory_extra += nblocks*nblocks*(sizeof(starpu_data_handle_t) + sizeof(TYPE *));
  211. size_t blocksize = (size_t)(size/nblocks)*(size/nblocks)*sizeof(TYPE);
  212. /* Allocate all the blocks that belong to this mpi node */
  213. unsigned long i,j;
  214. for (j = 0; j < nblocks; j++)
  215. {
  216. for (i = 0; i < nblocks; i++)
  217. {
  218. TYPE **blockptr = &dataA[j+i*nblocks];
  219. // starpu_data_handle_t *handleptr = &dataA_handles[j+nblocks*i];
  220. starpu_data_handle_t *handleptr = &dataA_handles[j+nblocks*i];
  221. if (get_block_rank(i, j) == rank)
  222. {
  223. /* This blocks should be treated by the current MPI process */
  224. /* Allocate and fill it */
  225. starpu_malloc((void **)blockptr, blocksize);
  226. allocated_memory += blocksize;
  227. //fprintf(stderr, "Rank %d : fill block (i = %d, j = %d)\n", rank, i, j);
  228. fill_block_with_random(*blockptr, size, nblocks);
  229. //fprintf(stderr, "Rank %d : fill block (i = %d, j = %d)\n", rank, i, j);
  230. if (i == j)
  231. {
  232. unsigned tmp;
  233. for (tmp = 0; tmp < size/nblocks; tmp++)
  234. {
  235. (*blockptr)[tmp*((size/nblocks)+1)] += 1;
  236. (*blockptr)[tmp*((size/nblocks)+1)] *= 100;
  237. }
  238. }
  239. /* Register it to StarPU */
  240. starpu_matrix_data_register(handleptr, STARPU_MAIN_RAM,
  241. (uintptr_t)*blockptr, size/nblocks,
  242. size/nblocks, size/nblocks, sizeof(TYPE));
  243. starpu_data_set_coordinates(*handleptr, 2, j, i);
  244. }
  245. else
  246. {
  247. *blockptr = STARPU_POISON_PTR;
  248. *handleptr = STARPU_POISON_PTR;
  249. }
  250. }
  251. }
  252. /* Allocate the temporary buffers required for the distributed algorithm */
  253. unsigned k;
  254. /* tmp buffer 11 */
  255. #ifdef SINGLE_TMP11
  256. starpu_malloc((void **)&tmp_11_block, blocksize);
  257. allocated_memory_extra += blocksize;
  258. starpu_matrix_data_register(&tmp_11_block_handle, STARPU_MAIN_RAM, (uintptr_t)tmp_11_block,
  259. size/nblocks, size/nblocks, size/nblocks, sizeof(TYPE));
  260. #else
  261. tmp_11_block_handles = calloc(nblocks, sizeof(starpu_data_handle_t));
  262. tmp_11_block = calloc(nblocks, sizeof(TYPE *));
  263. allocated_memory_extra += nblocks*(sizeof(starpu_data_handle_t) + sizeof(TYPE *));
  264. for (k = 0; k < nblocks; k++)
  265. {
  266. if (tmp_11_block_is_needed(rank, nblocks, k))
  267. {
  268. starpu_malloc((void **)&tmp_11_block[k], blocksize);
  269. allocated_memory_extra += blocksize;
  270. STARPU_ASSERT(tmp_11_block[k]);
  271. starpu_matrix_data_register(&tmp_11_block_handles[k], STARPU_MAIN_RAM,
  272. (uintptr_t)tmp_11_block[k],
  273. size/nblocks, size/nblocks, size/nblocks, sizeof(TYPE));
  274. }
  275. }
  276. #endif
  277. /* tmp buffers 12 and 21 */
  278. #ifdef SINGLE_TMP1221
  279. tmp_12_block_handles = calloc(nblocks, sizeof(starpu_data_handle_t));
  280. tmp_21_block_handles = calloc(nblocks, sizeof(starpu_data_handle_t));
  281. tmp_12_block = calloc(nblocks, sizeof(TYPE *));
  282. tmp_21_block = calloc(nblocks, sizeof(TYPE *));
  283. allocated_memory_extra += 2*nblocks*(sizeof(starpu_data_handle_t) + sizeof(TYPE *));
  284. #else
  285. for (i = 0; i < 2; i++)
  286. {
  287. tmp_12_block_handles[i] = calloc(nblocks, sizeof(starpu_data_handle_t));
  288. tmp_21_block_handles[i] = calloc(nblocks, sizeof(starpu_data_handle_t));
  289. tmp_12_block[i] = calloc(nblocks, sizeof(TYPE *));
  290. tmp_21_block[i] = calloc(nblocks, sizeof(TYPE *));
  291. allocated_memory_extra += 2*nblocks*(sizeof(starpu_data_handle_t) + sizeof(TYPE *));
  292. }
  293. #endif
  294. for (k = 0; k < nblocks; k++)
  295. {
  296. #ifdef SINGLE_TMP1221
  297. if (tmp_12_block_is_needed(rank, nblocks, k))
  298. {
  299. starpu_malloc((void **)&tmp_12_block[k], blocksize);
  300. allocated_memory_extra += blocksize;
  301. STARPU_ASSERT(tmp_12_block[k]);
  302. starpu_matrix_data_register(&tmp_12_block_handles[k], STARPU_MAIN_RAM,
  303. (uintptr_t)tmp_12_block[k],
  304. size/nblocks, size/nblocks, size/nblocks, sizeof(TYPE));
  305. }
  306. if (tmp_21_block_is_needed(rank, nblocks, k))
  307. {
  308. starpu_malloc((void **)&tmp_21_block[k], blocksize);
  309. allocated_memory_extra += blocksize;
  310. STARPU_ASSERT(tmp_21_block[k]);
  311. starpu_matrix_data_register(&tmp_21_block_handles[k], STARPU_MAIN_RAM,
  312. (uintptr_t)tmp_21_block[k],
  313. size/nblocks, size/nblocks, size/nblocks, sizeof(TYPE));
  314. }
  315. #else
  316. for (i = 0; i < 2; i++)
  317. {
  318. if (tmp_12_block_is_needed(rank, nblocks, k))
  319. {
  320. starpu_malloc((void **)&tmp_12_block[i][k], blocksize);
  321. allocated_memory_extra += blocksize;
  322. STARPU_ASSERT(tmp_12_block[i][k]);
  323. starpu_matrix_data_register(&tmp_12_block_handles[i][k], STARPU_MAIN_RAM,
  324. (uintptr_t)tmp_12_block[i][k],
  325. size/nblocks, size/nblocks, size/nblocks, sizeof(TYPE));
  326. }
  327. if (tmp_21_block_is_needed(rank, nblocks, k))
  328. {
  329. starpu_malloc((void **)&tmp_21_block[i][k], blocksize);
  330. allocated_memory_extra += blocksize;
  331. STARPU_ASSERT(tmp_21_block[i][k]);
  332. starpu_matrix_data_register(&tmp_21_block_handles[i][k], STARPU_MAIN_RAM,
  333. (uintptr_t)tmp_21_block[i][k],
  334. size/nblocks, size/nblocks, size/nblocks, sizeof(TYPE));
  335. }
  336. }
  337. #endif
  338. }
  339. //display_all_blocks(nblocks, size/nblocks);
  340. }
  341. TYPE *STARPU_PLU(get_block)(unsigned i, unsigned j)
  342. {
  343. return dataA[j+i*nblocks];
  344. }
  345. int get_block_rank(unsigned i, unsigned j)
  346. {
  347. /* Take a 2D block cyclic distribution */
  348. /* NB: p (resp. q) is for "direction" i (resp. j) */
  349. return (j % q) * p + (i % p);
  350. }
  351. starpu_data_handle_t STARPU_PLU(get_block_handle)(unsigned i, unsigned j)
  352. {
  353. return dataA_handles[j+i*nblocks];
  354. }
  355. static void display_grid(int rank, unsigned pnblocks)
  356. {
  357. if (!display)
  358. return;
  359. //if (rank == 0)
  360. {
  361. fprintf(stderr, "2D grid layout (Rank %d): \n", rank);
  362. unsigned i, j;
  363. for (j = 0; j < pnblocks; j++)
  364. {
  365. for (i = 0; i < pnblocks; i++)
  366. {
  367. TYPE *blockptr = STARPU_PLU(get_block)(i, j);
  368. starpu_data_handle_t handle = STARPU_PLU(get_block_handle)(i, j);
  369. fprintf(stderr, "%d (data %p handle %p)", get_block_rank(i, j), blockptr, handle);
  370. }
  371. fprintf(stderr, "\n");
  372. }
  373. }
  374. }
  375. int main(int argc, char **argv)
  376. {
  377. int rank;
  378. int world_size;
  379. int ret;
  380. unsigned i, j, k;
  381. /*
  382. * Initialization
  383. */
  384. int thread_support;
  385. if (MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &thread_support) != MPI_SUCCESS)
  386. {
  387. fprintf(stderr,"MPI_Init_thread failed\n");
  388. exit(1);
  389. }
  390. if (thread_support == MPI_THREAD_FUNNELED)
  391. fprintf(stderr,"Warning: MPI only has funneled thread support, not serialized, hoping this will work\n");
  392. if (thread_support < MPI_THREAD_FUNNELED)
  393. fprintf(stderr,"Warning: MPI does not have thread support!\n");
  394. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  395. starpu_mpi_comm_size(MPI_COMM_WORLD, &world_size);
  396. starpu_srand48((long int)time(NULL));
  397. parse_args(rank, argc, argv);
  398. ret = starpu_mpi_init_conf(NULL, NULL, 0, MPI_COMM_WORLD, NULL);
  399. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init_conf");
  400. /* We disable sequential consistency in this example */
  401. starpu_data_set_default_sequential_consistency_flag(0);
  402. if (p == -1 && q==-1)
  403. {
  404. fprintf(stderr, "Setting default values for p and q\n");
  405. p = (q % 2 == 0) ? 2 : 1;
  406. q = world_size / p;
  407. }
  408. STARPU_ASSERT_MSG(p*q == world_size, "p=%d, q=%d, world_size=%d\n", p, q, world_size);
  409. starpu_cublas_init();
  410. int barrier_ret = MPI_Barrier(MPI_COMM_WORLD);
  411. STARPU_ASSERT(barrier_ret == MPI_SUCCESS);
  412. /*
  413. * Problem Init
  414. */
  415. init_matrix(rank);
  416. fprintf(stderr, "Rank %d: allocated (%d + %d) MB = %d MB\n", rank,
  417. (int)(allocated_memory/(1024*1024)),
  418. (int)(allocated_memory_extra/(1024*1024)),
  419. (int)((allocated_memory+allocated_memory_extra)/(1024*1024)));
  420. display_grid(rank, nblocks);
  421. TYPE *a_r = NULL;
  422. // STARPU_PLU(display_data_content)(a_r, size);
  423. if (check)
  424. {
  425. TYPE *x, *y;
  426. x = calloc(size, sizeof(TYPE));
  427. STARPU_ASSERT(x);
  428. y = calloc(size, sizeof(TYPE));
  429. STARPU_ASSERT(y);
  430. if (rank == 0)
  431. {
  432. unsigned ind;
  433. for (ind = 0; ind < size; ind++)
  434. x[ind] = (TYPE)starpu_drand48();
  435. }
  436. a_r = STARPU_PLU(reconstruct_matrix)(size, nblocks);
  437. if (rank == 0)
  438. STARPU_PLU(display_data_content)(a_r, size);
  439. // STARPU_PLU(compute_ax)(size, x, y, nblocks, rank);
  440. free(x);
  441. free(y);
  442. }
  443. barrier_ret = MPI_Barrier(MPI_COMM_WORLD);
  444. STARPU_ASSERT(barrier_ret == MPI_SUCCESS);
  445. double timing = STARPU_PLU(plu_main)(nblocks, rank, world_size, no_prio);
  446. /*
  447. * Report performance
  448. */
  449. int reduce_ret;
  450. double min_timing = timing;
  451. double max_timing = timing;
  452. double sum_timing = timing;
  453. reduce_ret = MPI_Reduce(&timing, &min_timing, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD);
  454. STARPU_ASSERT(reduce_ret == MPI_SUCCESS);
  455. reduce_ret = MPI_Reduce(&timing, &max_timing, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
  456. STARPU_ASSERT(reduce_ret == MPI_SUCCESS);
  457. reduce_ret = MPI_Reduce(&timing, &sum_timing, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
  458. STARPU_ASSERT(reduce_ret == MPI_SUCCESS);
  459. if (rank == 0)
  460. {
  461. fprintf(stderr, "Computation took: %f ms\n", max_timing/1000);
  462. fprintf(stderr, "\tMIN : %f ms\n", min_timing/1000);
  463. fprintf(stderr, "\tMAX : %f ms\n", max_timing/1000);
  464. fprintf(stderr, "\tAVG : %f ms\n", sum_timing/(world_size*1000));
  465. unsigned n = size;
  466. double flop = (2.0f*n*n*n)/3.0f;
  467. fprintf(stderr, "Synthetic GFlops : %2.2f\n", (flop/max_timing/1000.0f));
  468. }
  469. /*
  470. * Test Result Correctness
  471. */
  472. if (check)
  473. {
  474. /*
  475. * Compute || A - LU ||
  476. */
  477. STARPU_PLU(compute_lu_matrix)(size, nblocks, a_r);
  478. #if 0
  479. /*
  480. * Compute || Ax - LUx ||
  481. */
  482. unsigned ind;
  483. y2 = calloc(size, sizeof(TYPE));
  484. STARPU_ASSERT(y);
  485. if (rank == 0)
  486. {
  487. for (ind = 0; ind < size; ind++)
  488. {
  489. y2[ind] = (TYPE)0.0;
  490. }
  491. }
  492. STARPU_PLU(compute_lux)(size, x, y2, nblocks, rank);
  493. /* Compute y2 = y2 - y */
  494. CPU_AXPY(size, -1.0, y, 1, y2, 1);
  495. TYPE err = CPU_ASUM(size, y2, 1);
  496. int max = CPU_IAMAX(size, y2, 1);
  497. fprintf(stderr, "(A - LU)X Avg error : %e\n", err/(size*size));
  498. fprintf(stderr, "(A - LU)X Max error : %e\n", y2[max]);
  499. #endif
  500. }
  501. /*
  502. * Termination
  503. */
  504. size_t blocksize = (size_t)(size/nblocks)*(size/nblocks)*sizeof(TYPE);
  505. for (j = 0; j < nblocks; j++)
  506. {
  507. for (i = 0; i < nblocks; i++)
  508. {
  509. starpu_data_handle_t handle = dataA_handles[j+nblocks*i];
  510. if (handle != STARPU_POISON_PTR)
  511. starpu_data_unregister(handle);
  512. TYPE *blockptr = dataA[j+i*nblocks];
  513. if (blockptr != STARPU_POISON_PTR)
  514. starpu_free_noflag(blockptr, blocksize);
  515. }
  516. }
  517. free(dataA_handles);
  518. free(dataA);
  519. #ifdef SINGLE_TMP11
  520. starpu_data_unregister(tmp_11_block_handle);
  521. starpu_free_noflag(tmp_11_block, blocksize);
  522. #else
  523. for (k = 0; k < nblocks; k++)
  524. {
  525. if (tmp_11_block_is_needed(rank, nblocks, k))
  526. {
  527. starpu_data_unregister(tmp_11_block_handles[k]);
  528. starpu_free_noflag(tmp_11_block[k], blocksize);
  529. }
  530. }
  531. free(tmp_11_block_handles);
  532. free(tmp_11_block);
  533. #endif
  534. for (k = 0; k < nblocks; k++)
  535. {
  536. #ifdef SINGLE_TMP1221
  537. if (tmp_12_block_is_needed(rank, nblocks, k))
  538. {
  539. starpu_data_unregister(tmp_12_block_handles);
  540. starpu_free_noflag(tmp_12_block[k], blocksize);
  541. }
  542. if (tmp_21_block_is_needed(rank, nblocks, k))
  543. {
  544. starpu_data_unregister(tmp_21_block_handles[k]);
  545. starpu_free_noflag(tmp_21_block[k], blocksize);
  546. }
  547. #else
  548. for (i = 0; i < 2; i++)
  549. {
  550. if (tmp_12_block_is_needed(rank, nblocks, k))
  551. {
  552. starpu_data_unregister(tmp_12_block_handles[i][k]);
  553. starpu_free_noflag(tmp_12_block[i][k], blocksize);
  554. }
  555. if (tmp_21_block_is_needed(rank, nblocks, k))
  556. {
  557. starpu_data_unregister(tmp_21_block_handles[i][k]);
  558. starpu_free_noflag(tmp_21_block[i][k], blocksize);
  559. }
  560. }
  561. #endif
  562. }
  563. #ifdef SINGLE_TMP1221
  564. free(tmp_12_block_handles);
  565. free(tmp_21_block_handles);
  566. free(tmp_12_block);
  567. free(tmp_21_block);
  568. #else
  569. for (i = 0; i < 2; i++)
  570. {
  571. free(tmp_12_block_handles[i]);
  572. free(tmp_21_block_handles[i]);
  573. free(tmp_12_block[i]);
  574. free(tmp_21_block[i]);
  575. }
  576. #endif
  577. barrier_ret = MPI_Barrier(MPI_COMM_WORLD);
  578. STARPU_ASSERT(barrier_ret == MPI_SUCCESS);
  579. starpu_cublas_shutdown();
  580. starpu_mpi_shutdown();
  581. MPI_Finalize();
  582. return 0;
  583. }