| 1 |
/* |
| 2 |
|
| 3 |
Copyright (C) 2014, The University of Texas at Austin |
| 4 |
|
| 5 |
This file is part of libflame and is available under the 3-Clause |
| 6 |
BSD license, which can be found in the LICENSE file at the top-level |
| 7 |
directory, or at http://opensource.org/licenses/BSD-3-Clause |
| 8 |
|
| 9 |
*/ |
| 10 |
#include "FLAME.h" |
| 11 |
|
| 12 |
#define FLA_ALG_REFERENCE 0 |
| 13 |
#define FLA_ALG_FRONT 1 |
| 14 |
|
| 15 |
|
| 16 |
FLA_Error REF_LQ_UT( FLA_Obj A, FLA_Obj t ); |
| 17 |
void time_LQ_UT( |
| 18 |
int variant, int type, int nrepeats, int m, int n, |
| 19 |
FLA_Obj A, FLA_Obj A_ref, FLA_Obj t, FLA_Obj T, FLA_Obj W, FLA_Obj b, FLA_Obj b_orig, |
| 20 |
double *dtime, double *diff, double *gflops ); |
| 21 |
|
| 22 |
|
| 23 |
void time_LQ_UT( |
| 24 |
int variant, int type, int nrepeats, int m, int n, |
| 25 |
FLA_Obj A, FLA_Obj A_ref, FLA_Obj t, FLA_Obj T, FLA_Obj W, FLA_Obj b, FLA_Obj b_orig, |
| 26 |
double *dtime, double *diff, double *gflops ) |
| 27 |
{ |
| 28 |
int |
| 29 |
irep; |
| 30 |
|
| 31 |
double |
| 32 |
dtime_old = 1.0e9; |
| 33 |
|
| 34 |
FLA_Obj |
| 35 |
A_save, b_save, norm; |
| 36 |
|
| 37 |
|
| 38 |
FLA_Obj_create_conf_to( FLA_NO_TRANSPOSE, A, &A_save ); |
| 39 |
FLA_Obj_create_conf_to( FLA_NO_TRANSPOSE, b, &b_save ); |
| 40 |
|
| 41 |
FLA_Obj_create( FLA_Obj_datatype_proj_to_real( A ), 1, 1, 0, 0, &norm ); |
| 42 |
|
| 43 |
FLA_Copy_external( A, A_save ); |
| 44 |
FLA_Copy_external( b, b_save ); |
| 45 |
|
| 46 |
|
| 47 |
for ( irep = 0 ; irep < nrepeats; irep++ ){ |
| 48 |
|
| 49 |
FLA_Copy_external( A_save, A ); |
| 50 |
|
| 51 |
*dtime = FLA_Clock(); |
| 52 |
|
| 53 |
switch( variant ){ |
| 54 |
|
| 55 |
case 0:{ |
| 56 |
switch( type ){ |
| 57 |
case FLA_ALG_REFERENCE: |
| 58 |
REF_LQ_UT( A, t ); |
| 59 |
break; |
| 60 |
case FLA_ALG_FRONT: |
| 61 |
FLA_LQ_UT( A, T ); |
| 62 |
break; |
| 63 |
default: |
| 64 |
printf("trouble\n"); |
| 65 |
} |
| 66 |
|
| 67 |
break; |
| 68 |
} |
| 69 |
|
| 70 |
} |
| 71 |
|
| 72 |
*dtime = FLA_Clock() - *dtime; |
| 73 |
dtime_old = min( *dtime, dtime_old ); |
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
if ( type == FLA_ALG_REFERENCE ) |
| 78 |
{ |
| 79 |
FLA_Obj AL, AR; |
| 80 |
FLA_Obj xT, xB; |
| 81 |
FLA_Obj x, y; |
| 82 |
|
| 83 |
FLA_Obj_create( FLA_Obj_datatype( b ), n, 1, 0, 0, &y ); |
| 84 |
FLA_Obj_create( FLA_Obj_datatype( b ), n, 1, 0, 0, &x ); |
| 85 |
|
| 86 |
FLA_Copy_external( b, b_orig ); |
| 87 |
|
| 88 |
FLA_Part_1x2( A, &AL, &AR, FLA_Obj_length( A ), FLA_LEFT ); |
| 89 |
FLA_Part_2x1( x, &xT, |
| 90 |
&xB, FLA_Obj_length( A ), FLA_TOP ); |
| 91 |
|
| 92 |
FLA_Copy_external( b, xT ); |
| 93 |
|
| 94 |
FLA_Trsm_external( FLA_LEFT, FLA_LOWER_TRIANGULAR, FLA_NO_TRANSPOSE, |
| 95 |
FLA_NONUNIT_DIAG, FLA_ONE, AL, xT ); |
| 96 |
|
| 97 |
FLA_Set( FLA_ZERO, xB ); |
| 98 |
|
| 99 |
if ( FLA_Obj_is_real( A ) ) |
| 100 |
FLA_Apply_Q_blk_external( FLA_LEFT, FLA_TRANSPOSE, FLA_ROWWISE, A, t, x ); |
| 101 |
else |
| 102 |
FLA_Apply_Q_blk_external( FLA_LEFT, FLA_CONJ_TRANSPOSE, FLA_ROWWISE, A, t, x ); |
| 103 |
|
| 104 |
FLA_Gemv_external( FLA_NO_TRANSPOSE, FLA_MINUS_ONE, A_save, x, FLA_ONE, b_orig ); |
| 105 |
FLA_Gemv_external( FLA_CONJ_TRANSPOSE, FLA_ONE, A_save, b_orig, FLA_ZERO, y ); |
| 106 |
FLA_Nrm2_external( y, norm ); |
| 107 |
FLA_Obj_extract_real_scalar( norm, diff ); |
| 108 |
|
| 109 |
//FLA_Obj_show( "A_ref after:", A, "%10.3e", "" ); |
| 110 |
|
| 111 |
FLA_Obj_free( &y ); |
| 112 |
FLA_Obj_free( &x ); |
| 113 |
} |
| 114 |
else |
| 115 |
{ |
| 116 |
FLA_Obj x, y; |
| 117 |
|
| 118 |
FLA_Obj_create( FLA_Obj_datatype( b ), n, 1, 0, 0, &y ); |
| 119 |
FLA_Obj_create( FLA_Obj_datatype( b ), n, 1, 0, 0, &x ); |
| 120 |
|
| 121 |
FLA_Copy_external( b, b_orig ); |
| 122 |
|
| 123 |
FLA_LQ_UT_solve( A, T, b, x ); |
| 124 |
|
| 125 |
FLA_Gemv_external( FLA_NO_TRANSPOSE, FLA_MINUS_ONE, A_save, x, FLA_ONE, b_orig ); |
| 126 |
FLA_Gemv_external( FLA_CONJ_TRANSPOSE, FLA_ONE, A_save, b_orig, FLA_ZERO, y ); |
| 127 |
FLA_Nrm2_external( y, norm ); |
| 128 |
FLA_Obj_extract_real_scalar( norm, diff ); |
| 129 |
|
| 130 |
//FLA_Obj_show( "A after:", A, "%10.3e", "" ); |
| 131 |
/* |
| 132 |
{ |
| 133 |
FLA_Obj Ah, Ahh; |
| 134 |
|
| 135 |
FLA_Obj_create_copy_of( FLA_CONJ_TRANSPOSE, A_save, &Ah ); |
| 136 |
FLA_QR_UT( Ah, T ); |
| 137 |
FLA_Obj_create_copy_of( FLA_CONJ_TRANSPOSE, Ah, &Ahh ); |
| 138 |
*diff = FLA_Max_elemwise_diff( Ahh, A ); |
| 139 |
|
| 140 |
FLA_Obj_free( &Ah ); |
| 141 |
FLA_Obj_free( &Ahh ); |
| 142 |
} |
| 143 |
*/ |
| 144 |
FLA_Obj_free( &x ); |
| 145 |
FLA_Obj_free( &y ); |
| 146 |
} |
| 147 |
|
| 148 |
*gflops = ( 2.0 * n * m * m - |
| 149 |
( 2.0 / 3.0 ) * m * m * m ) / |
| 150 |
dtime_old / 1e9; |
| 151 |
if ( FLA_Obj_is_complex( A ) ) |
| 152 |
*gflops *= 4.0; |
| 153 |
|
| 154 |
*dtime = dtime_old; |
| 155 |
|
| 156 |
FLA_Copy_external( A_save, A ); |
| 157 |
FLA_Copy_external( b_save, b ); |
| 158 |
|
| 159 |
FLA_Obj_free( &A_save ); |
| 160 |
FLA_Obj_free( &b_save ); |
| 161 |
FLA_Obj_free( &norm ); |
| 162 |
} |
| 163 |
|