add_vectors_interface.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012,2017 Inria
  4. * Copyright (C) 2010-2014,2016,2017,2019 CNRS
  5. * Copyright (C) 2009-2011,2013-2015,2017,2018-2019 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. /*
  19. * This is a small example of a C++ program using STL and starpu. We here just
  20. * add two std::vector with duplicating vectors. StarPU achieves data
  21. * transfers between objects.
  22. */
  23. #if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNU_MINOR < 9))
  24. int main(int argc, char **argv)
  25. {
  26. return 77;
  27. }
  28. #else
  29. #include <cassert>
  30. #include <vector>
  31. #ifdef PRINT_OUTPUT
  32. #include <iostream>
  33. #endif
  34. #include <starpu.h>
  35. #define MY_TYPE char, my_allocator<char>
  36. /* create an allocator to put data on the correct NUMA node */
  37. template <class T>
  38. class my_allocator
  39. {
  40. public:
  41. typedef size_t size_type;
  42. typedef ptrdiff_t difference_type;
  43. typedef T* pointer;
  44. typedef const T* const_pointer;
  45. typedef T& reference;
  46. typedef const T& const_reference;
  47. typedef T value_type;
  48. my_allocator()
  49. {
  50. this->node = STARPU_MAIN_RAM;
  51. }
  52. my_allocator(const my_allocator& a)
  53. {
  54. node = a.get_node();
  55. }
  56. explicit my_allocator(const unsigned node)
  57. {
  58. this->node = node;
  59. }
  60. pointer allocate(size_type n, const void * = 0)
  61. {
  62. T* t = (T*) starpu_malloc_on_node(this->node, n * sizeof(T));
  63. return t;
  64. }
  65. void deallocate(void* p, size_type n)
  66. {
  67. if (p)
  68. {
  69. starpu_free_on_node(this->node, (uintptr_t) p, n * sizeof(T));
  70. }
  71. }
  72. unsigned get_node() const
  73. {
  74. return node;
  75. }
  76. pointer address(reference x) const
  77. {
  78. return &x;
  79. }
  80. const_pointer address(const_reference x) const
  81. {
  82. return &x;
  83. }
  84. my_allocator<T>& operator=(const my_allocator&ref)
  85. {
  86. node = ref.node;
  87. return *this;
  88. }
  89. void construct(pointer p, const T& val)
  90. {
  91. new ((T*) p) T(val);
  92. }
  93. void destroy(pointer p)
  94. {
  95. p->~T();
  96. }
  97. size_type max_size() const
  98. {
  99. return size_type(-1);
  100. }
  101. template <class U>
  102. struct rebind
  103. {
  104. typedef my_allocator<U> other;
  105. };
  106. template <class U>
  107. explicit my_allocator(const my_allocator<U>&ref)
  108. {
  109. node = ref.node;
  110. }
  111. template <class U>
  112. my_allocator<U>& operator=(const my_allocator<U>&ref)
  113. {
  114. node = ref.node;
  115. return *this;
  116. }
  117. private:
  118. unsigned node;
  119. };
  120. /*
  121. * Create a new interface to catch C++ vector and make appropriate data transfers
  122. */
  123. struct vector_cpp_interface
  124. {
  125. enum starpu_data_interface_id id;
  126. uintptr_t ptr;
  127. uintptr_t dev_handle;
  128. size_t offset;
  129. uint32_t nx;
  130. size_t elemsize;
  131. std::vector<MY_TYPE>* vec;
  132. uint32_t slice_base;
  133. };
  134. #define VECTOR_CPP_GET_VEC(interface) ({ (((struct vector_cpp_interface *)(interface))->vec); })
  135. static int vector_interface_copy_any_to_any(void *src_interface, unsigned src_node,
  136. void *dst_interface, unsigned dst_node, void *async_data);
  137. #if __cplusplus >= 201103L
  138. static const struct starpu_data_copy_methods vector_cpp_copy_data_methods_s =
  139. {
  140. .can_copy = NULL,
  141. .ram_to_ram = NULL,
  142. .ram_to_cuda = NULL,
  143. .ram_to_opencl = NULL,
  144. .ram_to_mic = NULL,
  145. .cuda_to_ram = NULL,
  146. .cuda_to_cuda = NULL,
  147. .cuda_to_opencl = NULL,
  148. .opencl_to_ram = NULL,
  149. .opencl_to_cuda = NULL,
  150. .opencl_to_opencl = NULL,
  151. .mic_to_ram = NULL,
  152. .scc_src_to_sink = NULL,
  153. .scc_sink_to_src = NULL,
  154. .scc_sink_to_sink = NULL,
  155. .ram_to_mpi_ms = NULL,
  156. .mpi_ms_to_ram = NULL,
  157. .mpi_ms_to_mpi_ms = NULL,
  158. .ram_to_cuda_async = NULL,
  159. .cuda_to_ram_async = NULL,
  160. .cuda_to_cuda_async = NULL,
  161. .ram_to_opencl_async = NULL,
  162. .opencl_to_ram_async = NULL,
  163. .opencl_to_opencl_async = NULL,
  164. .ram_to_mpi_ms_async = NULL,
  165. .mpi_ms_to_ram_async = NULL,
  166. .mpi_ms_to_mpi_ms_async = NULL,
  167. .ram_to_mic_async = NULL,
  168. .mic_to_ram_async = NULL,
  169. .any_to_any = vector_interface_copy_any_to_any,
  170. };
  171. #else
  172. static const struct starpu_data_copy_methods vector_cpp_copy_data_methods_s =
  173. {
  174. NULL,
  175. NULL,
  176. NULL,
  177. NULL,
  178. NULL,
  179. NULL,
  180. NULL,
  181. NULL,
  182. NULL,
  183. NULL,
  184. NULL,
  185. NULL,
  186. NULL,
  187. NULL,
  188. NULL,
  189. NULL,
  190. NULL,
  191. NULL,
  192. NULL,
  193. NULL,
  194. NULL,
  195. NULL,
  196. NULL,
  197. NULL,
  198. NULL,
  199. NULL,
  200. NULL,
  201. NULL,
  202. NULL,
  203. vector_interface_copy_any_to_any,
  204. };
  205. #endif
  206. static void register_vector_cpp_handle(starpu_data_handle_t handle, unsigned home_node, void *data_interface);
  207. static starpu_ssize_t allocate_vector_cpp_buffer_on_node(void *data_interface_, unsigned dst_node);
  208. static void *vector_cpp_to_pointer(void *data_interface, unsigned node);
  209. static int vector_cpp_pointer_is_inside(void *data_interface, unsigned node, void *ptr);
  210. static void free_vector_cpp_buffer_on_node(void *data_interface, unsigned node);
  211. static void free_vector_cpp_buffer_on_node(void *data_interface, unsigned node);
  212. static size_t vector_cpp_interface_get_size(starpu_data_handle_t handle);
  213. static uint32_t footprint_vector_cpp_interface_crc32(starpu_data_handle_t handle);
  214. static int vector_cpp_compare(void *data_interface_a, void *data_interface_b);
  215. static void display_vector_cpp_interface(starpu_data_handle_t handle, FILE *f);
  216. static int pack_vector_cpp_handle(starpu_data_handle_t handle, unsigned node, void **ptr, starpu_ssize_t *count);
  217. static int unpack_vector_cpp_handle(starpu_data_handle_t handle, unsigned node, void *ptr, size_t count);
  218. static starpu_ssize_t vector_cpp_describe(void *data_interface, char *buf, size_t size);
  219. #if __cplusplus >= 201103L
  220. static struct starpu_data_interface_ops interface_vector_cpp_ops =
  221. {
  222. .register_data_handle = register_vector_cpp_handle,
  223. .allocate_data_on_node = allocate_vector_cpp_buffer_on_node,
  224. .free_data_on_node = free_vector_cpp_buffer_on_node,
  225. .init = NULL,
  226. .copy_methods = &vector_cpp_copy_data_methods_s,
  227. .handle_to_pointer = NULL,
  228. .to_pointer = vector_cpp_to_pointer,
  229. .pointer_is_inside = vector_cpp_pointer_is_inside,
  230. .get_size = vector_cpp_interface_get_size,
  231. .get_alloc_size = NULL,
  232. .footprint = footprint_vector_cpp_interface_crc32,
  233. .alloc_footprint = NULL,
  234. .compare = vector_cpp_compare,
  235. .alloc_compare = NULL,
  236. .display = display_vector_cpp_interface,
  237. .describe = vector_cpp_describe,
  238. .interfaceid = STARPU_UNKNOWN_INTERFACE_ID,
  239. .interface_size = sizeof(struct vector_cpp_interface),
  240. .is_multiformat = 0,
  241. .dontcache = 0,
  242. .get_mf_ops = NULL,
  243. .pack_data = pack_vector_cpp_handle,
  244. .unpack_data = unpack_vector_cpp_handle,
  245. .name = (char *) "VECTOR_CPP_INTERFACE"
  246. };
  247. #else
  248. static struct starpu_data_interface_ops interface_vector_cpp_ops =
  249. {
  250. register_vector_cpp_handle,
  251. allocate_vector_cpp_buffer_on_node,
  252. free_vector_cpp_buffer_on_node,
  253. NULL,
  254. &vector_cpp_copy_data_methods_s,
  255. vector_cpp_to_pointer,
  256. vector_cpp_pointer_is_inside,
  257. vector_cpp_interface_get_size,
  258. NULL,
  259. footprint_vector_cpp_interface_crc32,
  260. NULL,
  261. vector_cpp_compare,
  262. NULL,
  263. display_vector_cpp_interface,
  264. vector_cpp_describe,
  265. STARPU_UNKNOWN_INTERFACE_ID,
  266. sizeof(struct vector_cpp_interface),
  267. 0,
  268. 0,
  269. NULL,
  270. pack_vector_cpp_handle,
  271. unpack_vector_cpp_handle,
  272. (char *) "VECTOR_CPP_INTERFACE"
  273. };
  274. #endif
  275. static void *vector_cpp_to_pointer(void *data_interface, unsigned node)
  276. {
  277. (void) node;
  278. struct vector_cpp_interface *vector_interface = (struct vector_cpp_interface *) data_interface;
  279. return (void*) vector_interface->ptr;
  280. }
  281. static int vector_cpp_pointer_is_inside(void *data_interface, unsigned int node, void *ptr)
  282. {
  283. (void) node;
  284. struct vector_cpp_interface *vector_interface = (struct vector_cpp_interface *) data_interface;
  285. return (char*) ptr >= (char*) vector_interface->ptr &&
  286. (char*) ptr < (char*) vector_interface->ptr + vector_interface->nx*vector_interface->elemsize;
  287. }
  288. static void register_vector_cpp_handle(starpu_data_handle_t handle, unsigned home_node, void *data_interface)
  289. {
  290. struct vector_cpp_interface *vector_interface = (struct vector_cpp_interface *) data_interface;
  291. unsigned node;
  292. for (node = 0; node < STARPU_MAXNODES; node++)
  293. {
  294. struct vector_cpp_interface *local_interface = (struct vector_cpp_interface *)
  295. starpu_data_get_interface_on_node(handle, node);
  296. if (node == home_node)
  297. {
  298. local_interface->ptr = vector_interface->ptr;
  299. local_interface->dev_handle = vector_interface->dev_handle;
  300. local_interface->offset = vector_interface->offset;
  301. local_interface->vec = vector_interface->vec;
  302. }
  303. else
  304. {
  305. local_interface->ptr = 0;
  306. local_interface->dev_handle = 0;
  307. local_interface->offset = 0;
  308. local_interface->vec = NULL;
  309. }
  310. local_interface->id = vector_interface->id;
  311. local_interface->nx = vector_interface->nx;
  312. local_interface->elemsize = vector_interface->elemsize;
  313. local_interface->slice_base = vector_interface->slice_base;
  314. }
  315. }
  316. /* declare a new data with the vector interface */
  317. void vector_cpp_data_register(starpu_data_handle_t *handleptr, int home_node,
  318. std::vector<MY_TYPE>* vec, uint32_t nx, size_t elemsize)
  319. {
  320. #if __cplusplus >= 201103L
  321. struct vector_cpp_interface vector =
  322. {
  323. .id = STARPU_UNKNOWN_INTERFACE_ID,
  324. .ptr = (uintptr_t) &(*vec)[0],
  325. .dev_handle = (uintptr_t) &(*vec)[0],
  326. .offset = 0,
  327. .nx = nx,
  328. .elemsize = elemsize,
  329. .vec = vec,
  330. .slice_base = 0
  331. };
  332. #else
  333. struct vector_cpp_interface vector =
  334. {
  335. STARPU_UNKNOWN_INTERFACE_ID,
  336. (uintptr_t) &(*vec)[0],
  337. (uintptr_t) &(*vec)[0],
  338. 0,
  339. nx,
  340. elemsize,
  341. vec,
  342. 0
  343. };
  344. #endif
  345. starpu_data_register(handleptr, home_node, &vector, &interface_vector_cpp_ops);
  346. }
  347. /* offer an access to the data parameters */
  348. uint32_t vector_cpp_get_nx(starpu_data_handle_t handle)
  349. {
  350. struct vector_cpp_interface *vector_interface = (struct vector_cpp_interface *)
  351. starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
  352. return vector_interface->nx;
  353. }
  354. static uint32_t footprint_vector_cpp_interface_crc32(starpu_data_handle_t handle)
  355. {
  356. return starpu_hash_crc32c_be(vector_cpp_get_nx(handle), 0);
  357. }
  358. static int vector_cpp_compare(void *data_interface_a, void *data_interface_b)
  359. {
  360. struct vector_cpp_interface *vector_a = (struct vector_cpp_interface *) data_interface_a;
  361. struct vector_cpp_interface *vector_b = (struct vector_cpp_interface *) data_interface_b;
  362. /* Two vectors are considered compatible if they have the same size */
  363. return ((vector_a->nx == vector_b->nx)
  364. && (vector_a->elemsize == vector_b->elemsize));
  365. }
  366. static void display_vector_cpp_interface(starpu_data_handle_t handle, FILE *f)
  367. {
  368. struct vector_cpp_interface *vector_interface = (struct vector_cpp_interface *)
  369. starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
  370. fprintf(f, "%u\t", vector_interface->nx);
  371. }
  372. static int pack_vector_cpp_handle(starpu_data_handle_t handle, unsigned node, void **ptr, starpu_ssize_t *count)
  373. {
  374. STARPU_ASSERT(starpu_data_test_if_allocated_on_node(handle, node));
  375. struct vector_cpp_interface *vector_interface = (struct vector_cpp_interface *)
  376. starpu_data_get_interface_on_node(handle, node);
  377. *count = vector_interface->nx*vector_interface->elemsize;
  378. if (ptr != NULL)
  379. {
  380. starpu_malloc_flags(ptr, *count, 0);
  381. memcpy(*ptr, (void*)vector_interface->ptr, vector_interface->elemsize*vector_interface->nx);
  382. }
  383. return 0;
  384. }
  385. static int unpack_vector_cpp_handle(starpu_data_handle_t handle, unsigned node, void *ptr, size_t count)
  386. {
  387. STARPU_ASSERT(starpu_data_test_if_allocated_on_node(handle, node));
  388. struct vector_cpp_interface *vector_interface = (struct vector_cpp_interface *)
  389. starpu_data_get_interface_on_node(handle, node);
  390. STARPU_ASSERT(count == vector_interface->elemsize * vector_interface->nx);
  391. memcpy((void*)vector_interface->ptr, ptr, count);
  392. return 0;
  393. }
  394. static size_t vector_cpp_interface_get_size(starpu_data_handle_t handle)
  395. {
  396. size_t size;
  397. struct vector_cpp_interface *vector_interface = (struct vector_cpp_interface *)
  398. starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
  399. size = vector_interface->nx*vector_interface->elemsize;
  400. return size;
  401. }
  402. size_t vector_cpp_get_elemsize(starpu_data_handle_t handle)
  403. {
  404. struct vector_cpp_interface *vector_interface = (struct vector_cpp_interface *)
  405. starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
  406. return vector_interface->elemsize;
  407. }
  408. /* memory allocation/deallocation primitives for the vector interface */
  409. /* returns the size of the allocated area */
  410. static starpu_ssize_t allocate_vector_cpp_buffer_on_node(void *data_interface_, unsigned dst_node)
  411. {
  412. struct vector_cpp_interface *vector_interface = (struct vector_cpp_interface *) data_interface_;
  413. uint32_t nx = vector_interface->nx;
  414. size_t elemsize = vector_interface->elemsize;
  415. starpu_ssize_t allocated_memory;
  416. const my_allocator<char> allocator(dst_node);
  417. std::vector<MY_TYPE> * vec = new std::vector<MY_TYPE>(nx, 0, allocator);
  418. vector_interface->vec = vec;
  419. if (!vector_interface->vec)
  420. return -ENOMEM;
  421. allocated_memory = nx*elemsize;
  422. /* update the data properly in consequence */
  423. vector_interface->ptr = (uintptr_t) &((*vec)[0]);
  424. vector_interface->dev_handle = (uintptr_t) &((*vec)[0]);
  425. vector_interface->offset = 0;
  426. return allocated_memory;
  427. }
  428. static void free_vector_cpp_buffer_on_node(void *data_interface, unsigned node)
  429. {
  430. struct vector_cpp_interface *vector_interface = (struct vector_cpp_interface *) data_interface;
  431. delete vector_interface->vec;
  432. }
  433. static int vector_interface_copy_any_to_any(void *src_interface, unsigned src_node,
  434. void *dst_interface, unsigned dst_node, void *async_data)
  435. {
  436. struct vector_cpp_interface *src_vector = (struct vector_cpp_interface *) src_interface;
  437. struct vector_cpp_interface *dst_vector = (struct vector_cpp_interface *) dst_interface;
  438. int ret;
  439. ret = starpu_interface_copy(src_vector->dev_handle, src_vector->offset, src_node,
  440. dst_vector->dev_handle, dst_vector->offset, dst_node,
  441. src_vector->nx*src_vector->elemsize, async_data);
  442. return ret;
  443. }
  444. static starpu_ssize_t vector_cpp_describe(void *data_interface, char *buf, size_t size)
  445. {
  446. struct vector_cpp_interface *vector = (struct vector_cpp_interface *) data_interface;
  447. return snprintf(buf, size, "V%ux%u",
  448. (unsigned) vector->nx,
  449. (unsigned) vector->elemsize);
  450. }
  451. /*
  452. * End of interface
  453. */
  454. /* Kernel using STL objects */
  455. void cpu_kernel_add_vectors(void *buffers[], void *cl_arg)
  456. {
  457. std::vector<MY_TYPE>* vec_A = VECTOR_CPP_GET_VEC(buffers[0]);
  458. std::vector<MY_TYPE>* vec_B = VECTOR_CPP_GET_VEC(buffers[1]);
  459. std::vector<MY_TYPE>* vec_C = VECTOR_CPP_GET_VEC(buffers[2]);
  460. // all the std::vector have to have the same size
  461. assert(vec_A->size() == vec_B->size() && vec_B->size() == vec_C->size());
  462. // performs the vector addition (vec_C[] = vec_A[] + vec_B[])
  463. for (size_t i = 0; i < vec_C->size(); i++)
  464. (*vec_C)[i] = (*vec_A)[i] + (*vec_B)[i];
  465. }
  466. #define VEC_SIZE 1024
  467. int main(int argc, char **argv)
  468. {
  469. struct starpu_conf conf;
  470. starpu_conf_init(&conf);
  471. conf.nmic = 0;
  472. conf.nscc = 0;
  473. conf.nmpi_ms = 0;
  474. // initialize StarPU with default configuration
  475. int ret = starpu_init(&conf);
  476. if (ret == -ENODEV)
  477. return 77;
  478. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  479. /* Test data transfers between NUMA nodes if available */
  480. unsigned last_numa_node = starpu_memory_nodes_get_numa_count() - 1;
  481. const my_allocator<char> allocator_main_ram(STARPU_MAIN_RAM);
  482. const my_allocator<char> allocator_last_numa(last_numa_node);
  483. std::vector<MY_TYPE> vec_A(VEC_SIZE, 2, allocator_main_ram); // all the vector is initialized to 2
  484. std::vector<MY_TYPE> vec_B(VEC_SIZE, 3, allocator_main_ram); // all the vector is initialized to 3
  485. std::vector<MY_TYPE> vec_C(VEC_SIZE, 0, allocator_last_numa); // all the vector is initialized to 0
  486. // StarPU data registering
  487. starpu_data_handle_t spu_vec_A;
  488. starpu_data_handle_t spu_vec_B;
  489. starpu_data_handle_t spu_vec_C;
  490. // give the data of the vector to StarPU (C array)
  491. vector_cpp_data_register(&spu_vec_A, STARPU_MAIN_RAM, &vec_A, vec_A.size(), sizeof(char));
  492. vector_cpp_data_register(&spu_vec_B, STARPU_MAIN_RAM, &vec_B, vec_B.size(), sizeof(char));
  493. vector_cpp_data_register(&spu_vec_C, last_numa_node, &vec_C, vec_C.size(), sizeof(char));
  494. // create the StarPU codelet
  495. starpu_codelet cl;
  496. starpu_codelet_init(&cl);
  497. cl.cpu_funcs [0] = cpu_kernel_add_vectors;
  498. cl.cpu_funcs_name[0] = "cpu_kernel_add_vectors";
  499. cl.nbuffers = 3;
  500. cl.modes [0] = STARPU_R;
  501. cl.modes [1] = STARPU_R;
  502. cl.modes [2] = STARPU_W;
  503. cl.name = "add_vectors";
  504. // submit a new StarPU task to execute
  505. ret = starpu_task_insert(&cl,
  506. STARPU_R, spu_vec_A,
  507. STARPU_R, spu_vec_B,
  508. STARPU_W, spu_vec_C,
  509. 0);
  510. if (ret == -ENODEV)
  511. {
  512. // StarPU data unregistering
  513. starpu_data_unregister(spu_vec_C);
  514. starpu_data_unregister(spu_vec_B);
  515. starpu_data_unregister(spu_vec_A);
  516. // terminate StarPU, no task can be submitted after
  517. starpu_shutdown();
  518. return 77;
  519. }
  520. STARPU_CHECK_RETURN_VALUE(ret, "task_submit::add_vectors");
  521. // wait the task
  522. starpu_task_wait_for_all();
  523. // StarPU data unregistering
  524. starpu_data_unregister(spu_vec_C);
  525. starpu_data_unregister(spu_vec_B);
  526. starpu_data_unregister(spu_vec_A);
  527. // terminate StarPU, no task can be submitted after
  528. starpu_shutdown();
  529. // check results
  530. bool fail = false;
  531. int i = 0;
  532. while (!fail && i < VEC_SIZE)
  533. fail = vec_C[i++] != 5;
  534. if (fail)
  535. {
  536. #ifdef PRINT_OUTPUT
  537. std::cout << "Example failed..." << std::endl;
  538. #endif
  539. return EXIT_FAILURE;
  540. }
  541. else
  542. {
  543. #ifdef PRINT_OUTPUT
  544. std::cout << "Example successfully passed!" << std::endl;
  545. #endif
  546. return EXIT_SUCCESS;
  547. }
  548. }
  549. #endif