datatypes.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <starpu_mpi.h>
  17. #include <stdlib.h>
  18. #include "helper.h"
  19. typedef void (*check_func)(starpu_data_handle_t handle_s, starpu_data_handle_t handle_r, int *error);
  20. void send_recv_and_check(int rank, int node, starpu_data_handle_t handle_s, int tag_s, starpu_data_handle_t handle_r, int tag_r, int *error, check_func func)
  21. {
  22. int ret;
  23. MPI_Status status;
  24. if (rank == 0)
  25. {
  26. ret = starpu_mpi_send(handle_s, node, tag_s, MPI_COMM_WORLD);
  27. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_send");
  28. ret = starpu_mpi_recv(handle_r, node, tag_r, MPI_COMM_WORLD, &status);
  29. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_recv");
  30. assert(func);
  31. func(handle_s, handle_r, error);
  32. }
  33. else if (rank == 1)
  34. {
  35. ret = starpu_mpi_recv(handle_s, node, tag_s, MPI_COMM_WORLD, &status);
  36. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_recv");
  37. ret = starpu_mpi_send(handle_s, node, tag_r, MPI_COMM_WORLD);
  38. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_send");
  39. }
  40. }
  41. /*
  42. * Void
  43. */
  44. void check_void(starpu_data_handle_t handle_s, starpu_data_handle_t handle_r, int *error)
  45. {
  46. (void)error;
  47. (void)handle_s;
  48. (void)handle_r;
  49. FPRINTF_MPI(stderr, "Success with void value\n");
  50. }
  51. void exchange_void(int rank, int *error)
  52. {
  53. STARPU_SKIP_IF_VALGRIND;
  54. if (rank == 0)
  55. {
  56. starpu_data_handle_t void_handle[2];
  57. starpu_void_data_register(&void_handle[0]);
  58. starpu_void_data_register(&void_handle[1]);
  59. send_recv_and_check(rank, 1, void_handle[0], 0x42, void_handle[1], 0x1337, error, check_void);
  60. starpu_data_unregister(void_handle[0]);
  61. starpu_data_unregister(void_handle[1]);
  62. }
  63. else if (rank == 1)
  64. {
  65. starpu_data_handle_t void_handle;
  66. starpu_void_data_register(&void_handle);
  67. send_recv_and_check(rank, 0, void_handle, 0x42, NULL, 0x1337, NULL, NULL);
  68. starpu_data_unregister(void_handle);
  69. }
  70. }
  71. /*
  72. * Variable
  73. */
  74. void check_variable(starpu_data_handle_t handle_s, starpu_data_handle_t handle_r, int *error)
  75. {
  76. float *v_s, *v_r;
  77. STARPU_ASSERT(starpu_variable_get_elemsize(handle_s) == starpu_variable_get_elemsize(handle_r));
  78. v_s = (float *)starpu_variable_get_local_ptr(handle_s);
  79. v_r = (float *)starpu_variable_get_local_ptr(handle_r);
  80. if (*v_s == *v_r)
  81. {
  82. FPRINTF_MPI(stderr, "Success with variable value: %f == %f\n", *v_s, *v_r);
  83. }
  84. else
  85. {
  86. *error = 1;
  87. FPRINTF_MPI(stderr, "Error with variable value: %f != %f\n", *v_s, *v_r);
  88. }
  89. }
  90. void exchange_variable(int rank, int *error)
  91. {
  92. if (rank == 0)
  93. {
  94. float v = 42.12;
  95. starpu_data_handle_t variable_handle[2];
  96. starpu_variable_data_register(&variable_handle[0], STARPU_MAIN_RAM, (uintptr_t)&v, sizeof(v));
  97. starpu_variable_data_register(&variable_handle[1], -1, (uintptr_t)NULL, sizeof(v));
  98. send_recv_and_check(rank, 1, variable_handle[0], 0x42, variable_handle[1], 0x1337, error, check_variable);
  99. starpu_data_unregister(variable_handle[0]);
  100. starpu_data_unregister(variable_handle[1]);
  101. }
  102. else if (rank == 1)
  103. {
  104. starpu_data_handle_t variable_handle;
  105. starpu_variable_data_register(&variable_handle, -1, (uintptr_t)NULL, sizeof(float));
  106. send_recv_and_check(rank, 0, variable_handle, 0x42, NULL, 0x1337, NULL, NULL);
  107. starpu_data_unregister(variable_handle);
  108. }
  109. }
  110. /*
  111. * Vector
  112. */
  113. void check_vector(starpu_data_handle_t handle_s, starpu_data_handle_t handle_r, int *error)
  114. {
  115. int i;
  116. int nx;
  117. int *v_r, *v_s;
  118. STARPU_ASSERT(starpu_vector_get_elemsize(handle_s) == starpu_vector_get_elemsize(handle_r));
  119. STARPU_ASSERT(starpu_vector_get_nx(handle_s) == starpu_vector_get_nx(handle_r));
  120. nx = starpu_vector_get_nx(handle_r);
  121. v_r = (int *)starpu_vector_get_local_ptr(handle_r);
  122. v_s = (int *)starpu_vector_get_local_ptr(handle_s);
  123. for(i=0 ; i<nx ; i++)
  124. {
  125. if (v_s[i] == v_r[i])
  126. {
  127. FPRINTF_MPI(stderr, "Success with vector[%d] value: %d == %d\n", i, v_s[i], v_r[i]);
  128. }
  129. else
  130. {
  131. *error = 1;
  132. FPRINTF_MPI(stderr, "Error with vector[%d] value: %d != %d\n", i, v_s[i], v_r[i]);
  133. }
  134. }
  135. }
  136. void exchange_vector(int rank, int *error)
  137. {
  138. if (rank == 0)
  139. {
  140. int vector[4] = {1, 2, 3, 4};
  141. starpu_data_handle_t vector_handle[2];
  142. starpu_vector_data_register(&vector_handle[0], STARPU_MAIN_RAM, (uintptr_t)vector, 4, sizeof(vector[0]));
  143. starpu_vector_data_register(&vector_handle[1], -1, (uintptr_t)NULL, 4, sizeof(vector[0]));
  144. send_recv_and_check(rank, 1, vector_handle[0], 0x43, vector_handle[1], 0x2337, error, check_vector);
  145. starpu_data_unregister(vector_handle[0]);
  146. starpu_data_unregister(vector_handle[1]);
  147. }
  148. else if (rank == 1)
  149. {
  150. starpu_data_handle_t vector_handle;
  151. starpu_vector_data_register(&vector_handle, -1, (uintptr_t)NULL, 4, sizeof(int));
  152. send_recv_and_check(rank, 0, vector_handle, 0x43, NULL, 0x2337, NULL, NULL);
  153. starpu_data_unregister(vector_handle);
  154. }
  155. }
  156. /*
  157. * Matrix
  158. */
  159. void check_matrix(starpu_data_handle_t handle_s, starpu_data_handle_t handle_r, int *error)
  160. {
  161. STARPU_ASSERT(starpu_matrix_get_elemsize(handle_s) == starpu_matrix_get_elemsize(handle_r));
  162. STARPU_ASSERT(starpu_matrix_get_nx(handle_s) == starpu_matrix_get_nx(handle_r));
  163. STARPU_ASSERT(starpu_matrix_get_ny(handle_s) == starpu_matrix_get_ny(handle_r));
  164. STARPU_ASSERT(starpu_matrix_get_local_ld(handle_s) == starpu_matrix_get_local_ld(handle_r));
  165. char *matrix_s = (char *)starpu_matrix_get_local_ptr(handle_s);
  166. char *matrix_r = (char *)starpu_matrix_get_local_ptr(handle_r);
  167. int nx = starpu_matrix_get_nx(handle_s);
  168. int ny = starpu_matrix_get_ny(handle_s);
  169. int ldy = starpu_matrix_get_local_ld(handle_s);
  170. int x, y;
  171. for(y=0 ; y<ny ; y++)
  172. {
  173. for(x=0 ; x<nx ; x++)
  174. {
  175. int index=(y*ldy)+x;
  176. if (matrix_s[index] == matrix_r[index])
  177. {
  178. FPRINTF_MPI(stderr, "Success with matrix[%d,%d --> %d] value: %c == %c\n", x, y, index, matrix_s[index], matrix_r[index]);
  179. }
  180. else
  181. {
  182. *error = 1;
  183. FPRINTF_MPI(stderr, "Error with matrix[%d,%d --> %d] value: %c != %c\n", x, y, index, matrix_s[index], matrix_r[index]);
  184. }
  185. }
  186. }
  187. }
  188. void exchange_matrix(int rank, int *error)
  189. {
  190. int nx=3;
  191. int ny=2;
  192. if (rank == 0)
  193. {
  194. char *matrix, n='a';
  195. int x, y;
  196. starpu_data_handle_t matrix_handle[2];
  197. matrix = (char*)malloc(nx*ny*sizeof(char));
  198. assert(matrix);
  199. for(y=0 ; y<ny ; y++)
  200. {
  201. for(x=0 ; x<nx ; x++)
  202. {
  203. matrix[(y*nx)+x] = n++;
  204. }
  205. }
  206. starpu_matrix_data_register(&matrix_handle[0], STARPU_MAIN_RAM, (uintptr_t)matrix, nx, nx, ny, sizeof(char));
  207. starpu_matrix_data_register(&matrix_handle[1], -1, (uintptr_t)NULL, nx, nx, ny, sizeof(char));
  208. send_recv_and_check(rank, 1, matrix_handle[0], 0x75, matrix_handle[1], 0x8555, error, check_matrix);
  209. starpu_data_unregister(matrix_handle[0]);
  210. starpu_data_unregister(matrix_handle[1]);
  211. free(matrix);
  212. }
  213. else if (rank == 1)
  214. {
  215. starpu_data_handle_t matrix_handle;
  216. starpu_matrix_data_register(&matrix_handle, -1, (uintptr_t)NULL, nx, nx, ny, sizeof(char));
  217. send_recv_and_check(rank, 0, matrix_handle, 0x75, NULL, 0x8555, NULL, NULL);
  218. starpu_data_unregister(matrix_handle);
  219. }
  220. }
  221. /*
  222. * Block
  223. */
  224. void check_block(starpu_data_handle_t handle_s, starpu_data_handle_t handle_r, int *error)
  225. {
  226. STARPU_ASSERT(starpu_block_get_elemsize(handle_s) == starpu_block_get_elemsize(handle_r));
  227. STARPU_ASSERT(starpu_block_get_nx(handle_s) == starpu_block_get_nx(handle_r));
  228. STARPU_ASSERT(starpu_block_get_ny(handle_s) == starpu_block_get_ny(handle_r));
  229. STARPU_ASSERT(starpu_block_get_nz(handle_s) == starpu_block_get_nz(handle_r));
  230. STARPU_ASSERT(starpu_block_get_local_ldy(handle_s) == starpu_block_get_local_ldy(handle_r));
  231. STARPU_ASSERT(starpu_block_get_local_ldz(handle_s) == starpu_block_get_local_ldz(handle_r));
  232. starpu_data_acquire(handle_s, STARPU_R);
  233. starpu_data_acquire(handle_r, STARPU_R);
  234. float *block_s = (float *)starpu_block_get_local_ptr(handle_s);
  235. float *block_r = (float *)starpu_block_get_local_ptr(handle_r);
  236. int nx = starpu_block_get_nx(handle_s);
  237. int ny = starpu_block_get_ny(handle_s);
  238. int nz = starpu_block_get_nz(handle_s);
  239. int ldy = starpu_block_get_local_ldy(handle_s);
  240. int ldz = starpu_block_get_local_ldz(handle_s);
  241. int x, y, z;
  242. for(z=0 ; z<nz ; z++)
  243. {
  244. for(y=0 ; y<ny ; y++)
  245. for(x=0 ; x<nx ; x++)
  246. {
  247. int index=(z*ldz)+(y*ldy)+x;
  248. if (block_s[index] == block_r[index])
  249. {
  250. FPRINTF_MPI(stderr, "Success with block[%d,%d,%d --> %d] value: %f == %f\n", x, y, z, index, block_s[index], block_r[index]);
  251. }
  252. else
  253. {
  254. *error = 1;
  255. FPRINTF_MPI(stderr, "Error with block[%d,%d,%d --> %d] value: %f != %f\n", x, y, z, index, block_s[index], block_r[index]);
  256. }
  257. }
  258. }
  259. starpu_data_release(handle_s);
  260. starpu_data_release(handle_r);
  261. }
  262. void exchange_block(int rank, int *error)
  263. {
  264. int nx=3;
  265. int ny=2;
  266. int nz=4;
  267. if (rank == 0)
  268. {
  269. float *block, n=1.0;
  270. int x, y, z;
  271. starpu_data_handle_t block_handle[2];
  272. block = (float*)malloc(nx*ny*nz*sizeof(float));
  273. assert(block);
  274. for(z=0 ; z<nz ; z++)
  275. {
  276. for(y=0 ; y<ny ; y++)
  277. {
  278. for(x=0 ; x<nx ; x++)
  279. {
  280. block[(z*nx*ny)+(y*nx)+x] = n++;
  281. }
  282. }
  283. }
  284. starpu_block_data_register(&block_handle[0], STARPU_MAIN_RAM, (uintptr_t)block, nx, nx*ny, nx, ny, nz, sizeof(float));
  285. starpu_block_data_register(&block_handle[1], -1, (uintptr_t)NULL, nx, nx*ny, nx, ny, nz, sizeof(float));
  286. send_recv_and_check(rank, 1, block_handle[0], 0x73, block_handle[1], 0x8337, error, check_block);
  287. starpu_data_unregister(block_handle[0]);
  288. starpu_data_unregister(block_handle[1]);
  289. free(block);
  290. }
  291. else if (rank == 1)
  292. {
  293. starpu_data_handle_t block_handle;
  294. starpu_block_data_register(&block_handle, -1, (uintptr_t)NULL, nx, nx*ny, nx, ny, nz, sizeof(float));
  295. send_recv_and_check(rank, 0, block_handle, 0x73, NULL, 0x8337, NULL, NULL);
  296. starpu_data_unregister(block_handle);
  297. }
  298. }
  299. /*
  300. * BCSR
  301. */
  302. void check_bcsr(starpu_data_handle_t handle_s, starpu_data_handle_t handle_r, int *error)
  303. {
  304. STARPU_ASSERT(starpu_bcsr_get_elemsize(handle_s) == starpu_bcsr_get_elemsize(handle_r));
  305. STARPU_ASSERT(starpu_bcsr_get_nnz(handle_s) == starpu_bcsr_get_nnz(handle_r));
  306. STARPU_ASSERT(starpu_bcsr_get_nrow(handle_s) == starpu_bcsr_get_nrow(handle_r));
  307. STARPU_ASSERT(starpu_bcsr_get_firstentry(handle_s) == starpu_bcsr_get_firstentry(handle_r));
  308. STARPU_ASSERT(starpu_bcsr_get_r(handle_s) == starpu_bcsr_get_r(handle_r));
  309. STARPU_ASSERT(starpu_bcsr_get_c(handle_s) == starpu_bcsr_get_c(handle_r));
  310. starpu_data_acquire(handle_s, STARPU_R);
  311. starpu_data_acquire(handle_r, STARPU_R);
  312. uint32_t *colind_s = starpu_bcsr_get_local_colind(handle_s);
  313. uint32_t *colind_r = starpu_bcsr_get_local_colind(handle_r);
  314. uint32_t *rowptr_s = starpu_bcsr_get_local_rowptr(handle_s);
  315. uint32_t *rowptr_r = starpu_bcsr_get_local_rowptr(handle_r);
  316. int *bcsr_s = (int *)starpu_bcsr_get_local_nzval(handle_s);
  317. int *bcsr_r = (int *)starpu_bcsr_get_local_nzval(handle_r);
  318. int r = starpu_bcsr_get_r(handle_s);
  319. int c = starpu_bcsr_get_c(handle_s);
  320. int nnz = starpu_bcsr_get_nnz(handle_s);
  321. int nrows = starpu_bcsr_get_nrow(handle_s);
  322. int x;
  323. for(x=0 ; x<nnz ; x++)
  324. {
  325. if (colind_s[x] == colind_r[x])
  326. {
  327. FPRINTF_MPI(stderr, "Success with colind[%d] value: %u == %u\n", x, colind_s[x], colind_r[x]);
  328. }
  329. else
  330. {
  331. *error = 1;
  332. FPRINTF_MPI(stderr, "Error with colind[%d] value: %u != %u\n", x, colind_s[x], colind_r[x]);
  333. }
  334. }
  335. for(x=0 ; x<nrows+1 ; x++)
  336. {
  337. if (rowptr_s[x] == rowptr_r[x])
  338. {
  339. FPRINTF_MPI(stderr, "Success with rowptr[%d] value: %u == %u\n", x, rowptr_s[x], rowptr_r[x]);
  340. }
  341. else
  342. {
  343. *error = 1;
  344. FPRINTF_MPI(stderr, "Error with rowptr[%d] value: %u != %u\n", x, rowptr_s[x], rowptr_r[x]);
  345. }
  346. }
  347. for(x=0 ; x<r*c*nnz ; x++)
  348. {
  349. if (bcsr_s[x] == bcsr_r[x])
  350. {
  351. FPRINTF_MPI(stderr, "Success with bcsr[%d] value: %d == %d\n", x, bcsr_s[x], bcsr_r[x]);
  352. }
  353. else
  354. {
  355. *error = 1;
  356. FPRINTF_MPI(stderr, "Error with bcsr[%d] value: %d != %d\n", x, bcsr_s[x], bcsr_r[x]);
  357. }
  358. }
  359. starpu_data_release(handle_s);
  360. starpu_data_release(handle_r);
  361. }
  362. void exchange_bcsr(int rank, int *error)
  363. {
  364. /*
  365. * We use the following matrix:
  366. *
  367. * +----------------+
  368. * | 0 1 0 0 |
  369. * | 2 3 0 0 |
  370. * | 4 5 8 9 |
  371. * | 6 7 10 11 |
  372. * +----------------+
  373. *
  374. * nzval = [0, 1, 2, 3] ++ [4, 5, 6, 7] ++ [8, 9, 10, 11]
  375. * colind = [0, 0, 1]
  376. * rowptr = [0, 1, 3]
  377. * r = c = 2
  378. */
  379. /* Size of the blocks */
  380. #define BCSR_R 2
  381. #define BCSR_C 2
  382. #define BCSR_NROWS 2
  383. #define BCSR_NNZ_BLOCKS 3 /* out of 4 */
  384. #define BCSR_NZVAL_SIZE (BCSR_R*BCSR_C*BCSR_NNZ_BLOCKS)
  385. if (rank == 0)
  386. {
  387. starpu_data_handle_t bcsr_handle[2];
  388. uint32_t colind[BCSR_NNZ_BLOCKS] = {0, 0, 1};
  389. uint32_t rowptr[BCSR_NROWS+1] = {0, 1, BCSR_NNZ_BLOCKS};
  390. int nzval[BCSR_NZVAL_SIZE] =
  391. {
  392. 0, 1, 2, 3, /* First block */
  393. 4, 5, 6, 7, /* Second block */
  394. 8, 9, 10, 11 /* Third block */
  395. };
  396. starpu_bcsr_data_register(&bcsr_handle[0], STARPU_MAIN_RAM, BCSR_NNZ_BLOCKS, BCSR_NROWS, (uintptr_t) nzval, colind, rowptr, 0, BCSR_R, BCSR_C, sizeof(nzval[0]));
  397. starpu_bcsr_data_register(&bcsr_handle[1], -1, BCSR_NNZ_BLOCKS, BCSR_NROWS, (uintptr_t) NULL, (uint32_t *) NULL, (uint32_t *) NULL, 0, BCSR_R, BCSR_C, sizeof(nzval[0]));
  398. send_recv_and_check(rank, 1, bcsr_handle[0], 0x73, bcsr_handle[1], 0x8337, error, check_bcsr);
  399. starpu_data_unregister(bcsr_handle[0]);
  400. starpu_data_unregister(bcsr_handle[1]);
  401. }
  402. else if (rank == 1)
  403. {
  404. starpu_data_handle_t bcsr_handle;
  405. starpu_bcsr_data_register(&bcsr_handle, -1, BCSR_NNZ_BLOCKS, BCSR_NROWS, (uintptr_t) NULL, (uint32_t *) NULL, (uint32_t *) NULL, 0, BCSR_R, BCSR_C, sizeof(int));
  406. send_recv_and_check(rank, 0, bcsr_handle, 0x73, NULL, 0x8337, NULL, NULL);
  407. starpu_data_unregister(bcsr_handle);
  408. }
  409. }
  410. /*
  411. * CSR
  412. */
  413. void check_csr(starpu_data_handle_t handle_s, starpu_data_handle_t handle_r, int *error)
  414. {
  415. STARPU_ASSERT(starpu_csr_get_elemsize(handle_s) == starpu_csr_get_elemsize(handle_r));
  416. STARPU_ASSERT(starpu_csr_get_nnz(handle_s) == starpu_csr_get_nnz(handle_r));
  417. STARPU_ASSERT(starpu_csr_get_nrow(handle_s) == starpu_csr_get_nrow(handle_r));
  418. STARPU_ASSERT(starpu_csr_get_firstentry(handle_s) == starpu_csr_get_firstentry(handle_r));
  419. starpu_data_acquire(handle_s, STARPU_R);
  420. starpu_data_acquire(handle_r, STARPU_R);
  421. uint32_t *colind_s = starpu_csr_get_local_colind(handle_s);
  422. uint32_t *colind_r = starpu_csr_get_local_colind(handle_r);
  423. uint32_t *rowptr_s = starpu_csr_get_local_rowptr(handle_s);
  424. uint32_t *rowptr_r = starpu_csr_get_local_rowptr(handle_r);
  425. int *csr_s = (int *)starpu_csr_get_local_nzval(handle_s);
  426. int *csr_r = (int *)starpu_csr_get_local_nzval(handle_r);
  427. int nnz = starpu_csr_get_nnz(handle_s);
  428. int nrows = starpu_csr_get_nrow(handle_s);
  429. int x;
  430. for(x=0 ; x<nnz ; x++)
  431. {
  432. if (colind_s[x] == colind_r[x])
  433. {
  434. FPRINTF_MPI(stderr, "Success with colind[%d] value: %u == %u\n", x, colind_s[x], colind_r[x]);
  435. }
  436. else
  437. {
  438. *error = 1;
  439. FPRINTF_MPI(stderr, "Error with colind[%d] value: %u != %u\n", x, colind_s[x], colind_r[x]);
  440. }
  441. }
  442. for(x=0 ; x<nrows+1 ; x++)
  443. {
  444. if (rowptr_s[x] == rowptr_r[x])
  445. {
  446. FPRINTF_MPI(stderr, "Success with rowptr[%d] value: %u == %u\n", x, rowptr_s[x], rowptr_r[x]);
  447. }
  448. else
  449. {
  450. *error = 1;
  451. FPRINTF_MPI(stderr, "Error with rowptr[%d] value: %u != %u\n", x, rowptr_s[x], rowptr_r[x]);
  452. }
  453. }
  454. for(x=0 ; x<nnz ; x++)
  455. {
  456. if (csr_s[x] == csr_r[x])
  457. {
  458. FPRINTF_MPI(stderr, "Success with csr[%d] value: %d == %d\n", x, csr_s[x], csr_r[x]);
  459. }
  460. else
  461. {
  462. *error = 1;
  463. FPRINTF_MPI(stderr, "Error with csr[%d] value: %d != %d\n", x, csr_s[x], csr_r[x]);
  464. }
  465. }
  466. starpu_data_release(handle_s);
  467. starpu_data_release(handle_r);
  468. }
  469. void exchange_csr(int rank, int *error)
  470. {
  471. // the values are completely wrong, we just want to test that the communication is done correctly
  472. #define CSR_NROWS 2
  473. #define CSR_NNZ 5
  474. if (rank == 0)
  475. {
  476. starpu_data_handle_t csr_handle[2];
  477. uint32_t colind[CSR_NNZ] = {0, 1, 2, 3, 4};
  478. uint32_t rowptr[CSR_NROWS+1] = {0, 1, CSR_NNZ};
  479. int nzval[CSR_NNZ] = { 11, 22, 33, 44, 55 };
  480. starpu_csr_data_register(&csr_handle[0], STARPU_MAIN_RAM, CSR_NNZ, CSR_NROWS, (uintptr_t) nzval, colind, rowptr, 0, sizeof(nzval[0]));
  481. starpu_csr_data_register(&csr_handle[1], -1, CSR_NNZ, CSR_NROWS, (uintptr_t) NULL, (uint32_t *) NULL, (uint32_t *) NULL, 0, sizeof(nzval[0]));
  482. send_recv_and_check(rank, 1, csr_handle[0], 0x84, csr_handle[1], 0x8765, error, check_csr);
  483. starpu_data_unregister(csr_handle[0]);
  484. starpu_data_unregister(csr_handle[1]);
  485. }
  486. else if (rank == 1)
  487. {
  488. starpu_data_handle_t csr_handle;
  489. starpu_csr_data_register(&csr_handle, -1, CSR_NNZ, CSR_NROWS, (uintptr_t) NULL, (uint32_t *) NULL, (uint32_t *) NULL, 0, sizeof(int));
  490. send_recv_and_check(rank, 0, csr_handle, 0x84, NULL, 0x8765, NULL, NULL);
  491. starpu_data_unregister(csr_handle);
  492. }
  493. }
  494. int main(int argc, char **argv)
  495. {
  496. int ret, rank, size;
  497. int error=0;
  498. int mpi_init;
  499. MPI_INIT_THREAD(&argc, &argv, MPI_THREAD_SERIALIZED, &mpi_init);
  500. ret = starpu_mpi_init_conf(&argc, &argv, mpi_init, MPI_COMM_WORLD, NULL);
  501. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init_conf");
  502. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  503. starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
  504. if (size < 2)
  505. {
  506. if (rank == 0)
  507. FPRINTF(stderr, "We need at least 2 processes.\n");
  508. starpu_mpi_shutdown();
  509. if (!mpi_init)
  510. MPI_Finalize();
  511. return STARPU_TEST_SKIPPED;
  512. }
  513. exchange_void(rank, &error);
  514. exchange_variable(rank, &error);
  515. exchange_vector(rank, &error);
  516. exchange_matrix(rank, &error);
  517. exchange_block(rank, &error);
  518. exchange_bcsr(rank, &error);
  519. exchange_csr(rank, &error);
  520. starpu_mpi_shutdown();
  521. if (!mpi_init)
  522. MPI_Finalize();
  523. return rank == 0 ? error : 0;
  524. }