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: %