From ed0b89daeb71e47e944a6df2a0841bd27c38630f Mon Sep 17 00:00:00 2001 From: Marcus Winter Date: Wed, 25 Mar 2015 13:28:29 +0100 Subject: [PATCH] examples, tutorial: fixed mtapi_cpp --- doc/examples/mtapi/mtapi_cpp-fragmented.cc | 5 ++--- doc/examples/mtapi/mtapi_cpp_main-snippet.h | 6 ++++++ doc/examples/mtapi/mtapi_cpp_wait_task-snippet.h | 5 ++++- doc/tutorial/content/mtapi.tex | 6 +++++- 4 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 doc/examples/mtapi/mtapi_cpp_main-snippet.h diff --git a/doc/examples/mtapi/mtapi_cpp-fragmented.cc b/doc/examples/mtapi/mtapi_cpp-fragmented.cc index a87f11b..d211fd9 100644 --- a/doc/examples/mtapi/mtapi_cpp-fragmented.cc +++ b/doc/examples/mtapi/mtapi_cpp-fragmented.cc @@ -45,7 +45,7 @@ static #include "mtapi/mtapi_c_calc_direct-snippet.h" /* wait for completion */ #include "mtapi/mtapi_cpp_wait_task-snippet.h" - /* add the two preceeding numbers */ + /* add the two preceding numbers */ #include "mtapi/mtapi_write_back-snippet.h" static @@ -63,6 +63,5 @@ int fibonacci(int n) { } void RunMTAPI_CPP() { - int result = fibonacci(6); - std::cout << "result: " << result << std::endl; +#include "mtapi/mtapi_cpp_main-snippet.h" } diff --git a/doc/examples/mtapi/mtapi_cpp_main-snippet.h b/doc/examples/mtapi/mtapi_cpp_main-snippet.h new file mode 100644 index 0000000..582850a --- /dev/null +++ b/doc/examples/mtapi/mtapi_cpp_main-snippet.h @@ -0,0 +1,6 @@ + EMBB_TRY { + int result = fibonacci(6); + std::cout << "result: " << result << std::endl; + } EMBB_CATCH(embb::mtapi::StatusException &) { + std::cout << "MTAPI error occured." << std::endl; + } diff --git a/doc/examples/mtapi/mtapi_cpp_wait_task-snippet.h b/doc/examples/mtapi/mtapi_cpp_wait_task-snippet.h index 21637fd..9f1f9d7 100644 --- a/doc/examples/mtapi/mtapi_cpp_wait_task-snippet.h +++ b/doc/examples/mtapi/mtapi_cpp_wait_task-snippet.h @@ -1,2 +1,5 @@ mtapi_status_t status = task.Wait(MTAPI_INFINITE); - MTAPI_CHECK_STATUS(status); + if (status != MTAPI_SUCCESS) { + printf("task failed with error: %d\n\n", status); + exit(status); + } diff --git a/doc/tutorial/content/mtapi.tex b/doc/tutorial/content/mtapi.tex index 6b52cb6..956e93a 100644 --- a/doc/tutorial/content/mtapi.tex +++ b/doc/tutorial/content/mtapi.tex @@ -156,7 +156,7 @@ After everything is done, the action is deleted (\lstinline|mtapi_action_delete( % \\\inputlisting{../examples/mtapi/mtapi_c_action_signature-snippet.h} % -Checking the arguments and the result buffer is not done this time for simplicity. However, the terminating condition of the recursion still needs to be checked: +Checking argument and result buffer sizes is the same as in the C example. Also, the terminating condition of the recursion still needs to be checked: % \\\inputlisting{../examples/mtapi/mtapi_terminating_condition-snippet.h} % @@ -176,6 +176,10 @@ Finally, the two parts can be added and written into the result buffer: % \\\inputlisting{../examples/mtapi/mtapi_write_back-snippet.h} % +Note that there is no need to do error checking everywhere, since errors are reported as exceptions. In this example there is only a single try/catch block in the main function: +% +\\\inputlisting{../examples/mtapi/mtapi_cpp_main-snippet.h} +% The \lstinline|fibonacci()| function is about the same as in the C version. The MTAPI runtime needs to be initialized first: % -- libgit2 0.26.0