datatypes.c 18 KB

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