pzlansy.c 11.7 KB
Newer Older
1
/**
2 3
 *
 * @file pzlansy.c
4
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
5 6
 * @copyright 2009-2014 The University of Tennessee and The University of
 *                      Tennessee Research Foundation. All rights reserved.
Mathieu Faverge's avatar
Mathieu Faverge committed
7
 * @copyright 2012-2018 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8
 *                      Univ. Bordeaux. All rights reserved.
9
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
10
 ***
11
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
12
 * @brief Chameleon zlansy parallel algorithm
13
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
14
 * @version 1.0.0
15
 * @comment This file has been automatically generated
Mathieu Faverge's avatar
Mathieu Faverge committed
16
 *          from Plasma 2.6.0 for CHAMELEON 1.0.0
17 18 19 20 21
 * @author Emmanuel Agullo
 * @author Mathieu Faverge
 * @date 2010-11-15
 * @precisions normal z -> c d s
 *
22
 */
23
//ALLOC_WS :  A->mb
Mathieu Faverge's avatar
Mathieu Faverge committed
24 25
//WS_ADD :  A->mb

26 27
#include <stdlib.h>
#include <math.h>
28
#include "control/common.h"
29

Mathieu Faverge's avatar
Mathieu Faverge committed
30 31 32
#define A(m, n)    A,    (m), (n)
#define Wcol(m, n) Wcol, (m), (n)
#define Welt(m, n) Welt, (m), (n)
33

Mathieu Faverge's avatar
Mathieu Faverge committed
34 35 36 37 38
static inline void
chameleon_pzlansy_inf( cham_uplo_t uplo, CHAM_desc_t *A,
                       CHAM_desc_t *Wcol, CHAM_desc_t *Welt,
                       RUNTIME_option_t *options)
{
39
    int m, n;
Mathieu Faverge's avatar
Mathieu Faverge committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53
    int MT = A->mt;
    int NT = A->nt;
    int M  = A->m;
    int N  = A->n;
    int P  = Welt->p;
    int Q  = Welt->q;

    /**
     * Step 1:
     *  For j in [1,Q], Wcol(m, j) = reduce( A(m, j+k*Q) )
     */
    for(m = 0; m < MT; m++) {
        int nmin = ( uplo == ChamUpper ) ? m                      : 0;
        int nmax = ( uplo == ChamLower ) ? chameleon_min(m+1, NT) : NT;
54

Mathieu Faverge's avatar
Mathieu Faverge committed
55 56
        int tempmm = ( m == (MT-1) ) ? M - m * A->mb : A->mb;
        int ldam = BLKLDD( A, m );
57

Mathieu Faverge's avatar
Mathieu Faverge committed
58 59
        for(n = nmin; n < nmax; n++) {
            int tempnn = ( n == (NT-1) ) ? N - n * A->nb : A->nb;
60

Mathieu Faverge's avatar
Mathieu Faverge committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
            if ( n == m ) {
                INSERT_TASK_dzasum(
                    options,
                    ChamRowwise, uplo, tempmm, tempnn,
                    A(m, n), ldam, Wcol(m, n) );
            }
            else {
                INSERT_TASK_dzasum(
                    options,
                    ChamRowwise, ChamUpperLower, tempmm, tempnn,
                    A(m, n), ldam, Wcol(m, n) );

                INSERT_TASK_dzasum(
                    options,
                    ChamColumnwise, ChamUpperLower, tempmm, tempnn,
                    A(m, n), ldam, Wcol(n, m) );
            }
        }
    }
80

Mathieu Faverge's avatar
Mathieu Faverge committed
81 82
    for(m = 0; m < MT; m++) {
        int tempmm = ( m == (MT-1) ) ? M - m * A->mb : A->mb;
83

Mathieu Faverge's avatar
Mathieu Faverge committed
84 85 86 87 88 89 90
        for(n = Q; n < NT; n++) {
            INSERT_TASK_dgeadd(
                options,
                ChamNoTrans, tempmm, 1, A->nb,
                1.0, Wcol(m, n  ), tempmm,
                1.0, Wcol(m, n%Q), tempmm );
        }
91

Mathieu Faverge's avatar
Mathieu Faverge committed
92 93 94 95 96 97 98 99 100 101
        /**
         * Step 2:
         *  For each j, W(m, j) = reduce( Wcol(m, 0..Q-1) )
         */
        for(n = 1; n < Q; n++) {
            INSERT_TASK_dgeadd(
                options,
                ChamNoTrans, tempmm, 1, A->mb,
                1.0, Wcol(m, n), tempmm,
                1.0, Wcol(m, 0), tempmm );
102 103
        }

Mathieu Faverge's avatar
Mathieu Faverge committed
104 105 106 107 108
        INSERT_TASK_dlange(
            options,
            ChamMaxNorm, tempmm, 1, A->nb,
            Wcol(m, 0), 1, Welt(m, 0));
    }
109

Mathieu Faverge's avatar
Mathieu Faverge committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
    /**
     * Step 3:
     *  For m in 0..P-1, Welt(m, n) = max( Wcol(m..mt[P], n ) )
     */
    for(m = P; m < MT; m++) {
        INSERT_TASK_dlange_max(
            options,
            Welt(m, 0), Welt(m%P, 0) );
    }

    /**
     * Step 4:
     *  For each i, Welt(i, n) = max( Welt(0..P-1, n) )
     */
    for(m = 1; m < P; m++) {
        INSERT_TASK_dlange_max(
            options,
            Welt(m, 0), Welt(0, 0) );
    }
}

static inline void
chameleon_pzlansy_max( cham_trans_t trans, cham_uplo_t uplo, CHAM_desc_t *A,
                       CHAM_desc_t *Welt, RUNTIME_option_t *options)
{
    int m, n;
    int MT = A->mt;
    int NT = A->nt;
    int M  = A->m;
    int N  = A->n;
    int P  = Welt->p;
    int Q  = Welt->q;

    /**
     * Step 1:
     *  For j in [1,Q], Welt(m, j) = reduce( A(m, j+k*Q) )
     */
    for(m = 0; m < MT; m++) {
        int nmin = (uplo == ChamUpper ) ? m                      : 0;
        int nmax = (uplo == ChamLower ) ? chameleon_min(m+1, NT) : NT;

        int tempmm = ( m == (MT-1) ) ? M - m * A->mb : A->mb;
        int ldam = BLKLDD( A, m );

        for(n = nmin; n < nmax; n++) {
            int tempnn = ( n == (NT-1) ) ? N - n * A->nb : A->nb;

            if ( n == m ) {
                if ( trans == ChamConjTrans) {
                    INSERT_TASK_zlanhe(
                        options,
                        ChamMaxNorm, uplo, tempmm, A->nb,
                        A(m, n), ldam, Welt(m, n));
                }
                else {
                    INSERT_TASK_zlansy(
                        options,
                        ChamMaxNorm, uplo, tempmm, A->nb,
                        A(m, n), ldam, Welt(m, n));
169 170 171
                }
            }
            else {
Mathieu Faverge's avatar
Mathieu Faverge committed
172 173 174 175
                INSERT_TASK_zlange(
                    options,
                    ChamMaxNorm, tempmm, tempnn, A->nb,
                    A(m, n), ldam, Welt(m, n));
176 177
            }

Mathieu Faverge's avatar
Mathieu Faverge committed
178
            if ( n >= Q ) {
Mathieu Faverge's avatar
Mathieu Faverge committed
179
                INSERT_TASK_dlange_max(
Mathieu Faverge's avatar
Mathieu Faverge committed
180 181
                    options,
                    Welt(m, n), Welt(m, n%Q) );
182 183 184
            }
        }

Mathieu Faverge's avatar
Mathieu Faverge committed
185 186 187 188 189 190 191 192
        /**
         * Step 2:
         *  For each j, W(m, j) = reduce( Welt(m, 0..Q-1) )
         */
        for(n = 1; n < Q; n++) {
            INSERT_TASK_dlange_max(
                options,
                Welt(m, n), Welt(m, 0) );
193
        }
Mathieu Faverge's avatar
Mathieu Faverge committed
194 195 196 197 198
    }

    /**
     * Step 3:
     *  For m in 0..P-1, Welt(m, n) = max( Welt(m..mt[P], n ) )
199
     */
Mathieu Faverge's avatar
Mathieu Faverge committed
200 201 202 203 204
    for(m = P; m < MT; m++) {
        INSERT_TASK_dlange_max(
            options,
            Welt(m, 0), Welt(m%P, 0) );
    }
205

Mathieu Faverge's avatar
Mathieu Faverge committed
206 207 208 209 210 211 212 213 214 215
    /**
     * Step 4:
     *  For each i, Welt(i, n) = max( Welt(0..P-1, n) )
     */
    for(m = 1; m < P; m++) {
        INSERT_TASK_dlange_max(
            options,
            Welt(m, 0), Welt(0, 0) );
    }
}
216

Mathieu Faverge's avatar
Mathieu Faverge committed
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
static inline void
chameleon_pzlansy_frb( cham_trans_t trans, cham_uplo_t uplo,
                       CHAM_desc_t *A, CHAM_desc_t *Welt,
                       RUNTIME_option_t *options)
{
    int m, n;
    int MT = A->mt;
    int NT = A->nt;
    int M  = A->m;
    int N  = A->n;
    int P  = Welt->p;
    int Q  = Welt->q;

    /**
     * Step 1:
     *  For j in [1,Q], Welt(m, j) = reduce( A(m, j+k*Q) )
     */
    for(m = 0; m < MT; m++) {
        int nmin = (uplo == ChamUpper ) ? m                      : 0;
        int nmax = (uplo == ChamLower ) ? chameleon_min(m+1, NT) : NT;
237

Mathieu Faverge's avatar
Mathieu Faverge committed
238 239
        int tempmm = ( m == (MT-1) ) ? M - m * A->mb : A->mb;
        int ldam = BLKLDD( A, m );
240

Mathieu Faverge's avatar
Mathieu Faverge committed
241 242 243 244 245 246 247 248 249 250 251 252 253
        for(n = nmin; n < nmax; n++) {
            int tempnn = ( n == (NT-1) ) ? N - n * A->nb : A->nb;

            if ( n == m ) {
                if ( trans == ChamConjTrans) {
                    INSERT_TASK_zhessq(
                        options, uplo, tempmm,
                        A(m, n), ldam, Welt(m, n) );
                }
                else {
                    INSERT_TASK_zsyssq(
                        options, uplo, tempmm,
                        A(m, n), ldam, Welt(m, n) );
254 255 256
                }
            }
            else {
Mathieu Faverge's avatar
Mathieu Faverge committed
257 258 259 260 261 262
                INSERT_TASK_zgessq(
                    options, tempmm, tempnn,
                    A(m, n), ldam, Welt(m, n) );
                INSERT_TASK_zgessq(
                    options, tempmm, tempnn,
                    A(m, n), ldam, Welt(n, m) );
263 264
            }
        }
Mathieu Faverge's avatar
Mathieu Faverge committed
265
    }
266

Mathieu Faverge's avatar
Mathieu Faverge committed
267 268 269 270 271
    for(m = 0; m < MT; m++) {
        for(n = Q; n < NT; n++) {
            INSERT_TASK_dplssq(
                options, Welt(m, n), Welt(m, n%Q) );
        }
272

Mathieu Faverge's avatar
Mathieu Faverge committed
273 274 275 276 277 278 279
        /**
         * Step 2:
         *  For each j, W(m, j) = reduce( Welt(m, 0..Q-1) )
         */
        for(n = 1; n < Q; n++) {
            INSERT_TASK_dplssq(
                options, Welt(m, n), Welt(m, 0) );
280
        }
Mathieu Faverge's avatar
Mathieu Faverge committed
281
    }
282

Mathieu Faverge's avatar
Mathieu Faverge committed
283 284 285 286 287 288 289 290
    /**
     * Step 3:
     *  For m in 0..P-1, Welt(m, n) = max( Welt(m..mt[P], n ) )
     */
    for(m = P; m < MT; m++) {
        INSERT_TASK_dplssq(
            options, Welt(m, 0), Welt(m%P, 0) );
    }
291

Mathieu Faverge's avatar
Mathieu Faverge committed
292 293 294
    /**
     * Step 4:
     *  For each i, Welt(i, n) = max( Welt(0..P-1, n) )
295
     */
Mathieu Faverge's avatar
Mathieu Faverge committed
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
    for(m = 1; m < P; m++) {
        INSERT_TASK_dplssq(
            options, Welt(m, 0), Welt(0, 0) );
    }

    INSERT_TASK_dplssq2(
        options, Welt(0, 0) );
}

/**
 *
 */
void chameleon_pzlansy_generic( cham_normtype_t norm, cham_uplo_t uplo, cham_trans_t trans,
                                CHAM_desc_t *A, double *result,
                                RUNTIME_sequence_t *sequence, RUNTIME_request_t *request )
{
    CHAM_context_t *chamctxt;
    RUNTIME_option_t options;
    CHAM_desc_t *Wcol = NULL;
    CHAM_desc_t *Welt = NULL;
    double alpha = 0.0;
    double beta  = 0.0;

    int workn, workmt, worknt;
    int m, n;

    chamctxt = chameleon_context_self();
    if (sequence->status != CHAMELEON_SUCCESS)
        return;
    RUNTIME_options_init(&options, chamctxt, sequence, request);

    *result = 0.0;

    workmt = chameleon_max( A->mt, A->p );
    worknt = chameleon_max( A->nt, A->q );
    workn  = chameleon_max( A->n,  A->q );

    switch ( norm ) {
    case ChamOneNorm:
    case ChamInfNorm:
336 337
        RUNTIME_options_ws_alloc( &options, 1, 0 );

Mathieu Faverge's avatar
Mathieu Faverge committed
338 339
        CHAMELEON_Desc_Create( &Wcol, NULL, ChamRealDouble, 1, A->nb, A->nb,
                               workmt, worknt * A->nb, 0, 0, workmt, worknt * A->nb, A->p, A->q );
340

Mathieu Faverge's avatar
Mathieu Faverge committed
341 342
        CHAMELEON_Desc_Create( &Welt, NULL, ChamRealDouble, 1, 1, 1,
                               A->p, worknt, 0, 0, A->p, worknt, A->p, A->q );
343

Mathieu Faverge's avatar
Mathieu Faverge committed
344
        break;
345

Mathieu Faverge's avatar
Mathieu Faverge committed
346 347 348 349 350
        /*
         *  ChamFrobeniusNorm
         */
    case ChamFrobeniusNorm:
        RUNTIME_options_ws_alloc( &options, 1, 0 );
351

Mathieu Faverge's avatar
Mathieu Faverge committed
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
        alpha = 1.;
        CHAMELEON_Desc_Create( &Welt, NULL, ChamRealDouble, 2, 1, 2,
                               workmt*2, workn, 0, 0, workmt*2, workn, A->p, A->q );
        break;

        /*
         *  ChamMaxNorm
         */
    case ChamMaxNorm:
    default:
        RUNTIME_options_ws_alloc( &options, 1, 0 );

        CHAMELEON_Desc_Create( &Welt, NULL, ChamRealDouble, 1, 1, 1,
                               workmt, workn, 0, 0, workmt, workn, A->p, A->q );
    }

    /* Initialize workspaces */
    if ( (norm == ChamInfNorm) ||
         (norm == ChamOneNorm) )
    {
        /* Initialize Wcol tile */
        for(m = 0; m < Wcol->mt; m++) {
            for(n = 0; n < Wcol->nt; n++) {
                INSERT_TASK_dlaset(
                    &options,
                    ChamUpperLower, Wcol->mb, Wcol->nb,
                    alpha, beta,
                    Wcol(m,n), Wcol->mb );
380 381
            }
        }
Mathieu Faverge's avatar
Mathieu Faverge committed
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
    }
    for(m = 0; m < Welt->mt; m++) {
        for(n = 0; n < Welt->nt; n++) {
            INSERT_TASK_dlaset(
                &options,
                ChamUpperLower, Welt->mb, Welt->nb,
                alpha, beta,
                Welt(m,n), Welt->mb );
        }
    }

    switch ( norm ) {
    case ChamOneNorm:
    case ChamInfNorm:
        chameleon_pzlansy_inf( uplo, A, Wcol, Welt, &options );
        CHAMELEON_Desc_Flush( Wcol, sequence );
        break;

    case ChamFrobeniusNorm:
        chameleon_pzlansy_frb( trans, uplo, A, Welt, &options );
        break;

    case ChamMaxNorm:
    default:
        chameleon_pzlansy_max( trans, uplo, A, Welt, &options );
    }
408

Mathieu Faverge's avatar
Mathieu Faverge committed
409 410 411 412 413 414
    /**
     * Broadcast the result
     */
    for(m = 0; m < A->p; m++) {
        for(n = 0; n < A->q; n++) {
            if ( (m != 0) && (n != 0) ) {
Mathieu Faverge's avatar
Mathieu Faverge committed
415
                INSERT_TASK_dlacpy(
416
                    &options,
Mathieu Faverge's avatar
Mathieu Faverge committed
417
                    ChamUpperLower, 1, 1, 1,
Mathieu Faverge's avatar
Mathieu Faverge committed
418
                    Welt(0,0), 1, Welt(m, n), 1);
419 420 421
            }
        }
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
422

Mathieu Faverge's avatar
Mathieu Faverge committed
423 424 425 426 427 428 429 430 431
    CHAMELEON_Desc_Flush( Welt, sequence );
    RUNTIME_sequence_wait(chamctxt, sequence);

    *result = *(double *)Welt->get_blkaddr(Welt, A->myrank / A->q, A->myrank % A->q );

    if ( Wcol != NULL ) {
        CHAMELEON_Desc_Destroy( &Wcol );
    }
    CHAMELEON_Desc_Destroy( &Welt );
Mathieu Faverge's avatar
Mathieu Faverge committed
432

433
    RUNTIME_options_ws_free(&options);
Mathieu Faverge's avatar
Mathieu Faverge committed
434
    RUNTIME_options_finalize(&options, chamctxt);
435
}