1/**
2 * \file
3 * \brief API to use the bomp library
4 */
5
6/*
7 * Copyright (c)2014 ETH Zurich.
8 * All rights reserved.
9 *
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Universitaetsstrasse 6, CH-8092 Zurich. Attn: Systems Group.
13 */
14
15#include <bomp_internal.h>
16
17struct bomp_state *g_bomp_state;
18
19int bomp_switch_backend(bomp_backend_t backend)
20{
21    if (g_bomp_state && (g_bomp_state->backend_type == backend)) {
22        return SYS_ERR_OK;
23    }
24
25    struct bomp_state *prev = g_bomp_state;
26
27    switch (backend) {
28        case BOMP_BACKEND_BOMP:
29            g_bomp_state = bomp_get_backend_state_bomp();
30            break;
31        case BOMP_BACKEND_XOMP:
32            g_bomp_state = bomp_get_backend_state_xomp();
33            break;
34        case BOMP_BACKEND_LINUX:
35            g_bomp_state = bomp_get_backend_state_linux();
36            break;
37        default:
38            /* TODO: error code INVAID BACKEND */
39            return -1;
40            break;
41    }
42
43    if (g_bomp_state == NULL) {
44        g_bomp_state = prev;
45        return -1;
46    }
47
48    return SYS_ERR_OK;
49}
50
51#include <icv.h>
52void bomp_common_init(struct bomp_state *st)
53{
54    bomp_mutex_init(&st->critical_lock);
55    bomp_lock_init(&st->atomic_lock);
56    st->nested = 0;
57    st->behaviour_nested = 0;
58    st->behaviour_dynamic = 0;
59    st->bomp_threads = 1;
60    bomp_icv_init_from_env(&st->icv_task);
61    bomp_icv_dev_init_from_env(&st->icv_dev);
62}
63
64void bomp_set_tls(void *xdata)
65{
66    struct bomp_thread_local_data *local;
67    struct bomp_work *work_data = (struct bomp_work*)xdata;
68
69    assert(g_bomp_state);
70
71    /* Populate the Thread Local Storage data */
72    local = calloc(1, sizeof(struct bomp_thread_local_data));
73    assert(local != NULL);
74    local->thr = g_bomp_state->backend.get_thread();
75    local->work = work_data;
76    g_bomp_state->tld[work_data->thread_id] = local;
77    g_bomp_state->backend.set_tls(local);
78}
79
80
81