Commit ed0b89da by Marcus Winter

examples, tutorial: fixed mtapi_cpp

parent 9f038e87
......@@ -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"
}
EMBB_TRY {
int result = fibonacci(6);
std::cout << "result: " << result << std::endl;
} EMBB_CATCH(embb::mtapi::StatusException &) {
std::cout << "MTAPI error occured." << std::endl;
}
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);
}
......@@ -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:
%
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment