diff --git a/AUTOTEST/check-headers.filters b/AUTOTEST/check-headers.filters new file mode 100644 index 000000000..580e2dff6 --- /dev/null +++ b/AUTOTEST/check-headers.filters @@ -0,0 +1,6 @@ +mpicc +mpif77 +include/fortran_matrix.h +include/multivector.h +include/interpreter.h +include/temp_multivector.h diff --git a/AUTOTEST/check-headers.sh b/AUTOTEST/check-headers.sh new file mode 100755 index 000000000..0a9847298 --- /dev/null +++ b/AUTOTEST/check-headers.sh @@ -0,0 +1,41 @@ +#!/bin/sh +# Copyright 1998-2019 Lawrence Livermore National Security, LLC and other +# HYPRE Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +testname=`basename $0 .sh` + +# Echo usage information +case $1 in + -h|-help) + cat <&2 diff --git a/src/examples/ex1.c b/src/examples/ex1.c index 738871b69..c8b1aa552 100644 --- a/src/examples/ex1.c +++ b/src/examples/ex1.c @@ -27,6 +27,7 @@ */ #include +#include /* Struct linear solvers header */ #include "HYPRE_struct_ls.h" diff --git a/src/examples/ex11.c b/src/examples/ex11.c index 0de0d885b..9954f47e0 100644 --- a/src/examples/ex11.c +++ b/src/examples/ex11.c @@ -24,6 +24,9 @@ The eigensolver is LOBPCG with AMG preconditioner. */ +#include +#include +#include #include #include "HYPRE.h" #include "HYPRE_parcsr_ls.h" diff --git a/src/examples/ex13.c b/src/examples/ex13.c index 18a6c822a..3639651de 100644 --- a/src/examples/ex13.c +++ b/src/examples/ex13.c @@ -77,6 +77,9 @@ connectivity" point. */ +#include +#include +#include #include #include "HYPRE_sstruct_mv.h" #include "HYPRE_sstruct_ls.h" diff --git a/src/examples/ex14.c b/src/examples/ex14.c index a25815b23..33a221b00 100644 --- a/src/examples/ex14.c +++ b/src/examples/ex14.c @@ -75,6 +75,9 @@ finite element problem in the SStruct interface. */ +#include +#include +#include #include #include "HYPRE_sstruct_mv.h" #include "HYPRE_sstruct_ls.h" diff --git a/src/examples/ex15.c b/src/examples/ex15.c index a3ba70bdb..36d62ca41 100644 --- a/src/examples/ex15.c +++ b/src/examples/ex15.c @@ -39,6 +39,9 @@ this example. */ +#include +#include +#include #include #include "HYPRE_sstruct_mv.h" #include "HYPRE_sstruct_ls.h" diff --git a/src/examples/ex15big.c b/src/examples/ex15big.c index 740ceab2e..e01801676 100644 --- a/src/examples/ex15big.c +++ b/src/examples/ex15big.c @@ -34,6 +34,9 @@ We recommend comparing this example with Example 15. */ +#include +#include +#include #include #include "HYPRE_sstruct_mv.h" #include "HYPRE_sstruct_ls.h" diff --git a/src/examples/ex16.c b/src/examples/ex16.c index f83c3eddc..15dae5468 100644 --- a/src/examples/ex16.c +++ b/src/examples/ex16.c @@ -24,6 +24,9 @@ an n x n sub-mesh of data, so the global mesh is nN x nN. */ +#include +#include +#include #include #include "HYPRE_sstruct_mv.h" #include "HYPRE_sstruct_ls.h" diff --git a/src/examples/ex2.c b/src/examples/ex2.c index c016d70f0..ff48c7245 100644 --- a/src/examples/ex2.c +++ b/src/examples/ex2.c @@ -26,6 +26,7 @@ */ #include +#include /* Struct linear solvers header */ #include "HYPRE_struct_ls.h" diff --git a/src/examples/ex3.c b/src/examples/ex3.c index d5e2db753..c5f486582 100644 --- a/src/examples/ex3.c +++ b/src/examples/ex3.c @@ -43,6 +43,9 @@ example. */ +#include +#include +#include #include #include "HYPRE_struct_ls.h" diff --git a/src/examples/ex4.c b/src/examples/ex4.c index a2c693ea8..2b23ce9eb 100644 --- a/src/examples/ex4.c +++ b/src/examples/ex4.c @@ -52,6 +52,9 @@ example. */ +#include +#include +#include #include #include "HYPRE_krylov.h" #include "HYPRE_struct_ls.h" diff --git a/src/examples/ex5.c b/src/examples/ex5.c index c0ad348fd..f02df1c49 100644 --- a/src/examples/ex5.c +++ b/src/examples/ex5.c @@ -23,6 +23,9 @@ solvers are AMG, PCG, and PCG with AMG or Parasails preconditioners. */ +#include +#include +#include #include #include "HYPRE_krylov.h" #include "HYPRE.h" diff --git a/src/examples/ex5big.c b/src/examples/ex5big.c index e7fcda44f..2c0347d08 100644 --- a/src/examples/ex5big.c +++ b/src/examples/ex5big.c @@ -31,6 +31,9 @@ recommend comparing this example with Example 5. */ +#include +#include +#include #include #include "HYPRE_krylov.h" #include "HYPRE.h" diff --git a/src/examples/ex6.c b/src/examples/ex6.c index 224f4dbe8..26a8a94e3 100644 --- a/src/examples/ex6.c +++ b/src/examples/ex6.c @@ -27,6 +27,8 @@ */ #include +#include +#include /* SStruct linear solvers headers */ #include "HYPRE_sstruct_ls.h" diff --git a/src/examples/ex7.c b/src/examples/ex7.c index 77182602b..56b296a2f 100644 --- a/src/examples/ex7.c +++ b/src/examples/ex7.c @@ -46,6 +46,9 @@ chapter of the User's Manual. */ +#include +#include +#include #include #include "HYPRE_krylov.h" #include "HYPRE_sstruct_ls.h" diff --git a/src/examples/ex8.c b/src/examples/ex8.c index d54acfe37..e9994e499 100644 --- a/src/examples/ex8.c +++ b/src/examples/ex8.c @@ -26,6 +26,8 @@ */ #include +#include +#include /* SStruct linear solvers headers */ #include "HYPRE_sstruct_ls.h" diff --git a/src/examples/ex9.c b/src/examples/ex9.c index 0e706a6ba..27bd3ab8f 100644 --- a/src/examples/ex9.c +++ b/src/examples/ex9.c @@ -38,6 +38,9 @@ We recommend viewing Examples 3, 6 and 7 before this example. */ +#include +#include +#include #include #include "HYPRE_sstruct_ls.h" #include "HYPRE_krylov.h" diff --git a/src/krylov/lobpcg.h b/src/krylov/lobpcg.h index 542dc031c..f917bc9cd 100644 --- a/src/krylov/lobpcg.h +++ b/src/krylov/lobpcg.h @@ -6,6 +6,7 @@ ******************************************************************************/ #include "multivector.h" +#include "_hypre_utilities.h" #ifndef LOCALLY_OPTIMAL_BLOCK_PRECONDITIONED_CONJUGATE_GRADIENTS #define LOCALLY_OPTIMAL_BLOCK_PRECONDITIONED_CONJUGATE_GRADIENTS diff --git a/src/test/struct_newboxloop.c b/src/test/struct_newboxloop.c index 2685326f4..a8e95ec2f 100644 --- a/src/test/struct_newboxloop.c +++ b/src/test/struct_newboxloop.c @@ -37,11 +37,7 @@ #include -#include "fortran_matrix.h" #include "HYPRE_lobpcg.h" -#include "interpreter.h" -#include "multivector.h" -#include "HYPRE_MatvecFunctions.h" /* end lobpcg */ diff --git a/src/test/test_mgr.c b/src/test/test_mgr.c index 9b52a5331..5170cb1cf 100644 --- a/src/test/test_mgr.c +++ b/src/test/test_mgr.c @@ -36,13 +36,8 @@ #include #include -#include "fortran_matrix.h" #include "HYPRE_lobpcg.h" -#include "interpreter.h" -#include "multivector.h" -#include "HYPRE_MatvecFunctions.h" - /* max dt */ #define DT_INF 1.0e30 HYPRE_Int diff --git a/src/utilities/HYPRE_utilities.h b/src/utilities/HYPRE_utilities.h index b2e6e4368..66acc4036 100644 --- a/src/utilities/HYPRE_utilities.h +++ b/src/utilities/HYPRE_utilities.h @@ -109,6 +109,13 @@ typedef HYPRE_Int MPI_Comm; /* bits 4-8 are reserved for the index of the argument error */ #define HYPRE_ERROR_CONV 256 /* method did not converge as expected */ +/*-------------------------------------------------------------------------- + * HYPRE init/finalize + *--------------------------------------------------------------------------*/ + +HYPRE_Int HYPRE_Init(); +HYPRE_Int HYPRE_Finalize(); + /*-------------------------------------------------------------------------- * HYPRE error user functions *--------------------------------------------------------------------------*/ diff --git a/src/utilities/_hypre_utilities.h b/src/utilities/_hypre_utilities.h index 958aeedf0..8c61778e3 100644 --- a/src/utilities/_hypre_utilities.h +++ b/src/utilities/_hypre_utilities.h @@ -2919,8 +2919,6 @@ HYPRE_Real hypre_cimag( HYPRE_Complex value ); hypre_Handle* hypre_handle(); hypre_Handle* hypre_HandleCreate(); HYPRE_Int hypre_HandleDestroy(hypre_Handle *hypre_handle_); -HYPRE_Int HYPRE_Init(); -HYPRE_Int HYPRE_Finalize(); HYPRE_Int hypre_SetDevice(HYPRE_Int use_device, hypre_Handle *hypre_handle_); /* hypre_qsort.c */ diff --git a/src/utilities/fortran_matrix.c b/src/utilities/fortran_matrix.c index b0fac17b6..672830160 100644 --- a/src/utilities/fortran_matrix.c +++ b/src/utilities/fortran_matrix.c @@ -15,706 +15,706 @@ utilities_FortranMatrix* utilities_FortranMatrixCreate(void) { - utilities_FortranMatrix* mtx; + utilities_FortranMatrix* mtx; - mtx = hypre_TAlloc(utilities_FortranMatrix, 1, HYPRE_MEMORY_HOST); - hypre_assert( mtx != NULL ); + mtx = hypre_TAlloc(utilities_FortranMatrix, 1, HYPRE_MEMORY_HOST); + hypre_assert( mtx != NULL ); - mtx->globalHeight = 0; - mtx->height = 0; - mtx->width = 0; - mtx->value = NULL; - mtx->ownsValues = 0; + mtx->globalHeight = 0; + mtx->height = 0; + mtx->width = 0; + mtx->value = NULL; + mtx->ownsValues = 0; - return mtx; + return mtx; } void -utilities_FortranMatrixAllocateData( hypre_longint h, hypre_longint w, - utilities_FortranMatrix* mtx ) { +utilities_FortranMatrixAllocateData( HYPRE_BigInt h, HYPRE_BigInt w, + utilities_FortranMatrix* mtx ) { - hypre_assert( h > 0 && w > 0 ); - hypre_assert( mtx != NULL ); + hypre_assert( h > 0 && w > 0 ); + hypre_assert( mtx != NULL ); - if ( mtx->value != NULL && mtx->ownsValues ) - free( mtx->value ); + if ( mtx->value != NULL && mtx->ownsValues ) + free( mtx->value ); - mtx->value = hypre_CTAlloc(HYPRE_Real, h*w, HYPRE_MEMORY_HOST); - hypre_assert ( mtx->value != NULL ); + mtx->value = hypre_CTAlloc(HYPRE_Real, h*w, HYPRE_MEMORY_HOST); + hypre_assert ( mtx->value != NULL ); - mtx->globalHeight = h; - mtx->height = h; - mtx->width = w; - mtx->ownsValues = 1; + mtx->globalHeight = h; + mtx->height = h; + mtx->width = w; + mtx->ownsValues = 1; } void -utilities_FortranMatrixWrap( HYPRE_Real* v, hypre_longint gh, hypre_longint h, hypre_longint w, - utilities_FortranMatrix* mtx ) { +utilities_FortranMatrixWrap( HYPRE_Real* v, HYPRE_BigInt gh, HYPRE_BigInt h, HYPRE_BigInt w, + utilities_FortranMatrix* mtx ) { - hypre_assert( h > 0 && w > 0 ); - hypre_assert( mtx != NULL ); + hypre_assert( h > 0 && w > 0 ); + hypre_assert( mtx != NULL ); - if ( mtx->value != NULL && mtx->ownsValues ) - free( mtx->value ); + if ( mtx->value != NULL && mtx->ownsValues ) + free( mtx->value ); - mtx->value = v; - hypre_assert ( mtx->value != NULL ); + mtx->value = v; + hypre_assert ( mtx->value != NULL ); - mtx->globalHeight = gh; - mtx->height = h; - mtx->width = w; - mtx->ownsValues = 0; + mtx->globalHeight = gh; + mtx->height = h; + mtx->width = w; + mtx->ownsValues = 0; } void utilities_FortranMatrixDestroy( utilities_FortranMatrix* mtx ) { - if ( mtx == NULL ) - return; + if ( mtx == NULL ) + return; - if ( mtx->ownsValues && mtx->value != NULL ) - free(mtx->value); + if ( mtx->ownsValues && mtx->value != NULL ) + free(mtx->value); - free(mtx); + free(mtx); } -hypre_longint +HYPRE_BigInt utilities_FortranMatrixGlobalHeight( utilities_FortranMatrix* mtx ) { - hypre_assert( mtx != NULL ); + hypre_assert( mtx != NULL ); - return mtx->globalHeight; + return mtx->globalHeight; } -hypre_longint +HYPRE_BigInt utilities_FortranMatrixHeight( utilities_FortranMatrix* mtx ) { - hypre_assert( mtx != NULL ); + hypre_assert( mtx != NULL ); - return mtx->height; + return mtx->height; } -hypre_longint +HYPRE_BigInt utilities_FortranMatrixWidth( utilities_FortranMatrix* mtx ) { - hypre_assert( mtx != NULL ); + hypre_assert( mtx != NULL ); - return mtx->width; + return mtx->width; } HYPRE_Real* utilities_FortranMatrixValues( utilities_FortranMatrix* mtx ) { - hypre_assert( mtx != NULL ); + hypre_assert( mtx != NULL ); - return mtx->value; + return mtx->value; } void utilities_FortranMatrixClear( utilities_FortranMatrix* mtx ) { - hypre_longint i, j, h, w, jump; - HYPRE_Real* p; + HYPRE_BigInt i, j, h, w, jump; + HYPRE_Real* p; - hypre_assert( mtx != NULL ); + hypre_assert( mtx != NULL ); - h = mtx->height; - w = mtx->width; + h = mtx->height; + w = mtx->width; - jump = mtx->globalHeight - h; - - for ( j = 0, p = mtx->value; j < w; j++ ) { - for ( i = 0; i < h; i++, p++ ) - *p = 0.0; - p += jump; - } + jump = mtx->globalHeight - h; + + for ( j = 0, p = mtx->value; j < w; j++ ) { + for ( i = 0; i < h; i++, p++ ) + *p = 0.0; + p += jump; + } } void utilities_FortranMatrixClearL( utilities_FortranMatrix* mtx ) { - hypre_longint i, j, k, h, w, jump; - HYPRE_Real* p; + HYPRE_BigInt i, j, k, h, w, jump; + HYPRE_Real* p; - hypre_assert( mtx != NULL ); + hypre_assert( mtx != NULL ); - h = mtx->height; - w = mtx->width; + h = mtx->height; + w = mtx->width; - if ( w > h ) - w = h; + if ( w > h ) + w = h; - jump = mtx->globalHeight - h; - - for ( j = 0, p = mtx->value; j < w - 1; j++ ) { - k = j + 1; - p += k; - for ( i = k; i < h; i++, p++ ) - *p = 0.0; - p += jump; - } + jump = mtx->globalHeight - h; + + for ( j = 0, p = mtx->value; j < w - 1; j++ ) { + k = j + 1; + p += k; + for ( i = k; i < h; i++, p++ ) + *p = 0.0; + p += jump; + } } -void +void utilities_FortranMatrixSetToIdentity( utilities_FortranMatrix* mtx ) { - hypre_longint j, h, w, jump; - HYPRE_Real* p; + HYPRE_BigInt j, h, w, jump; + HYPRE_Real* p; - hypre_assert( mtx != NULL ); + hypre_assert( mtx != NULL ); - utilities_FortranMatrixClear( mtx ); + utilities_FortranMatrixClear( mtx ); - h = mtx->height; - w = mtx->width; + h = mtx->height; + w = mtx->width; - jump = mtx->globalHeight; + jump = mtx->globalHeight; - for ( j = 0, p = mtx->value; j < w && j < h; j++, p += jump ) - *p++ = 1.0; + for ( j = 0, p = mtx->value; j < w && j < h; j++, p += jump ) + *p++ = 1.0; } -void +void utilities_FortranMatrixTransposeSquare( utilities_FortranMatrix* mtx ) { - hypre_longint i, j, g, h, w, jump; - HYPRE_Real* p; - HYPRE_Real* q; - HYPRE_Real tmp; + HYPRE_BigInt i, j, g, h, w, jump; + HYPRE_Real* p; + HYPRE_Real* q; + HYPRE_Real tmp; - hypre_assert( mtx != NULL ); + hypre_assert( mtx != NULL ); - g = mtx->globalHeight; - h = mtx->height; - w = mtx->width; + g = mtx->globalHeight; + h = mtx->height; + w = mtx->width; - hypre_assert( h == w ); + hypre_assert( h == w ); - jump = mtx->globalHeight - h; - - for ( j = 0, p = mtx->value; j < w; j++ ) { - q = p; - p++; - q += g; - for ( i = j + 1; i < h; i++, p++, q += g ) { - tmp = *p; - *p = *q; - *q = tmp; - } - p += ++jump; - } + jump = mtx->globalHeight - h; + + for ( j = 0, p = mtx->value; j < w; j++ ) { + q = p; + p++; + q += g; + for ( i = j + 1; i < h; i++, p++, q += g ) { + tmp = *p; + *p = *q; + *q = tmp; + } + p += ++jump; + } } -void +void utilities_FortranMatrixSymmetrize( utilities_FortranMatrix* mtx ) { - hypre_longint i, j, g, h, w, jump; - HYPRE_Real* p; - HYPRE_Real* q; + HYPRE_BigInt i, j, g, h, w, jump; + HYPRE_Real* p; + HYPRE_Real* q; - hypre_assert( mtx != NULL ); + hypre_assert( mtx != NULL ); - g = mtx->globalHeight; - h = mtx->height; - w = mtx->width; + g = mtx->globalHeight; + h = mtx->height; + w = mtx->width; - hypre_assert( h == w ); + hypre_assert( h == w ); - jump = mtx->globalHeight - h; - - for ( j = 0, p = mtx->value; j < w; j++ ) { - q = p; - p++; - q += g; - for ( i = j + 1; i < h; i++, p++, q += g ) - *p = *q = (*p + *q)*0.5; - p += ++jump; - } + jump = mtx->globalHeight - h; + + for ( j = 0, p = mtx->value; j < w; j++ ) { + q = p; + p++; + q += g; + for ( i = j + 1; i < h; i++, p++, q += g ) + *p = *q = (*p + *q)*0.5; + p += ++jump; + } } -void -utilities_FortranMatrixCopy( utilities_FortranMatrix* src, HYPRE_Int t, - utilities_FortranMatrix* dest ) { +void +utilities_FortranMatrixCopy( utilities_FortranMatrix* src, HYPRE_Int t, + utilities_FortranMatrix* dest ) { - hypre_longint i, j, h, w; - hypre_longint jp, jq, jr; - HYPRE_Real* p; - HYPRE_Real* q; - HYPRE_Real* r; + HYPRE_BigInt i, j, h, w; + HYPRE_BigInt jp, jq, jr; + HYPRE_Real* p; + HYPRE_Real* q; + HYPRE_Real* r; - hypre_assert( src != NULL && dest != NULL ); + hypre_assert( src != NULL && dest != NULL ); - h = dest->height; - w = dest->width; + h = dest->height; + w = dest->width; - jp = dest->globalHeight - h; + jp = dest->globalHeight - h; - if ( t == 0 ) { - hypre_assert( src->height == h && src->width == w ); - jq = 1; - jr = src->globalHeight; - } - else { - hypre_assert( src->height == w && src->width == h ); - jr = 1; - jq = src->globalHeight; - } + if ( t == 0 ) { + hypre_assert( src->height == h && src->width == w ); + jq = 1; + jr = src->globalHeight; + } + else { + hypre_assert( src->height == w && src->width == h ); + jr = 1; + jq = src->globalHeight; + } - for ( j = 0, p = dest->value, r = src->value; j < w; j++, p += jp, r += jr ) - for ( i = 0, q = r; i < h; i++, p++, q += jq ) + for ( j = 0, p = dest->value, r = src->value; j < w; j++, p += jp, r += jr ) + for ( i = 0, q = r; i < h; i++, p++, q += jq ) + *p = *q; +} + +void +utilities_FortranMatrixIndexCopy( HYPRE_Int* index, + utilities_FortranMatrix* src, HYPRE_Int t, + utilities_FortranMatrix* dest ) { + + HYPRE_BigInt i, j, h, w; + HYPRE_BigInt jp, jq, jr; + HYPRE_Real* p; + HYPRE_Real* q; + HYPRE_Real* r; + + hypre_assert( src != NULL && dest != NULL ); + + h = dest->height; + w = dest->width; + + jp = dest->globalHeight - h; + + if ( t == 0 ) { + hypre_assert( src->height == h && src->width == w ); + jq = 1; + jr = src->globalHeight; + } + else { + hypre_assert( src->height == w && src->width == h ); + jr = 1; + jq = src->globalHeight; + } + + for ( j = 0, p = dest->value; j < w; j++, p += jp ) { + r = src->value + (index[j]-1)*jr; + for ( i = 0, q = r; i < h; i++, p++, q += jq ) + *p = *q; + } +} + +void +utilities_FortranMatrixSetDiagonal( utilities_FortranMatrix* mtx, + utilities_FortranMatrix* vec ) { + + HYPRE_BigInt j, h, w, jump; + HYPRE_Real* p; + HYPRE_Real* q; + + hypre_assert( mtx != NULL && vec != NULL ); + + h = mtx->height; + w = mtx->width; + + hypre_assert( vec->height >= h ); + + jump = mtx->globalHeight + 1; + + for ( j = 0, p = mtx->value, q = vec->value; j < w && j < h; + j++, p += jump, q++ ) *p = *q; -} - -void -utilities_FortranMatrixIndexCopy( HYPRE_Int* index, - utilities_FortranMatrix* src, HYPRE_Int t, - utilities_FortranMatrix* dest ) { - - hypre_longint i, j, h, w; - hypre_longint jp, jq, jr; - HYPRE_Real* p; - HYPRE_Real* q; - HYPRE_Real* r; - - hypre_assert( src != NULL && dest != NULL ); - - h = dest->height; - w = dest->width; - - jp = dest->globalHeight - h; - - if ( t == 0 ) { - hypre_assert( src->height == h && src->width == w ); - jq = 1; - jr = src->globalHeight; - } - else { - hypre_assert( src->height == w && src->width == h ); - jr = 1; - jq = src->globalHeight; - } - - for ( j = 0, p = dest->value; j < w; j++, p += jp ) { - r = src->value + (index[j]-1)*jr; - for ( i = 0, q = r; i < h; i++, p++, q += jq ) - *p = *q; - } -} - -void -utilities_FortranMatrixSetDiagonal( utilities_FortranMatrix* mtx, - utilities_FortranMatrix* vec ) { - - hypre_longint j, h, w, jump; - HYPRE_Real* p; - HYPRE_Real* q; - - hypre_assert( mtx != NULL && vec != NULL ); - - h = mtx->height; - w = mtx->width; - - hypre_assert( vec->height >= h ); - - jump = mtx->globalHeight + 1; - - for ( j = 0, p = mtx->value, q = vec->value; j < w && j < h; - j++, p += jump, q++ ) - *p = *q; } -void -utilities_FortranMatrixGetDiagonal( utilities_FortranMatrix* mtx, - utilities_FortranMatrix* vec ) { +void +utilities_FortranMatrixGetDiagonal( utilities_FortranMatrix* mtx, + utilities_FortranMatrix* vec ) { - hypre_longint j, h, w, jump; - HYPRE_Real* p; - HYPRE_Real* q; - - hypre_assert( mtx != NULL && vec != NULL ); + HYPRE_BigInt j, h, w, jump; + HYPRE_Real* p; + HYPRE_Real* q; - h = mtx->height; - w = mtx->width; + hypre_assert( mtx != NULL && vec != NULL ); - hypre_assert( vec->height >= h ); + h = mtx->height; + w = mtx->width; - jump = mtx->globalHeight + 1; + hypre_assert( vec->height >= h ); - for ( j = 0, p = mtx->value, q = vec->value; j < w && j < h; - j++, p += jump, q++ ) - *q = *p; + jump = mtx->globalHeight + 1; + + for ( j = 0, p = mtx->value, q = vec->value; j < w && j < h; + j++, p += jump, q++ ) + *q = *p; } -void -utilities_FortranMatrixAdd( HYPRE_Real a, - utilities_FortranMatrix* mtxA, - utilities_FortranMatrix* mtxB, - utilities_FortranMatrix* mtxC ) { +void +utilities_FortranMatrixAdd( HYPRE_Real a, + utilities_FortranMatrix* mtxA, + utilities_FortranMatrix* mtxB, + utilities_FortranMatrix* mtxC ) { - hypre_longint i, j, h, w, jA, jB, jC; - HYPRE_Real *pA; - HYPRE_Real *pB; - HYPRE_Real *pC; + HYPRE_BigInt i, j, h, w, jA, jB, jC; + HYPRE_Real *pA; + HYPRE_Real *pB; + HYPRE_Real *pC; - hypre_assert( mtxA != NULL && mtxB != NULL && mtxC != NULL ); + hypre_assert( mtxA != NULL && mtxB != NULL && mtxC != NULL ); - h = mtxA->height; - w = mtxA->width; + h = mtxA->height; + w = mtxA->width; - hypre_assert( mtxB->height == h && mtxB->width == w ); - hypre_assert( mtxC->height == h && mtxC->width == w ); + hypre_assert( mtxB->height == h && mtxB->width == w ); + hypre_assert( mtxC->height == h && mtxC->width == w ); - jA = mtxA->globalHeight - h; - jB = mtxB->globalHeight - h; - jC = mtxC->globalHeight - h; + jA = mtxA->globalHeight - h; + jB = mtxB->globalHeight - h; + jC = mtxC->globalHeight - h; - pA = mtxA->value; - pB = mtxB->value; - pC = mtxC->value; + pA = mtxA->value; + pB = mtxB->value; + pC = mtxC->value; - if ( a == 0.0 ) { - for ( j = 0; j < w; j++ ) { - for ( i = 0; i < h; i++, pA++, pB++, pC++ ) - *pC = *pB; - pA += jA; - pB += jB; - pC += jC; - } - } - else if ( a == 1.0 ) { - for ( j = 0; j < w; j++ ) { - for ( i = 0; i < h; i++, pA++, pB++, pC++ ) - *pC = *pA + *pB; - pA += jA; - pB += jB; - pC += jC; - } - } - else if ( a == -1.0 ) { - for ( j = 0; j < w; j++ ) { - for ( i = 0; i < h; i++, pA++, pB++, pC++ ) - *pC = *pB - *pA; - pA += jA; - pB += jB; - pC += jC; - } - } - else { - for ( j = 0; j < w; j++ ) { - for ( i = 0; i < h; i++, pA++, pB++, pC++ ) - *pC = *pA * a + *pB; - pA += jA; - pB += jB; - pC += jC; - } - } + if ( a == 0.0 ) { + for ( j = 0; j < w; j++ ) { + for ( i = 0; i < h; i++, pA++, pB++, pC++ ) + *pC = *pB; + pA += jA; + pB += jB; + pC += jC; + } + } + else if ( a == 1.0 ) { + for ( j = 0; j < w; j++ ) { + for ( i = 0; i < h; i++, pA++, pB++, pC++ ) + *pC = *pA + *pB; + pA += jA; + pB += jB; + pC += jC; + } + } + else if ( a == -1.0 ) { + for ( j = 0; j < w; j++ ) { + for ( i = 0; i < h; i++, pA++, pB++, pC++ ) + *pC = *pB - *pA; + pA += jA; + pB += jB; + pC += jC; + } + } + else { + for ( j = 0; j < w; j++ ) { + for ( i = 0; i < h; i++, pA++, pB++, pC++ ) + *pC = *pA * a + *pB; + pA += jA; + pB += jB; + pC += jC; + } + } } -void -utilities_FortranMatrixDMultiply( utilities_FortranMatrix* vec, - utilities_FortranMatrix* mtx ) { +void +utilities_FortranMatrixDMultiply( utilities_FortranMatrix* vec, + utilities_FortranMatrix* mtx ) { - hypre_longint i, j, h, w, jump; - HYPRE_Real* p; - HYPRE_Real* q; + HYPRE_BigInt i, j, h, w, jump; + HYPRE_Real* p; + HYPRE_Real* q; - hypre_assert( mtx != NULL && vec != NULL ); + hypre_assert( mtx != NULL && vec != NULL ); - h = mtx->height; - w = mtx->width; + h = mtx->height; + w = mtx->width; - hypre_assert( vec->height == h ); + hypre_assert( vec->height == h ); - jump = mtx->globalHeight - h; + jump = mtx->globalHeight - h; - for ( j = 0, p = mtx->value; j < w; j++ ) { - for ( i = 0, q = vec->value; i < h; i++, p++, q++ ) - *p = *p * (*q); - p += jump; - } + for ( j = 0, p = mtx->value; j < w; j++ ) { + for ( i = 0, q = vec->value; i < h; i++, p++, q++ ) + *p = *p * (*q); + p += jump; + } } -void -utilities_FortranMatrixMultiplyD( utilities_FortranMatrix* mtx, - utilities_FortranMatrix* vec ) { +void +utilities_FortranMatrixMultiplyD( utilities_FortranMatrix* mtx, + utilities_FortranMatrix* vec ) { - hypre_longint i, j, h, w, jump; - HYPRE_Real* p; - HYPRE_Real* q; + HYPRE_BigInt i, j, h, w, jump; + HYPRE_Real* p; + HYPRE_Real* q; - hypre_assert( mtx != NULL && vec != NULL ); + hypre_assert( mtx != NULL && vec != NULL ); - h = mtx->height; - w = mtx->width; + h = mtx->height; + w = mtx->width; - hypre_assert( vec->height == w ); + hypre_assert( vec->height == w ); - jump = mtx->globalHeight - h; + jump = mtx->globalHeight - h; - for ( j = 0, q = vec->value, p = mtx->value; j < w; j++, q++ ) { - for ( i = 0; i < h; i++, p++) - *p = *p * (*q); - p += jump; - } + for ( j = 0, q = vec->value, p = mtx->value; j < w; j++, q++ ) { + for ( i = 0; i < h; i++, p++) + *p = *p * (*q); + p += jump; + } } -void -utilities_FortranMatrixMultiply( utilities_FortranMatrix* mtxA, HYPRE_Int tA, - utilities_FortranMatrix* mtxB, HYPRE_Int tB, - utilities_FortranMatrix* mtxC ) { - hypre_longint h, w; - hypre_longint i, j, k, l; - hypre_longint iA, kA; - hypre_longint kB, jB; - hypre_longint iC, jC; +void +utilities_FortranMatrixMultiply( utilities_FortranMatrix* mtxA, HYPRE_Int tA, + utilities_FortranMatrix* mtxB, HYPRE_Int tB, + utilities_FortranMatrix* mtxC ) { + HYPRE_BigInt h, w; + HYPRE_BigInt i, j, k, l; + HYPRE_BigInt iA, kA; + HYPRE_BigInt kB, jB; + HYPRE_BigInt iC, jC; - HYPRE_Real* pAi0; - HYPRE_Real* pAik; - HYPRE_Real* pB0j; - HYPRE_Real* pBkj; - HYPRE_Real* pC0j; - HYPRE_Real* pCij; + HYPRE_Real* pAi0; + HYPRE_Real* pAik; + HYPRE_Real* pB0j; + HYPRE_Real* pBkj; + HYPRE_Real* pC0j; + HYPRE_Real* pCij; - HYPRE_Real s; + HYPRE_Real s; - hypre_assert( mtxA != NULL && mtxB != NULL && mtxC != NULL ); + hypre_assert( mtxA != NULL && mtxB != NULL && mtxC != NULL ); - h = mtxC->height; - w = mtxC->width; - iC = 1; - jC = mtxC->globalHeight; + h = mtxC->height; + w = mtxC->width; + iC = 1; + jC = mtxC->globalHeight; - if ( tA == 0 ) { - hypre_assert( mtxA->height == h ); - l = mtxA->width; - iA = 1; - kA = mtxA->globalHeight; - } - else { - l = mtxA->height; - hypre_assert( mtxA->width == h ); - kA = 1; - iA = mtxA->globalHeight; - } + if ( tA == 0 ) { + hypre_assert( mtxA->height == h ); + l = mtxA->width; + iA = 1; + kA = mtxA->globalHeight; + } + else { + l = mtxA->height; + hypre_assert( mtxA->width == h ); + kA = 1; + iA = mtxA->globalHeight; + } - if ( tB == 0 ) { - hypre_assert( mtxB->height == l ); - hypre_assert( mtxB->width == w ); - kB = 1; - jB = mtxB->globalHeight; - } - else { - hypre_assert( mtxB->width == l ); - hypre_assert( mtxB->height == w ); - jB = 1; - kB = mtxB->globalHeight; - } + if ( tB == 0 ) { + hypre_assert( mtxB->height == l ); + hypre_assert( mtxB->width == w ); + kB = 1; + jB = mtxB->globalHeight; + } + else { + hypre_assert( mtxB->width == l ); + hypre_assert( mtxB->height == w ); + jB = 1; + kB = mtxB->globalHeight; + } - for ( j = 0, pB0j = mtxB->value, pC0j = mtxC->value; j < w; - j++, pB0j += jB, pC0j += jC ) - for ( i = 0, pCij = pC0j, pAi0 = mtxA->value; i < h; - i++, pCij += iC, pAi0 += iA ) { - s = 0.0; - for ( k = 0, pAik = pAi0, pBkj = pB0j; k < l; - k++, pAik += kA, pBkj += kB ) - s += *pAik * (*pBkj); - *pCij = s; - } + for ( j = 0, pB0j = mtxB->value, pC0j = mtxC->value; j < w; + j++, pB0j += jB, pC0j += jC ) + for ( i = 0, pCij = pC0j, pAi0 = mtxA->value; i < h; + i++, pCij += iC, pAi0 += iA ) { + s = 0.0; + for ( k = 0, pAik = pAi0, pBkj = pB0j; k < l; + k++, pAik += kA, pBkj += kB ) + s += *pAik * (*pBkj); + *pCij = s; + } } -HYPRE_Real +HYPRE_Real utilities_FortranMatrixFNorm( utilities_FortranMatrix* mtx ) { - - hypre_longint i, j, h, w, jump; - HYPRE_Real* p; - HYPRE_Real norm; + HYPRE_BigInt i, j, h, w, jump; + HYPRE_Real* p; - hypre_assert( mtx != NULL ); + HYPRE_Real norm; - h = mtx->height; - w = mtx->width; - - jump = mtx->globalHeight - h; + hypre_assert( mtx != NULL ); - norm = 0.0; + h = mtx->height; + w = mtx->width; - for ( j = 0, p = mtx->value; j < w; j++ ) { - for ( i = 0; i < h; i++, p++ ) - norm += (*p) * (*p); - p += jump; - } + jump = mtx->globalHeight - h; - norm = sqrt(norm); - return norm; + norm = 0.0; + + for ( j = 0, p = mtx->value; j < w; j++ ) { + for ( i = 0; i < h; i++, p++ ) + norm += (*p) * (*p); + p += jump; + } + + norm = sqrt(norm); + return norm; } -HYPRE_Real -utilities_FortranMatrixValue( utilities_FortranMatrix* mtx, - hypre_longint i, hypre_longint j ) { +HYPRE_Real +utilities_FortranMatrixValue( utilities_FortranMatrix* mtx, + HYPRE_BigInt i, HYPRE_BigInt j ) { - hypre_longint k; + HYPRE_BigInt k; - hypre_assert( mtx != NULL ); + hypre_assert( mtx != NULL ); - hypre_assert( 1 <= i && i <= mtx->height ); - hypre_assert( 1 <= j && j <= mtx->width ); + hypre_assert( 1 <= i && i <= mtx->height ); + hypre_assert( 1 <= j && j <= mtx->width ); - k = i - 1 + (j - 1)*mtx->globalHeight; - return mtx->value[k]; + k = i - 1 + (j - 1)*mtx->globalHeight; + return mtx->value[k]; } -HYPRE_Real* -utilities_FortranMatrixValuePtr( utilities_FortranMatrix* mtx, - hypre_longint i, hypre_longint j ) { +HYPRE_Real* +utilities_FortranMatrixValuePtr( utilities_FortranMatrix* mtx, + HYPRE_BigInt i, HYPRE_BigInt j ) { - hypre_longint k; + HYPRE_BigInt k; - hypre_assert( mtx != NULL ); + hypre_assert( mtx != NULL ); - hypre_assert( 1 <= i && i <= mtx->height ); - hypre_assert( 1 <= j && j <= mtx->width ); + hypre_assert( 1 <= i && i <= mtx->height ); + hypre_assert( 1 <= j && j <= mtx->width ); - k = i - 1 + (j - 1)*mtx->globalHeight; - return mtx->value + k; + k = i - 1 + (j - 1)*mtx->globalHeight; + return mtx->value + k; } -HYPRE_Real +HYPRE_Real utilities_FortranMatrixMaxValue( utilities_FortranMatrix* mtx ) { - hypre_longint i, j, jump; - hypre_longint h, w; - HYPRE_Real* p; - HYPRE_Real maxVal; + HYPRE_BigInt i, j, jump; + HYPRE_BigInt h, w; + HYPRE_Real* p; + HYPRE_Real maxVal; - hypre_assert( mtx != NULL ); + hypre_assert( mtx != NULL ); - h = mtx->height; - w = mtx->width; + h = mtx->height; + w = mtx->width; - jump = mtx->globalHeight - h; + jump = mtx->globalHeight - h; - maxVal = mtx->value[0]; + maxVal = mtx->value[0]; - for ( j = 0, p = mtx->value; j < w; j++ ) { - for ( i = 0; i < h; i++, p++ ) - if ( *p > maxVal ) - maxVal = *p; - p += jump; - } + for ( j = 0, p = mtx->value; j < w; j++ ) { + for ( i = 0; i < h; i++, p++ ) + if ( *p > maxVal ) + maxVal = *p; + p += jump; + } - return maxVal; + return maxVal; } -void +void utilities_FortranMatrixSelectBlock( utilities_FortranMatrix* mtx, - hypre_longint iFrom, hypre_longint iTo, - hypre_longint jFrom, hypre_longint jTo, - utilities_FortranMatrix* block ) { + HYPRE_BigInt iFrom, HYPRE_BigInt iTo, + HYPRE_BigInt jFrom, HYPRE_BigInt jTo, + utilities_FortranMatrix* block ) { - if ( block->value != NULL && block->ownsValues ) - free( block->value ); + if ( block->value != NULL && block->ownsValues ) + free( block->value ); - block->globalHeight = mtx->globalHeight; - if ( iTo < iFrom || jTo < jFrom ) { - block->height = 0; - block->width = 0; - block->value = NULL; - return; - } - block->height = iTo - iFrom + 1; - block->width = jTo - jFrom + 1; - block->value = mtx->value + iFrom - 1 + (jFrom - 1)*mtx->globalHeight; - block->ownsValues = 0; + block->globalHeight = mtx->globalHeight; + if ( iTo < iFrom || jTo < jFrom ) { + block->height = 0; + block->width = 0; + block->value = NULL; + return; + } + block->height = iTo - iFrom + 1; + block->width = jTo - jFrom + 1; + block->value = mtx->value + iFrom - 1 + (jFrom - 1)*mtx->globalHeight; + block->ownsValues = 0; } -void +void utilities_FortranMatrixUpperInv( utilities_FortranMatrix* u ) { - hypre_longint i, j, k; - hypre_longint n, jc, jd; - HYPRE_Real v; - HYPRE_Real* diag; /* diag(i) = u(i,i)_original */ - HYPRE_Real* pin; /* &u(i-1,n) */ - HYPRE_Real* pii; /* &u(i,i) */ - HYPRE_Real* pij; /* &u(i,j) */ - HYPRE_Real* pik; /* &u(i,k) */ - HYPRE_Real* pkj; /* &u(k,j) */ - HYPRE_Real* pd; /* &diag(i) */ + HYPRE_BigInt i, j, k; + HYPRE_BigInt n, jc, jd; + HYPRE_Real v; + HYPRE_Real* diag; /* diag(i) = u(i,i)_original */ + HYPRE_Real* pin; /* &u(i-1,n) */ + HYPRE_Real* pii; /* &u(i,i) */ + HYPRE_Real* pij; /* &u(i,j) */ + HYPRE_Real* pik; /* &u(i,k) */ + HYPRE_Real* pkj; /* &u(k,j) */ + HYPRE_Real* pd; /* &diag(i) */ - n = u->height; - hypre_assert( u->width == n ); + n = u->height; + hypre_assert( u->width == n ); - diag = hypre_CTAlloc(HYPRE_Real, n, HYPRE_MEMORY_HOST); - hypre_assert( diag != NULL ); + diag = hypre_CTAlloc(HYPRE_Real, n, HYPRE_MEMORY_HOST); + hypre_assert( diag != NULL ); - jc = u->globalHeight; - jd = jc + 1; + jc = u->globalHeight; + jd = jc + 1; - pii = u->value; - pd = diag; - for ( i = 0; i < n; i++, pii += jd, pd++ ) { - v = *pd = *pii; - *pii = 1.0/v; - } + pii = u->value; + pd = diag; + for ( i = 0; i < n; i++, pii += jd, pd++ ) { + v = *pd = *pii; + *pii = 1.0/v; + } - pii -= jd; - pin = pii - 1; - pii -= jd; - pd -= 2; - for ( i = n - 1; i > 0; i--, pii -= jd, pin--, pd-- ) { - pij = pin; - for ( j = n; j > i; j--, pij -= jc ) { - v = 0; - pik = pii + jc; - pkj = pij + 1; - for ( k = i + 1; k <= j; k++, pik += jc, pkj++ ) { - v -= (*pik) * (*pkj); + pii -= jd; + pin = pii - 1; + pii -= jd; + pd -= 2; + for ( i = n - 1; i > 0; i--, pii -= jd, pin--, pd-- ) { + pij = pin; + for ( j = n; j > i; j--, pij -= jc ) { + v = 0; + pik = pii + jc; + pkj = pij + 1; + for ( k = i + 1; k <= j; k++, pik += jc, pkj++ ) { + v -= (*pik) * (*pkj); + } + *pij = v/(*pd); } - *pij = v/(*pd); - } - } + } - free( diag ); + free( diag ); } HYPRE_Int utilities_FortranMatrixPrint( utilities_FortranMatrix* mtx, const char *fileName) { - hypre_longint i, j, h, w, jump; - HYPRE_Real* p; - FILE* fp; + HYPRE_BigInt i, j, h, w, jump; + HYPRE_Real* p; + FILE* fp; - hypre_assert( mtx != NULL ); + hypre_assert( mtx != NULL ); - if ( !(fp = fopen(fileName,"w")) ) - return 1; + if ( !(fp = fopen(fileName,"w")) ) + return 1; - h = mtx->height; - w = mtx->width; - - hypre_fprintf(fp,"%ld\n",h); - hypre_fprintf(fp,"%ld\n",w); - - jump = mtx->globalHeight - h; - - for ( j = 0, p = mtx->value; j < w; j++ ) { - for ( i = 0; i < h; i++, p++ ) - hypre_fprintf(fp,"%.14e\n",*p); - p += jump; - } + h = mtx->height; + w = mtx->width; - fclose(fp); - return 0; + hypre_fprintf(fp,"%ld\n",h); + hypre_fprintf(fp,"%ld\n",w); + + jump = mtx->globalHeight - h; + + for ( j = 0, p = mtx->value; j < w; j++ ) { + for ( i = 0; i < h; i++, p++ ) + hypre_fprintf(fp,"%.14e\n",*p); + p += jump; + } + + fclose(fp); + return 0; } diff --git a/src/utilities/fortran_matrix.h b/src/utilities/fortran_matrix.h index ddb957beb..2c6d1bc98 100644 --- a/src/utilities/fortran_matrix.h +++ b/src/utilities/fortran_matrix.h @@ -8,13 +8,13 @@ #ifndef FORTRAN_STYLE_MATRIX #define FORTRAN_STYLE_MATRIX -#include "_hypre_utilities.h" +#include "HYPRE_utilities.h" typedef struct { - hypre_longint globalHeight; - hypre_longint height; - hypre_longint width; + HYPRE_BigInt globalHeight; + HYPRE_BigInt height; + HYPRE_BigInt width; HYPRE_Real* value; HYPRE_Int ownsValues; } utilities_FortranMatrix; @@ -26,19 +26,19 @@ extern "C" { utilities_FortranMatrix* utilities_FortranMatrixCreate(void); void -utilities_FortranMatrixAllocateData( hypre_longint h, hypre_longint w, +utilities_FortranMatrixAllocateData( HYPRE_BigInt h, HYPRE_BigInt w, utilities_FortranMatrix* mtx ); void -utilities_FortranMatrixWrap( HYPRE_Real*, hypre_longint gh, hypre_longint h, hypre_longint w, +utilities_FortranMatrixWrap( HYPRE_Real*, HYPRE_BigInt gh, HYPRE_BigInt h, HYPRE_BigInt w, utilities_FortranMatrix* mtx ); void utilities_FortranMatrixDestroy( utilities_FortranMatrix* mtx ); -hypre_longint +HYPRE_BigInt utilities_FortranMatrixGlobalHeight( utilities_FortranMatrix* mtx ); -hypre_longint +HYPRE_BigInt utilities_FortranMatrixHeight( utilities_FortranMatrix* mtx ); -hypre_longint +HYPRE_BigInt utilities_FortranMatrixWidth( utilities_FortranMatrix* mtx ); HYPRE_Real* utilities_FortranMatrixValues( utilities_FortranMatrix* mtx ); @@ -89,17 +89,17 @@ utilities_FortranMatrixFNorm( utilities_FortranMatrix* mtx ); HYPRE_Real utilities_FortranMatrixValue( utilities_FortranMatrix* mtx, - hypre_longint i, hypre_longint j ); + HYPRE_BigInt i, HYPRE_BigInt j ); HYPRE_Real* utilities_FortranMatrixValuePtr( utilities_FortranMatrix* mtx, - hypre_longint i, hypre_longint j ); + HYPRE_BigInt i, HYPRE_BigInt j ); HYPRE_Real utilities_FortranMatrixMaxValue( utilities_FortranMatrix* mtx ); void utilities_FortranMatrixSelectBlock( utilities_FortranMatrix* mtx, - hypre_longint iFrom, hypre_longint iTo, - hypre_longint jFrom, hypre_longint jTo, + HYPRE_BigInt iFrom, HYPRE_BigInt iTo, + HYPRE_BigInt jFrom, HYPRE_BigInt jTo, utilities_FortranMatrix* block ); void utilities_FortranMatrixUpperInv( utilities_FortranMatrix* u );