1/*
2 * Copyright (c) 2007-12 ETH Zurich.
3 * All rights reserved.
4 *
5 * This file is distributed under the terms in the attached LICENSE file.
6 * If you do not find this file, copies can be found by writing to:
7 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
8 */
9extern "C" {
10    #include <barrelfish_kpi/types.h>
11    #include <errors/errno.h>
12    #include <xomp/xomp.h>
13    #include "xomptest.h"
14}
15
16#include <iostream>
17
18#include <omp.h>
19
20using namespace std;
21
22void do_process(uint32_t *src,
23                uint32_t *dst)
24{
25    cout << "do_process C++ called " << endl;
26    if (src == NULL || dst == 0) {
27        return;
28    }
29#pragma omp parallel for
30    for (unsigned int j = 0; j < IT; j++) {
31        for (unsigned int i = 0; i < MAX; i += IT) {
32            dst[i + j] = src[i + j];
33        }
34    }
35}
36
37int main(int argc,
38         char *argv[])
39{
40    errval_t err;
41
42    xomp_wid_t wid;
43    err = xomp_worker_parse_cmdline(argc, argv, &wid);
44    switch (err_no(err)) {
45        case SYS_ERR_OK:
46            std::cout << "XOMP Test started. (WORKER) #args:" << argc << std::endl;
47            err = xomp_worker_init(wid);
48            if (err_is_fail(err)) {
49                std::cout <<  "could not initialize the worker: " << err_getstring(err) << std::endl;
50            }
51            break;
52        case XOMP_ERR_BAD_INVOCATION:
53            std::cout << "XOMP Test started. (MASTER) #args:" << argc << std::endl;
54            err = start_master(argc, argv);
55            if (err_is_fail(err)) {
56                std::cout <<  "could not start the master: " << err_getstring(err) << std::endl;
57            }
58            break;
59        default:
60            break;
61    }
62
63    if (err_is_fail(err)) {
64        std::cout <<  "error while initializing" << err_getstring(err) << std::endl;
65    }
66
67    handle_messages();
68
69    return 0;
70}
71
72