runtime_control.c 3.7 KB
Newer Older
1
/**
2 3
 *
 * @file runtime_control.c
4
 *
5
 * @copyright 2012-2017 The University of Tennessee and The University of
Mathieu Faverge's avatar
Mathieu Faverge committed
6
 *                      Tennessee Research Foundation. All rights reserved.
7 8 9
 * @copyright 2012-2017 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
 *                      Univ. Bordeaux. All rights reserved.
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
10 11 12 13
 ***
 *
 * @brief Chameleon PaRSEC control routines
 *
14 15 16 17
 * @version 1.0.0
 * @author Reazul Hoque
 * @author Mathieu Faverge
 * @date 2017-01-12
18 19 20 21
 *
 **/
#include <stdio.h>
#include <stdlib.h>
22
#include "chameleon_parsec.h"
23

Mathieu Faverge's avatar
Mathieu Faverge committed
24 25 26 27
#if defined(CHAMELEON_USE_MPI)
#include <mpi.h>
#endif

28 29 30
/*******************************************************************************
 * Initialize MORSE
 **/
31 32 33 34
int RUNTIME_init( MORSE_context_t *morse,
                  int ncpus,
                  int ncudas,
                  int nthreads_per_worker )
35 36 37 38 39
{
    int hres = -1, default_ncores = -1;
    int *argc = (int *)malloc(sizeof(int));
    *argc = 0;

Mathieu Faverge's avatar
Mathieu Faverge committed
40
    /* Initializing parsec context */
41 42
    if( 0 < ncpus ) {
        default_ncores = ncpus;
43 44
    }
    morse->parallel_enabled = MORSE_TRUE;
Mathieu Faverge's avatar
Mathieu Faverge committed
45 46
    morse->schedopt = (void *)parsec_init(default_ncores, argc, NULL);

47
    if(NULL != morse->schedopt) {
48
        morse->nworkers = ncpus;
49 50 51 52 53
        morse->nthreads_per_worker = nthreads_per_worker;
        hres = 0;
    }

    free(argc);
54 55

    (void)ncudas;
56 57 58 59 60 61
    return hres;
}

/*******************************************************************************
 * Finalize MORSE
 */
62
void RUNTIME_finalize( MORSE_context_t *morse )
63
{
Mathieu Faverge's avatar
Mathieu Faverge committed
64 65
    parsec_context_t *parsec = (parsec_context_t*)morse->schedopt;
    parsec_fini(&parsec);
66 67 68 69
    return;
}

/*******************************************************************************
70
 *  To suspend the processing of new tasks by workers
71
 **/
72
void RUNTIME_pause( MORSE_context_t *morse )
73
{
74
    (void)morse;
75 76 77
    return;
}

78
/*******************************************************************************
79 80
 *  This is the symmetrical call to RUNTIME_pause,
 *  used to resume the workers polling for new tasks.
81
 **/
82
void RUNTIME_resume( MORSE_context_t *morse )
83
{
84
    (void)morse;
85 86
    return;
}
87 88 89 90 91

/*******************************************************************************
 * Barrier MORSE.
 **/
void RUNTIME_barrier( MORSE_context_t *morse )
92
{
93
    parsec_context_t *parsec = (parsec_context_t*)(morse->schedopt);
94 95
    // This will be a problem with the fake tasks inserted to detect end of DTD algorithms
    parsec_context_wait( parsec );
96 97 98
    return;
}

99
/*******************************************************************************
100
 *  Display a progress information when executing the tasks
101
 **/
102
void RUNTIME_progress( MORSE_context_t *morse )
103 104 105 106 107 108
{
    (void)morse;
    return;
}

/*******************************************************************************
109
 * Thread rank.
110
 **/
111
int RUNTIME_thread_rank( MORSE_context_t *morse )
112
{
113
    (void)morse;
114
    return 0;
115 116 117
}

/*******************************************************************************
118
 * Thread rank.
119
 **/
120
int RUNTIME_thread_size( MORSE_context_t *morse )
121
{
122 123
    // TODO: fixme
    //return vpmap_get_nb_total_threads();
124
    (void)morse;
125
    return 1;
126 127 128
}

/*******************************************************************************
129
 *  This returns the rank of this process
130
 **/
131
int RUNTIME_comm_rank( MORSE_context_t *morse )
132
{
133
    int rank = 0;
134
#if defined(CHAMELEON_USE_MPI)
135
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
136
#endif
137 138 139

    (void)morse;
    return rank;
140
}
Mathieu Faverge's avatar
Mathieu Faverge committed
141 142

/*******************************************************************************
143
 *  This returns the size of the distributed computation
Mathieu Faverge's avatar
Mathieu Faverge committed
144
 **/
145
int RUNTIME_comm_size( MORSE_context_t *morse )
Mathieu Faverge's avatar
Mathieu Faverge committed
146
{
147 148 149 150 151 152 153
    int size = 0;
#if defined(CHAMELEON_USE_MPI)
    MPI_Comm_size(MPI_COMM_WORLD, &size);
#endif

    (void)morse;
    return size;
Mathieu Faverge's avatar
Mathieu Faverge committed
154
}