| [2aa6644] | 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 | *
|
|---|
| 18 | * Struct matrix-vector implementation of PCG interface routines.
|
|---|
| 19 | *
|
|---|
| 20 | *****************************************************************************/
|
|---|
| 21 |
|
|---|
| 22 | #include "headers.h"
|
|---|
| 23 |
|
|---|
| 24 | /*--------------------------------------------------------------------------
|
|---|
| 25 | * hypre_ParKrylovCAlloc
|
|---|
| 26 | *--------------------------------------------------------------------------*/
|
|---|
| 27 |
|
|---|
| 28 | char *
|
|---|
| 29 | hypre_ParKrylovCAlloc( int count,
|
|---|
| 30 | int elt_size )
|
|---|
| 31 | {
|
|---|
| 32 | return( hypre_CAlloc( count, elt_size ) );
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | /*--------------------------------------------------------------------------
|
|---|
| 36 | * hypre_ParKrylovFree
|
|---|
| 37 | *--------------------------------------------------------------------------*/
|
|---|
| 38 |
|
|---|
| 39 | int
|
|---|
| 40 | hypre_ParKrylovFree( char *ptr )
|
|---|
| 41 | {
|
|---|
| 42 | int ierr = 0;
|
|---|
| 43 |
|
|---|
| 44 | hypre_Free( ptr );
|
|---|
| 45 |
|
|---|
| 46 | return ierr;
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | /*--------------------------------------------------------------------------
|
|---|
| 50 | * hypre_ParKrylovCreateVector
|
|---|
| 51 | *--------------------------------------------------------------------------*/
|
|---|
| 52 |
|
|---|
| 53 | void *
|
|---|
| 54 | hypre_ParKrylovCreateVector( void *vvector )
|
|---|
| 55 | {
|
|---|
| 56 | hypre_ParVector *vector = vvector;
|
|---|
| 57 | hypre_ParVector *new_vector;
|
|---|
| 58 |
|
|---|
| 59 | new_vector = hypre_ParVectorCreate( hypre_ParVectorComm(vector),
|
|---|
| 60 | hypre_ParVectorGlobalSize(vector),
|
|---|
| 61 | hypre_ParVectorPartitioning(vector) );
|
|---|
| 62 | hypre_ParVectorSetPartitioningOwner(new_vector,0);
|
|---|
| 63 | hypre_ParVectorInitialize(new_vector);
|
|---|
| 64 |
|
|---|
| 65 | return ( (void *) new_vector );
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | /*--------------------------------------------------------------------------
|
|---|
| 69 | * hypre_ParKrylovCreateVectorArray
|
|---|
| 70 | *--------------------------------------------------------------------------*/
|
|---|
| 71 |
|
|---|
| 72 | void *
|
|---|
| 73 | hypre_ParKrylovCreateVectorArray(int n, void *vvector )
|
|---|
| 74 | {
|
|---|
| 75 | hypre_ParVector *vector = vvector;
|
|---|
| 76 | hypre_ParVector **new_vector;
|
|---|
| 77 | int i;
|
|---|
| 78 |
|
|---|
| 79 | new_vector = hypre_CTAlloc(hypre_ParVector*,n);
|
|---|
| 80 | for (i=0; i < n; i++)
|
|---|
| 81 | {
|
|---|
| 82 | new_vector[i] = hypre_ParVectorCreate( hypre_ParVectorComm(vector),
|
|---|
| 83 | hypre_ParVectorGlobalSize(vector),
|
|---|
| 84 | hypre_ParVectorPartitioning(vector) );
|
|---|
| 85 | hypre_ParVectorSetPartitioningOwner(new_vector[i],0);
|
|---|
| 86 | hypre_ParVectorInitialize(new_vector[i]);
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | return ( (void *) new_vector );
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | /*--------------------------------------------------------------------------
|
|---|
| 93 | * hypre_ParKrylovDestroyVector
|
|---|
| 94 | *--------------------------------------------------------------------------*/
|
|---|
| 95 |
|
|---|
| 96 | int
|
|---|
| 97 | hypre_ParKrylovDestroyVector( void *vvector )
|
|---|
| 98 | {
|
|---|
| 99 | hypre_ParVector *vector = vvector;
|
|---|
| 100 |
|
|---|
| 101 | return( hypre_ParVectorDestroy( vector ) );
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | /*--------------------------------------------------------------------------
|
|---|
| 105 | * hypre_ParKrylovMatvecCreate
|
|---|
| 106 | *--------------------------------------------------------------------------*/
|
|---|
| 107 |
|
|---|
| 108 | void *
|
|---|
| 109 | hypre_ParKrylovMatvecCreate( void *A,
|
|---|
| 110 | void *x )
|
|---|
| 111 | {
|
|---|
| 112 | void *matvec_data;
|
|---|
| 113 |
|
|---|
| 114 | matvec_data = NULL;
|
|---|
| 115 |
|
|---|
| 116 | return ( matvec_data );
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | /*--------------------------------------------------------------------------
|
|---|
| 120 | * hypre_ParKrylovMatvec
|
|---|
| 121 | *--------------------------------------------------------------------------*/
|
|---|
| 122 |
|
|---|
| 123 | int
|
|---|
| 124 | hypre_ParKrylovMatvec( void *matvec_data,
|
|---|
| 125 | double alpha,
|
|---|
| 126 | void *A,
|
|---|
| 127 | void *x,
|
|---|
| 128 | double beta,
|
|---|
| 129 | void *y )
|
|---|
| 130 | {
|
|---|
| 131 | return ( hypre_ParCSRMatrixMatvec ( alpha,
|
|---|
| 132 | (hypre_ParCSRMatrix *) A,
|
|---|
| 133 | (hypre_ParVector *) x,
|
|---|
| 134 | beta,
|
|---|
| 135 | (hypre_ParVector *) y ) );
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | /*--------------------------------------------------------------------------
|
|---|
| 139 | * hypre_ParKrylovMatvecT
|
|---|
| 140 | *--------------------------------------------------------------------------*/
|
|---|
| 141 |
|
|---|
| 142 | int
|
|---|
| 143 | hypre_ParKrylovMatvecT(void *matvec_data,
|
|---|
| 144 | double alpha,
|
|---|
| 145 | void *A,
|
|---|
| 146 | void *x,
|
|---|
| 147 | double beta,
|
|---|
| 148 | void *y )
|
|---|
| 149 | {
|
|---|
| 150 | return ( hypre_ParCSRMatrixMatvecT( alpha,
|
|---|
| 151 | (hypre_ParCSRMatrix *) A,
|
|---|
| 152 | (hypre_ParVector *) x,
|
|---|
| 153 | beta,
|
|---|
| 154 | (hypre_ParVector *) y ) );
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | /*--------------------------------------------------------------------------
|
|---|
| 158 | * hypre_ParKrylovMatvecDestroy
|
|---|
| 159 | *--------------------------------------------------------------------------*/
|
|---|
| 160 |
|
|---|
| 161 | int
|
|---|
| 162 | hypre_ParKrylovMatvecDestroy( void *matvec_data )
|
|---|
| 163 | {
|
|---|
| 164 | return 0;
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | /*--------------------------------------------------------------------------
|
|---|
| 168 | * hypre_ParKrylovInnerProd
|
|---|
| 169 | *--------------------------------------------------------------------------*/
|
|---|
| 170 |
|
|---|
| 171 | double
|
|---|
| 172 | hypre_ParKrylovInnerProd( void *x,
|
|---|
| 173 | void *y )
|
|---|
| 174 | {
|
|---|
| 175 | return ( hypre_ParVectorInnerProd( (hypre_ParVector *) x,
|
|---|
| 176 | (hypre_ParVector *) y ) );
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 | /*--------------------------------------------------------------------------
|
|---|
| 181 | * hypre_ParKrylovCopyVector
|
|---|
| 182 | *--------------------------------------------------------------------------*/
|
|---|
| 183 |
|
|---|
| 184 | int
|
|---|
| 185 | hypre_ParKrylovCopyVector( void *x,
|
|---|
| 186 | void *y )
|
|---|
| 187 | {
|
|---|
| 188 | return ( hypre_ParVectorCopy( (hypre_ParVector *) x,
|
|---|
| 189 | (hypre_ParVector *) y ) );
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | /*--------------------------------------------------------------------------
|
|---|
| 193 | * hypre_ParKrylovClearVector
|
|---|
| 194 | *--------------------------------------------------------------------------*/
|
|---|
| 195 |
|
|---|
| 196 | int
|
|---|
| 197 | hypre_ParKrylovClearVector( void *x )
|
|---|
| 198 | {
|
|---|
| 199 | return ( hypre_ParVectorSetConstantValues( (hypre_ParVector *) x, 0.0 ) );
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | /*--------------------------------------------------------------------------
|
|---|
| 203 | * hypre_ParKrylovScaleVector
|
|---|
| 204 | *--------------------------------------------------------------------------*/
|
|---|
| 205 |
|
|---|
| 206 | int
|
|---|
| 207 | hypre_ParKrylovScaleVector( double alpha,
|
|---|
| 208 | void *x )
|
|---|
| 209 | {
|
|---|
| 210 | return ( hypre_ParVectorScale( alpha, (hypre_ParVector *) x ) );
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 | /*--------------------------------------------------------------------------
|
|---|
| 214 | * hypre_ParKrylovAxpy
|
|---|
| 215 | *--------------------------------------------------------------------------*/
|
|---|
| 216 |
|
|---|
| 217 | int
|
|---|
| 218 | hypre_ParKrylovAxpy( double alpha,
|
|---|
| 219 | void *x,
|
|---|
| 220 | void *y )
|
|---|
| 221 | {
|
|---|
| 222 | return ( hypre_ParVectorAxpy( alpha, (hypre_ParVector *) x,
|
|---|
| 223 | (hypre_ParVector *) y ) );
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | /*--------------------------------------------------------------------------
|
|---|
| 227 | * hypre_ParKrylovCommInfo
|
|---|
| 228 | *--------------------------------------------------------------------------*/
|
|---|
| 229 |
|
|---|
| 230 | int
|
|---|
| 231 | hypre_ParKrylovCommInfo( void *A, int *my_id, int *num_procs)
|
|---|
| 232 | {
|
|---|
| 233 | MPI_Comm comm = hypre_ParCSRMatrixComm ( (hypre_ParCSRMatrix *) A);
|
|---|
| 234 | MPI_Comm_size(comm,num_procs);
|
|---|
| 235 | MPI_Comm_rank(comm,my_id);
|
|---|
| 236 | return 0;
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 | /*--------------------------------------------------------------------------
|
|---|
| 240 | * hypre_ParKrylovIdentitySetup
|
|---|
| 241 | *--------------------------------------------------------------------------*/
|
|---|
| 242 |
|
|---|
| 243 | int
|
|---|
| 244 | hypre_ParKrylovIdentitySetup( void *vdata,
|
|---|
| 245 | void *A,
|
|---|
| 246 | void *b,
|
|---|
| 247 | void *x )
|
|---|
| 248 |
|
|---|
| 249 | {
|
|---|
| 250 | return 0;
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | /*--------------------------------------------------------------------------
|
|---|
| 254 | * hypre_ParKrylovIdentity
|
|---|
| 255 | *--------------------------------------------------------------------------*/
|
|---|
| 256 |
|
|---|
| 257 | int
|
|---|
| 258 | hypre_ParKrylovIdentity( void *vdata,
|
|---|
| 259 | void *A,
|
|---|
| 260 | void *b,
|
|---|
| 261 | void *x )
|
|---|
| 262 |
|
|---|
| 263 | {
|
|---|
| 264 | return( hypre_ParKrylovCopyVector( b, x ) );
|
|---|
| 265 | }
|
|---|
| 266 |
|
|---|