source: CIVL/examples/mpi-omp/AMG2013/parcsr_ls/par_scaled_matnorm.c

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/*BHEADER**********************************************************************
2 * Copyright (c) 2008, Lawrence Livermore National Security, LLC.
3 * Produced at the Lawrence Livermore National Laboratory.
4 * This file is part of HYPRE. See file COPYRIGHT for details.
5 *
6 * HYPRE is free software; you can redistribute it and/or modify it under the
7 * terms of the GNU Lesser General Public License (as published by the Free
8 * Software Foundation) version 2.1 dated February 1999.
9 *
10 * $Revision: 2.4 $
11 ***********************************************************************EHEADER*/
12
13
14
15/******************************************************************************
16 *
17 * computes |D^-1/2 A D^-1/2 |_sup where D diagonal matrix
18 *
19 *****************************************************************************/
20
21#include "headers.h"
22
23/*--------------------------------------------------------------------------
24 * hypre_ParCSRMatrixScaledNorm
25 *--------------------------------------------------------------------------*/
26
27int
28hypre_ParCSRMatrixScaledNorm( hypre_ParCSRMatrix *A, double *scnorm)
29{
30 hypre_ParCSRCommHandle *comm_handle;
31 hypre_ParCSRCommPkg *comm_pkg = hypre_ParCSRMatrixCommPkg(A);
32 MPI_Comm comm = hypre_ParCSRMatrixComm(A);
33 hypre_CSRMatrix *diag = hypre_ParCSRMatrixDiag(A);
34 int *diag_i = hypre_CSRMatrixI(diag);
35 int *diag_j = hypre_CSRMatrixJ(diag);
36 double *diag_data = hypre_CSRMatrixData(diag);
37 hypre_CSRMatrix *offd = hypre_ParCSRMatrixOffd(A);
38 int *offd_i = hypre_CSRMatrixI(offd);
39 int *offd_j = hypre_CSRMatrixJ(offd);
40 double *offd_data = hypre_CSRMatrixData(offd);
41 HYPRE_BigInt global_num_rows = hypre_ParCSRMatrixGlobalNumRows(A);
42 HYPRE_BigInt *row_starts = hypre_ParCSRMatrixRowStarts(A);
43 int num_rows = hypre_CSRMatrixNumRows(diag);
44
45 hypre_ParVector *dinvsqrt;
46 double *dis_data;
47 hypre_Vector *dis_ext;
48 double *dis_ext_data;
49 hypre_Vector *sum;
50 double *sum_data;
51
52 int num_cols_offd = hypre_CSRMatrixNumCols(offd);
53 int num_sends, i, j, index, start;
54
55 double *d_buf_data;
56 double mat_norm, max_row_sum;
57
58 dinvsqrt = hypre_ParVectorCreate(comm, global_num_rows, row_starts);
59 hypre_ParVectorInitialize(dinvsqrt);
60 dis_data = hypre_VectorData(hypre_ParVectorLocalVector(dinvsqrt));
61 hypre_ParVectorSetPartitioningOwner(dinvsqrt,0);
62 dis_ext = hypre_SeqVectorCreate(num_cols_offd);
63 hypre_SeqVectorInitialize(dis_ext);
64 dis_ext_data = hypre_VectorData(dis_ext);
65 sum = hypre_SeqVectorCreate(num_rows);
66 hypre_SeqVectorInitialize(sum);
67 sum_data = hypre_VectorData(sum);
68
69 /* generate dinvsqrt */
70 for (i=0; i < num_rows; i++)
71 {
72 dis_data[i] = 1.0/sqrt(fabs(diag_data[diag_i[i]]));
73 }
74
75 /*---------------------------------------------------------------------
76 * If there exists no CommPkg for A, a CommPkg is generated using
77 * equally load balanced partitionings
78 *--------------------------------------------------------------------*/
79 if (!comm_pkg)
80 {
81#ifdef HYPRE_NO_GLOBAL_PARTITION
82 hypre_NewCommPkgCreate(A);
83#else
84 hypre_MatvecCommPkgCreate(A);
85#endif
86 comm_pkg = hypre_ParCSRMatrixCommPkg(A);
87 }
88
89 num_sends = hypre_ParCSRCommPkgNumSends(comm_pkg);
90 d_buf_data = hypre_CTAlloc(double, hypre_ParCSRCommPkgSendMapStart(comm_pkg,
91 num_sends));
92
93 index = 0;
94 for (i = 0; i < num_sends; i++)
95 {
96 start = hypre_ParCSRCommPkgSendMapStart(comm_pkg, i);
97 for (j = start; j < hypre_ParCSRCommPkgSendMapStart(comm_pkg, i+1); j++)
98 d_buf_data[index++]
99 = dis_data[hypre_ParCSRCommPkgSendMapElmt(comm_pkg,j)];
100 }
101
102 comm_handle = hypre_ParCSRCommHandleCreate( 1, comm_pkg, d_buf_data,
103 dis_ext_data);
104
105 for (i=0; i < num_rows; i++)
106 {
107 for (j=diag_i[i]; j < diag_i[i+1]; j++)
108 {
109 sum_data[i] += fabs(diag_data[j])*dis_data[i]*dis_data[diag_j[j]];
110 }
111 }
112 hypre_ParCSRCommHandleDestroy(comm_handle);
113
114 for (i=0; i < num_rows; i++)
115 {
116 for (j=offd_i[i]; j < offd_i[i+1]; j++)
117 {
118 sum_data[i] += fabs(offd_data[j])*dis_data[i]*dis_ext_data[offd_j[j]];
119 }
120 }
121
122 max_row_sum = 0;
123 for (i=0; i < num_rows; i++)
124 {
125 if (max_row_sum < sum_data[i])
126 max_row_sum = sum_data[i];
127 }
128
129 MPI_Allreduce(&max_row_sum, &mat_norm, 1, MPI_DOUBLE, MPI_MAX, comm);
130
131 hypre_ParVectorDestroy(dinvsqrt);
132 hypre_SeqVectorDestroy(sum);
133 hypre_SeqVectorDestroy(dis_ext);
134 hypre_TFree(d_buf_data);
135
136 *scnorm = mat_norm;
137 return 0;
138}
Note: See TracBrowser for help on using the repository browser.