step1.h 3.52 KB
Newer Older
1
/**
2 3
 *
 * @file step1.h
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
 *
12
 * @brief Chameleon step1 example header
13 14 15 16 17
 *
 * @version 1.0.0
 * @author Florent Pruvost
 * @date 2014-10-29
 *
18
 */
PRUVOST Florent's avatar
PRUVOST Florent committed
19 20
#ifndef _step1_h_
#define _step1_h_
21 22

/* Common include for all steps of the tutorial */
Mathieu Faverge's avatar
Mathieu Faverge committed
23
#include "lapack_to_chameleon.h"
24 25

/* Specific includes for step 1 */
26
#include <coreblas/lapacke.h>
Mathieu Faverge's avatar
Mathieu Faverge committed
27
#include <chameleon.h>
28 29 30 31 32 33 34 35 36 37 38 39

/* Integer parameters for step1 */
enum iparam_step1 {
    IPARAM_THRDNBR,        /* Number of cores                            */
    IPARAM_N,              /* Number of columns of the matrix            */
    IPARAM_NRHS,           /* Number of RHS                              */
    /* End */
    IPARAM_SIZEOF
};

/* Specific routines used in step1.c main program */

40
/**
41 42 43 44 45 46 47 48
 * Initialize integer parameters
 */
static void init_iparam(int iparam[IPARAM_SIZEOF]){
    iparam[IPARAM_THRDNBR       ] = -1;
    iparam[IPARAM_N             ] = 500;
    iparam[IPARAM_NRHS          ] = 1;
 }

49
/**
50 51 52 53 54 55 56 57 58 59 60 61 62 63
 * Print how to use the program
 */
static void show_help(char *prog_name) {
    printf( "Usage:\n%s [options]\n\n", prog_name );
    printf( "Options are:\n"
            "  --help           Show this help\n"
            "\n"
            "  --n=X            dimension (N). (default: 500)\n"
            "  --nrhs=X         number of RHS. (default: 1)\n"
            "\n"
            "  --threads=X      Number of CPU workers (default: _SC_NPROCESSORS_ONLN)\n"
            "\n");
}

64
/**
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
 * Read arguments following step1 program call
 */
static void read_args(int argc, char *argv[], int *iparam){
    int i;
    for (i = 1; i < argc && argv[i]; ++i) {
        if ( startswith( argv[i], "--help") || startswith( argv[i], "-help") ||
             startswith( argv[i], "--h") || startswith( argv[i], "-h") ) {
            show_help( argv[0] );
            exit(0);
        } else if (startswith( argv[i], "--n=" )) {
            sscanf( strchr( argv[i], '=' ) + 1, "%d", &(iparam[IPARAM_N]) );
        } else if (startswith( argv[i], "--nrhs=" )) {
            sscanf( strchr( argv[i], '=' ) + 1, "%d", &(iparam[IPARAM_NRHS]) );
        } else if (startswith( argv[i], "--threads=" )) {
            sscanf( strchr( argv[i], '=' ) + 1, "%d", &(iparam[IPARAM_THRDNBR]) );
        } else {
            fprintf( stderr, "Unknown option: %s\n", argv[i] );
        }
    }
}

86
/**
87 88 89
 * Print a header message to summarize main parameters
 */
static void print_header(char *prog_name, int * iparam) {
90
#if defined(CHAMELEON_SIMULATION)
91 92 93 94 95 96
    double    eps = 0.;
#else
    double    eps = LAPACKE_dlamch_work( 'e' );
#endif

    printf( "#\n"
97
            "# CHAMELEON %d.%d.%d, %s\n"
98 99 100 101 102 103 104
            "# Nb threads: %d\n"
            "# Nb gpus:    %d\n"
            "# N:          %d\n"
            "# NB:         %d\n"
            "# IB:         %d\n"
            "# eps:        %e\n"
            "#\n",
105 106 107
            CHAMELEON_VERSION_MAJOR,
            CHAMELEON_VERSION_MINOR,
            CHAMELEON_VERSION_MICRO,
108 109 110 111 112 113 114 115 116 117 118 119 120 121
            prog_name,
            iparam[IPARAM_THRDNBR],
            0,
            iparam[IPARAM_N],
            128,
            32,
            eps );

    printf( "#      M       N  K/NRHS   seconds   Gflop/s\n");
    printf( "#%7d %7d %7d ", iparam[IPARAM_N], iparam[IPARAM_N], iparam[IPARAM_NRHS]);
    fflush( stdout );
    return;
}

PRUVOST Florent's avatar
PRUVOST Florent committed
122
#endif /* _step1_h_ */