Une MAJ de sécurité est nécessaire sur notre version actuelle. Elle sera effectuée lundi 02/08 entre 12h30 et 13h. L'interruption de service devrait durer quelques minutes (probablement moins de 5 minutes).

runtime_control.c 5.98 KB
Newer Older
1 2
/**
 *
3 4
 * @copyright (c) 2009-2014 The University of Tennessee and The University
 *                          of Tennessee Research Foundation.
5
 *                          All rights reserved.
6
 * @copyright (c) 2012-2016 Inria. All rights reserved.
7
 * @copyright (c) 2012-2016 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
8 9 10 11 12
 *
 **/

/**
 *
13
 * @file runtime_control.c
14 15 16 17 18
 *
 *  MORSE auxiliary routines
 *  MORSE is a software package provided by Univ. of Tennessee,
 *  Univ. of California Berkeley and Univ. of Colorado Denver
 *
19
 * @version 0.9.0
20 21 22 23 24 25 26 27
 * @author Mathieu Faverge
 * @author Cedric Augonnet
 * @author Cedric Castagnede
 * @date 2010-11-15
 *
 **/
#include <stdio.h>
#include <stdlib.h>
28
#include "runtime/starpu/include/morse_starpu.h"
29

30 31 32 33 34 35 36 37 38
#if defined(CHAMELEON_SIMULATION)
# ifndef STARPU_SIMGRID
#  error "Starpu was not built with simgrid support (--enable-simgrid). Can not run Chameleon with simulation support."
# endif
#else
# ifdef STARPU_SIMGRID
#  warning "Starpu was built with simgrid support. Better build Chameleon with simulation support (-DCHAMELEON_SIMULATION=YES)."
# endif
#endif
39 40 41 42 43 44 45 46 47 48 49 50
/*******************************************************************************
 * Thread rank.
 **/
int RUNTIME_rank(MORSE_context_t *morse)
{
    (void)morse;
    return starpu_worker_get_id();
}

/*******************************************************************************
 *
 **/
51
int RUNTIME_init_scheduler( MORSE_context_t *morse, int ncpus, int ncudas, int nthreads_per_worker)
52 53 54 55
{
    starpu_conf_t *conf = (starpu_conf_t*)(morse->schedopt);
    int hres = -1;

56 57 58 59 60
    /* StarPU was already initialized by an external library */
    if (conf == NULL) {
        return 0;
    }

61
    conf->ncpus = ncpus;
62
    conf->ncuda = ncudas;
63 64
    conf->nopencl = 0;

65
#if !defined(CHAMELEON_SIMULATION)
66 67 68
    /* By default, enable calibration */
    if (!getenv("STARPU_CALIBRATE"))
        conf->calibrate = 1;
69
#endif
70

Mathieu Faverge's avatar
Mathieu Faverge committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84
    /* By default, use the dmdas strategy */
    if (!getenv("STARPU_SCHED")) {
        if (conf->ncuda > 0) {
            conf->sched_policy_name = "dmdas";
        }
        else {
            /**
             * Set scheduling to "ws"/"lws" if no cuda devices used because it
             * behaves better on homogneneous architectures. If the user wants
             * to use another scheduling strategy, he can set STARPU_SCHED
             * env. var. to whatever he wants
             */
#if (STARPU_MAJOR_VERSION > 1) || ((STARPU_MAJOR_VERSION == 1) && (STARPU_MINOR_VERSION >= 2))
            conf->sched_policy_name = "lws";
85
#else
Mathieu Faverge's avatar
Mathieu Faverge committed
86
            conf->sched_policy_name = "ws";
87
#endif
Mathieu Faverge's avatar
Mathieu Faverge committed
88 89
        }
    }
90

91
    if ((ncpus == -1)||(nthreads_per_worker == -1))
92 93 94 95 96 97 98 99 100 101
    {
        morse->parallel_enabled = MORSE_FALSE;

        hres = starpu_init( conf );
    }
    else {
        int worker;

        morse->parallel_enabled = MORSE_TRUE;

102
        for (worker = 0; worker < ncpus; worker++)
103 104
            conf->workers_bindid[worker] = (worker+1)*nthreads_per_worker - 1;

105
        for (worker = 0; worker < ncpus; worker++)
106 107 108 109 110 111
            conf->workers_bindid[worker + ncudas] = worker*nthreads_per_worker;

        conf->use_explicit_workers_bindid = 1;

        hres = starpu_init( conf );

112
        morse->nworkers = ncpus;
113 114 115
        morse->nthreads_per_worker = nthreads_per_worker;
    }

PRUVOST Florent's avatar
@all  
PRUVOST Florent committed
116
#ifdef USE_STARPU_MALLOC_ON_NODE_SET_DEFAULT_FLAGS
117 118 119 120 121
    starpu_malloc_on_node_set_default_flags(STARPU_MAIN_RAM, STARPU_MALLOC_PINNED | STARPU_MALLOC_COUNT
#ifdef STARPU_MALLOC_SIMULATION_FOLDED
            | STARPU_MALLOC_SIMULATION_FOLDED
#endif
            );
122 123
#endif

124
#if defined(CHAMELEON_USE_MPI)
125 126
    {
        int flag = 0;
127
#if !defined(CHAMELEON_SIMULATION)
128
        MPI_Initialized( &flag );
129
#endif
130
        starpu_mpi_init(NULL, NULL, !flag);
131 132
        RUNTIME_comm_rank(&(morse->my_mpi_rank));
        RUNTIME_comm_size(&(morse->mpi_comm_size));
133 134 135
    }
#endif

136
#if defined(CHAMELEON_USE_CUDA) && !defined(CHAMELEON_SIMULATION)
137 138 139 140 141 142 143 144 145 146 147 148
    starpu_cublas_init();
#endif

    return hres;
}

/*******************************************************************************
 *
 */
void RUNTIME_finalize_scheduler( MORSE_context_t *morse )
{
    (void)morse;
149 150 151

    /* StarPU was already initialized by an external library */
    if (morse->schedopt == NULL) {
152
        return;
153 154
    }

155
#if defined(CHAMELEON_USE_MPI)
156 157
    starpu_mpi_shutdown();
#endif
158
#if defined(CHAMELEON_USE_CUDA) && !defined(CHAMELEON_SIMULATION)
159 160 161 162 163 164 165 166 167 168 169 170 171 172
    starpu_cublas_shutdown();
#endif

    starpu_shutdown();
    return;
}

/*******************************************************************************
 *  Busy-waiting barrier
 **/
void RUNTIME_barrier( MORSE_context_t *morse )
{
    (void)morse;
    starpu_task_wait_for_all();
173
#if defined(CHAMELEON_USE_MPI)
174 175 176
    starpu_mpi_barrier(MPI_COMM_WORLD);
#endif
}
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197

/*******************************************************************************
 *  To suspend the processing of new tasks by workers
 **/
void RUNTIME_pause( MORSE_context_t *morse )
{
    (void)morse;
    starpu_pause();
    return;
}

/*******************************************************************************
 *  This is the symmetrical call to RUNTIME_pause,
 *  used to resume the workers polling for new tasks.
 **/
void RUNTIME_resume( MORSE_context_t *morse )
{
    (void)morse;
    starpu_resume();
    return;
}
198 199 200 201

/*******************************************************************************
 *  This returns the rank of this process
 **/
202
void RUNTIME_comm_rank( int *rank )
203 204
{
#if defined(CHAMELEON_USE_MPI)
THIBAULT Samuel's avatar
THIBAULT Samuel committed
205
#  if defined(HAVE_STARPU_MPI_COMM_RANK)
206 207 208 209 210 211 212 213 214 215 216 217 218
    starpu_mpi_comm_rank(MPI_COMM_WORLD, rank);
#  else
    MPI_Comm_rank(MPI_COMM_WORLD, rank);
#  endif
#else
    *rank = 0;
#endif
    return;
}

/*******************************************************************************
 *  This returns the size of the distributed computation
 **/
219
void RUNTIME_comm_size( int *size )
220 221
{
#if defined(CHAMELEON_USE_MPI)
THIBAULT Samuel's avatar
THIBAULT Samuel committed
222
#  if defined(HAVE_STARPU_MPI_COMM_RANK)
223 224 225 226 227 228 229 230 231
    starpu_mpi_comm_size(MPI_COMM_WORLD, size);
#  else
    MPI_Comm_size(MPI_COMM_WORLD, size);
#  endif
#else
    *size = 1;
#endif
    return;
}