add_vectors_interface.cpp 17 KB

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