datatypes.c 18 KB

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