runtime_control.c 4.31 KB
Newer Older
1 2
/**
 *
3 4
 * @copyright (c) 2009-2014 The University of Tennessee and The University
 *                          of Tennessee Research Foundation.
5 6
 *                          All rights reserved.
 * @copyright (c) 2012-2014 Inria. All rights reserved.
7
 * @copyright (c) 2012-2014 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 39 40 41

/*******************************************************************************
 * Thread rank.
 **/
int RUNTIME_rank(MORSE_context_t *morse)
{
    (void)morse;
    return starpu_worker_get_id();
}

/*******************************************************************************
 *
 **/
42
int RUNTIME_init_scheduler( MORSE_context_t *morse, int ncpus, int ncudas, int nthreads_per_worker)
43 44 45 46
{
    starpu_conf_t *conf = (starpu_conf_t*)(morse->schedopt);
    int hres = -1;

47
    conf->ncpus = ncpus;
48
    conf->ncuda = ncudas;
49 50 51 52 53
    conf->nopencl = 0;

    /* By default, enable calibration */
    if (!getenv("STARPU_CALIBRATE"))
        conf->calibrate = 1;
54

Mathieu Faverge's avatar
Mathieu Faverge committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68
    /* 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";
69
#else
Mathieu Faverge's avatar
Mathieu Faverge committed
70
            conf->sched_policy_name = "ws";
71
#endif
Mathieu Faverge's avatar
Mathieu Faverge committed
72 73
        }
    }
74

75
    if ((ncpus == -1)||(nthreads_per_worker == -1))
76 77 78 79 80 81 82 83 84 85
    {
        morse->parallel_enabled = MORSE_FALSE;

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

        morse->parallel_enabled = MORSE_TRUE;

86
        for (worker = 0; worker < ncpus; worker++)
87 88
            conf->workers_bindid[worker] = (worker+1)*nthreads_per_worker - 1;

89
        for (worker = 0; worker < ncpus; worker++)
90 91 92 93 94 95
            conf->workers_bindid[worker + ncudas] = worker*nthreads_per_worker;

        conf->use_explicit_workers_bindid = 1;

        hres = starpu_init( conf );

96
        morse->nworkers = ncpus;
97 98 99
        morse->nthreads_per_worker = nthreads_per_worker;
    }

100
#if defined(CHAMELEON_USE_MPI)
101 102 103 104 105 106 107 108 109 110 111 112 113
    {
        int flag = 0;
        MPI_Initialized( &flag );
        starpu_mpi_init(NULL, NULL, !flag);
        MPI_Comm_rank(MPI_COMM_WORLD, &(morse->my_mpi_rank));
        MPI_Comm_size(MPI_COMM_WORLD, &(morse->mpi_comm_size));
    }
#endif

#if defined(HAVE_STARPU_FXT_PROFILING)
    starpu_fxt_stop_profiling();
#endif

114
#if defined(CHAMELEON_USE_CUDA)
115 116 117 118 119 120 121 122 123 124 125 126
    starpu_cublas_init();
#endif

    return hres;
}

/*******************************************************************************
 *
 */
void RUNTIME_finalize_scheduler( MORSE_context_t *morse )
{
    (void)morse;
127
#if defined(CHAMELEON_USE_MPI)
128 129
    starpu_mpi_shutdown();
#endif
130
#if defined(CHAMELEON_USE_CUDA)
131 132 133 134 135 136 137 138 139 140 141 142 143 144
    starpu_cublas_shutdown();
#endif

    starpu_shutdown();
    return;
}

/*******************************************************************************
 *  Busy-waiting barrier
 **/
void RUNTIME_barrier( MORSE_context_t *morse )
{
    (void)morse;
    starpu_task_wait_for_all();
145
#if defined(CHAMELEON_USE_MPI)
146 147 148
    starpu_mpi_barrier(MPI_COMM_WORLD);
#endif
}
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169

/*******************************************************************************
 *  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;
}