datatypes.c 18 KB

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