pzlansy.c 12.2 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
 *
10
 ***
11
 *
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
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

30 31
#define A( m, n )        A,     (m), (n)
#define W( desc, m, n ) (desc), (m), (n)
32

Mathieu Faverge's avatar
Mathieu Faverge committed
33 34 35 36 37
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)
{
38
    int m, n;
Mathieu Faverge's avatar
Mathieu Faverge committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52
    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;
53

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

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

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

                INSERT_TASK_dzasum(
                    options,
                    ChamColumnwise, ChamUpperLower, tempmm, tempnn,
75
                    A(m, n), ldam, W( Wcol, n, m) );
Mathieu Faverge's avatar
Mathieu Faverge committed
76 77 78
            }
        }
    }
79

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

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

Mathieu Faverge's avatar
Mathieu Faverge committed
91 92 93 94 95 96 97 98
        /**
         * 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,
99 100
                1.0, W( Wcol, m, n), tempmm,
                1.0, W( Wcol, m, 0), tempmm );
101 102
        }

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

Mathieu Faverge's avatar
Mathieu Faverge committed
109 110
    /**
     * Step 3:
111
     *  For m in 0..P-1, W( Welt, m, n) = max( Wcol(m..mt[P], n ) )
Mathieu Faverge's avatar
Mathieu Faverge committed
112 113 114 115
     */
    for(m = P; m < MT; m++) {
        INSERT_TASK_dlange_max(
            options,
116
            W( Welt, m, 0), W( Welt, m%P, 0) );
Mathieu Faverge's avatar
Mathieu Faverge committed
117 118 119 120
    }

    /**
     * Step 4:
121
     *  For each i, W( Welt, i, n) = max( W( Welt, 0..P-1, n) )
Mathieu Faverge's avatar
Mathieu Faverge committed
122 123 124 125
     */
    for(m = 1; m < P; m++) {
        INSERT_TASK_dlange_max(
            options,
126
            W( Welt, m, 0), W( Welt, 0, 0) );
Mathieu Faverge's avatar
Mathieu Faverge committed
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
    }
}

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,
161
                        A(m, n), ldam, W( Welt, m, n));
Mathieu Faverge's avatar
Mathieu Faverge committed
162 163 164 165 166
                }
                else {
                    INSERT_TASK_zlansy(
                        options,
                        ChamMaxNorm, uplo, tempmm, A->nb,
167
                        A(m, n), ldam, W( Welt, m, n));
168 169 170
                }
            }
            else {
Mathieu Faverge's avatar
Mathieu Faverge committed
171 172 173
                INSERT_TASK_zlange(
                    options,
                    ChamMaxNorm, tempmm, tempnn, A->nb,
174
                    A(m, n), ldam, W( Welt, m, n));
175 176
            }

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

Mathieu Faverge's avatar
Mathieu Faverge committed
184 185 186 187 188 189 190
        /**
         * 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,
191
                W( Welt, m, n), W( Welt, m, 0) );
192
        }
Mathieu Faverge's avatar
Mathieu Faverge committed
193 194 195 196 197
    }

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

Mathieu Faverge's avatar
Mathieu Faverge committed
205 206 207 208 209 210 211
    /**
     * 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,
212
            W( Welt, m, 0), W( Welt, 0, 0) );
Mathieu Faverge's avatar
Mathieu Faverge committed
213 214
    }
}
215

Mathieu Faverge's avatar
Mathieu Faverge committed
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
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;
236

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

Mathieu Faverge's avatar
Mathieu Faverge committed
240 241 242 243 244 245 246
        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,
247
                        A(m, n), ldam, W( Welt, m, n) );
Mathieu Faverge's avatar
Mathieu Faverge committed
248 249 250 251
                }
                else {
                    INSERT_TASK_zsyssq(
                        options, uplo, tempmm,
252
                        A(m, n), ldam, W( Welt, m, n) );
253 254 255
                }
            }
            else {
Mathieu Faverge's avatar
Mathieu Faverge committed
256 257
                INSERT_TASK_zgessq(
                    options, tempmm, tempnn,
258
                    A(m, n), ldam, W( Welt, m, n) );
Mathieu Faverge's avatar
Mathieu Faverge committed
259 260
                INSERT_TASK_zgessq(
                    options, tempmm, tempnn,
261
                    A(m, n), ldam, W( Welt, n, m) );
262 263
            }
        }
Mathieu Faverge's avatar
Mathieu Faverge committed
264
    }
265

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

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

Mathieu Faverge's avatar
Mathieu Faverge committed
282 283 284 285 286 287
    /**
     * 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(
288
            options, W( Welt, m, 0), W( Welt, m%P, 0) );
Mathieu Faverge's avatar
Mathieu Faverge committed
289
    }
290

Mathieu Faverge's avatar
Mathieu Faverge committed
291 292 293
    /**
     * Step 4:
     *  For each i, Welt(i, n) = max( Welt(0..P-1, n) )
294
     */
Mathieu Faverge's avatar
Mathieu Faverge committed
295 296
    for(m = 1; m < P; m++) {
        INSERT_TASK_dplssq(
297
            options, W( Welt, m, 0), W( Welt, 0, 0) );
Mathieu Faverge's avatar
Mathieu Faverge committed
298 299 300
    }

    INSERT_TASK_dplssq2(
301
        options, W( Welt, 0, 0) );
Mathieu Faverge's avatar
Mathieu Faverge committed
302 303 304 305 306 307 308 309 310 311 312
}

/**
 *
 */
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;
313 314
    CHAM_desc_t Wcol;
    CHAM_desc_t Welt;
Mathieu Faverge's avatar
Mathieu Faverge committed
315 316 317
    double alpha = 0.0;
    double beta  = 0.0;

Mathieu Faverge's avatar
Mathieu Faverge committed
318
    int workmt, worknt;
319
    int m, n, wcol_init = 0;
Mathieu Faverge's avatar
Mathieu Faverge committed
320 321

    chamctxt = chameleon_context_self();
Mathieu Faverge's avatar
Mathieu Faverge committed
322
    if ( sequence->status != CHAMELEON_SUCCESS ) {
Mathieu Faverge's avatar
Mathieu Faverge committed
323
        return;
Mathieu Faverge's avatar
Mathieu Faverge committed
324
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
325 326 327 328 329 330 331 332 333 334
    RUNTIME_options_init(&options, chamctxt, sequence, request);

    *result = 0.0;

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

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

337 338 339 340
        chameleon_desc_init( &Wcol, CHAMELEON_MAT_ALLOC_GLOBAL, ChamRealDouble, A->mb, 1, A->mb,
                             workmt * A->mb, worknt, 0, 0, workmt * A->mb, worknt, A->p, A->q,
                             NULL, NULL, NULL );
        wcol_init = 1;
341

342 343 344
        chameleon_desc_init( &Welt, CHAMELEON_MAT_ALLOC_GLOBAL, ChamRealDouble, 1, 1, 1,
                             workmt, A->q, 0, 0, workmt, A->q, A->p, A->q,
                             NULL, NULL, NULL );
Mathieu Faverge's avatar
Mathieu Faverge committed
345
        break;
346

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

Mathieu Faverge's avatar
Mathieu Faverge committed
353
        alpha = 1.;
354
        chameleon_desc_init( &Welt, CHAMELEON_MAT_ALLOC_GLOBAL, ChamRealDouble, 2, 1, 2,
355
                             workmt*2, worknt, 0, 0, workmt*2, worknt, A->p, A->q,
356
                             NULL, NULL, NULL );
Mathieu Faverge's avatar
Mathieu Faverge committed
357 358 359 360 361 362 363 364 365
        break;

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

366
        chameleon_desc_init( &Welt, CHAMELEON_MAT_ALLOC_GLOBAL, ChamRealDouble, 1, 1, 1,
367
                             workmt, worknt, 0, 0, workmt, worknt, A->p, A->q,
368
                             NULL, NULL, NULL );
Mathieu Faverge's avatar
Mathieu Faverge committed
369 370 371 372 373 374 375
    }

    /* Initialize workspaces */
    if ( (norm == ChamInfNorm) ||
         (norm == ChamOneNorm) )
    {
        /* Initialize Wcol tile */
376 377
        for(m = 0; m < Wcol.mt; m++) {
            for(n = 0; n < Wcol.nt; n++) {
Mathieu Faverge's avatar
Mathieu Faverge committed
378 379
                INSERT_TASK_dlaset(
                    &options,
380
                    ChamUpperLower, Wcol.mb, Wcol.nb,
Mathieu Faverge's avatar
Mathieu Faverge committed
381
                    alpha, beta,
382
                    W( &Wcol, m, n ), Wcol.mb );
383 384
            }
        }
Mathieu Faverge's avatar
Mathieu Faverge committed
385
    }
386 387
    for(m = 0; m < Welt.mt; m++) {
        for(n = 0; n < Welt.nt; n++) {
Mathieu Faverge's avatar
Mathieu Faverge committed
388 389
            INSERT_TASK_dlaset(
                &options,
390
                ChamUpperLower, Welt.mb, Welt.nb,
Mathieu Faverge's avatar
Mathieu Faverge committed
391
                alpha, beta,
392
                W( &Welt, m, n ), Welt.mb );
Mathieu Faverge's avatar
Mathieu Faverge committed
393 394 395 396 397 398
        }
    }

    switch ( norm ) {
    case ChamOneNorm:
    case ChamInfNorm:
399 400
        chameleon_pzlansy_inf( uplo, A, &Wcol, &Welt, &options );
        CHAMELEON_Desc_Flush( &Wcol, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
401 402 403
        break;

    case ChamFrobeniusNorm:
404
        chameleon_pzlansy_frb( trans, uplo, A, &Welt, &options );
Mathieu Faverge's avatar
Mathieu Faverge committed
405 406 407 408
        break;

    case ChamMaxNorm:
    default:
409
        chameleon_pzlansy_max( trans, uplo, A, &Welt, &options );
Mathieu Faverge's avatar
Mathieu Faverge committed
410
    }
411

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

Mathieu Faverge's avatar
Mathieu Faverge committed
426 427 428
    if ( wcol_init ) {
        CHAMELEON_Desc_Flush( &Wcol, sequence );
    }
429
    CHAMELEON_Desc_Flush( &Welt, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
430
    CHAMELEON_Desc_Flush( A, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
431 432
    RUNTIME_sequence_wait(chamctxt, sequence);

433
    *result = *(double *)Welt.get_blkaddr( &Welt, A->myrank / A->q, A->myrank % A->q );
Mathieu Faverge's avatar
Mathieu Faverge committed
434

435 436
    if ( wcol_init ) {
        chameleon_desc_destroy( &Wcol );
Mathieu Faverge's avatar
Mathieu Faverge committed
437
    }
438
    chameleon_desc_destroy( &Welt );
Mathieu Faverge's avatar
Mathieu Faverge committed
439

440
    RUNTIME_options_ws_free(&options);
Mathieu Faverge's avatar
Mathieu Faverge committed
441
    RUNTIME_options_finalize(&options, chamctxt);
442
}