-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdgenm2.c
86 lines (76 loc) · 2.68 KB
/
pdgenm2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
*
* Copyright (c) 2017, King Abdullah University of Science and Technology
* All rights reserved.
*
**/
/**
*
* @file pdgenm2.c
*
* QDWH is a high performance software framework for computing
* the polar decomposition on distributed-memory manycore systems provided by KAUST
*
* @version 2.0.0
* @author Dalal Sukkari
* @author Hatem Ltaief
* @date 2017-11-13
*
**/
#include "common.h"
void pdgenm2( double *A, int M, int N, int descA[9], double *W, int descW[9], double *Sx, int descSx[9], double *e, double tol)
{
/*
*
* NORMEST Estimate the matrix 2-norm.
* NORMEST(S) is an estimate of the 2-norm of the matrix S.
* NORMEST(S,tol) uses relative error tol instead of 1.e-6.
* [nrm,cnt] = NORMEST(..) also gives the number of iterations used.
*
* This function is intended primarily for sparse matrices,
* although it works correctly and may be useful for large, full
* matrices as well. Use NORMEST when your problem is large
* enough that NORM takes too long to compute and an approximate
* norm is acceptable.
*
*/
int maxiter = 100; /* should never take this many iterations. */
int i1 = 1;
int cnt = 0;
int info;
double e0, alpha, beta, normx, normSx;
//x = sum(abs(S),1)';
/* Since in qdwh.c we are finding norm1 of the matrix A,
* then we already have the sum of the columns saved in W
* otherwise we should call the following pdlange
*/
//e0 = pdlange_ ( "1", &M, &N, A, &i1, &i1, descA, W);
double *w = (double *)malloc(1*sizeof(double)) ;
*e = pdlange_ ( "f", &N, &i1, W, &i1, &i1, descW, w);
//pdnrm2_( &N, e, W, &i1 , &i1, descW , &i1);
if (*e == 0){ return;}
//x = x/e;
alpha = 1.0;
pdlascl_( "G", e, &alpha, &N, &i1, W, &i1, &i1, descW, &info);
e0 = 0;
while ( (cnt < maxiter) &&
(fabs((*e) - e0) > (tol * (*e))) )
{
e0 = *e; alpha = 1.0; beta = 0.0;
pdgemv_ ("N", &M, &N, &alpha, A, &i1, &i1, descA, W, &i1, &i1, descW, &i1, &beta, Sx, &i1, &i1, descSx, &i1);
normSx = pdlange_ ( "f", &N, &i1, Sx, &i1, &i1, descSx, w);
//if nnz(Sx) == 0
// Sx = rand(size(Sx),class(Sx));
//end
pdgemv_ ("N", &M, &N, &alpha, A, &i1, &i1, descA, Sx, &i1, &i1, descSx, &i1, &beta, W, &i1, &i1, descW, &i1);
normx = pdlange_ ( "f", &N, &i1, W, &i1, &i1, descW, w);
*e = normx/normSx;
pdlascl_( "G", &normx, &alpha, &N, &i1, W, &i1, &i1, descW, &info);
cnt = cnt+1;
if ( (cnt >= maxiter) &&
(fabs((*e) - e0) > (tol * (*e))) ) {
fprintf(stderr, "normest: didn't converge\n");
}
}
return;
}