Skip to content

Commit

Permalink
Merge pull request Reference-LAPACK#888 from mkrainiuk/lapacke_64
Browse files Browse the repository at this point in the history
Add Index-64 API as extended API with _64 suffix for LAPACKE
  • Loading branch information
langou authored Feb 10, 2024
2 parents 50d6890 + bc5d836 commit c6bc401
Show file tree
Hide file tree
Showing 4,171 changed files with 54,928 additions and 31,468 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ else()
set(LAPACKELIB "lapacke")
set(TMGLIB "tmglib")
endif()
# By default build standard API and extended _64 API
# By default build extended _64 API for supported compilers only
set(INDEX64_EXT_API_COMPILERS "Intel|GNU")
option(BUILD_INDEX64_EXT_API "Build Index-64 API as extended API with _64 suffix" ON)
message(STATUS "Build Index-64 API as extended API with _64 suffix: ${BUILD_INDEX64_EXT_API}")

include(GNUInstallDirs)

Expand Down
3 changes: 2 additions & 1 deletion INSTALL/droundup_lwork.f
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ DOUBLE PRECISION FUNCTION DROUNDUP_LWORK( LWORK )
*
IF( INT( DROUNDUP_LWORK ) .LT. LWORK ) THEN
* Force round up of LWORK
DROUNDUP_LWORK = DROUNDUP_LWORK * ( 1.0D+0 + EPSILON(0.0D+0) )
DROUNDUP_LWORK = DROUNDUP_LWORK *
$ ( 1.0D+0 + EPSILON(0.0D+0) )
ENDIF
*
RETURN
Expand Down
3 changes: 2 additions & 1 deletion INSTALL/sroundup_lwork.f
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ REAL FUNCTION SROUNDUP_LWORK( LWORK )
*
IF( INT( SROUNDUP_LWORK ) .LT. LWORK ) THEN
* Force round up of LWORK
SROUNDUP_LWORK = SROUNDUP_LWORK * ( 1.0E+0 + EPSILON(0.0E+0) )
SROUNDUP_LWORK = SROUNDUP_LWORK *
$ ( 1.0E+0 + EPSILON(0.0E+0) )
ENDIF
*
RETURN
Expand Down
25 changes: 24 additions & 1 deletion LAPACKE/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,35 @@ if(LAPACKE_WITH_TMG)
endif()
list(APPEND SOURCES ${UTILS})

add_library(${LAPACKELIB} ${SOURCES})
add_library(${LAPACKELIB}_obj OBJECT ${SOURCES})
set_target_properties(${LAPACKELIB}_obj PROPERTIES POSITION_INDEPENDENT_CODE ON)

if(BUILD_INDEX64_EXT_API)
# 64bit Integer Extended Interface
set(SOURCES_64_C)
list(APPEND SOURCES_64_C ${SOURCES})
list(REMOVE_ITEM SOURCES_64_C src/lapacke_nancheck.c)
list(REMOVE_ITEM SOURCES_64_C utils/lapacke_make_complex_float.c)
list(REMOVE_ITEM SOURCES_64_C utils/lapacke_make_complex_double.c)
add_library(${LAPACKELIB}_64_obj OBJECT ${SOURCES_64_C})
set_target_properties(${LAPACKELIB}_64_obj PROPERTIES
POSITION_INDEPENDENT_CODE ON)
target_compile_options(${LAPACKELIB}_64_obj PRIVATE
-DLAPACK_ILP64
-DLAPACKE_API64
-DWeirdNEC
-DCBLAS_API64)
endif()

add_library(${LAPACKELIB} $<TARGET_OBJECTS:${LAPACKELIB}_obj>
$<$<BOOL:${BUILD_INDEX64_EXT_API}>: $<TARGET_OBJECTS:${LAPACKELIB}_64_obj>>)

set_target_properties(
${LAPACKELIB} PROPERTIES
LINKER_LANGUAGE C
VERSION ${LAPACK_VERSION}
SOVERSION ${LAPACK_MAJOR_VERSION}
POSITION_INDEPENDENT_CODE ON
)
target_include_directories(${LAPACKELIB} PUBLIC
$<BUILD_INTERFACE:${LAPACK_BINARY_DIR}/include>
Expand Down
25 changes: 21 additions & 4 deletions LAPACKE/example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,29 @@ add_executable(xexample_DGESV_colmajor example_DGESV_colmajor.c lapacke_example_
add_executable(xexample_DGELS_rowmajor example_DGELS_rowmajor.c lapacke_example_aux.c lapacke_example_aux.h)
add_executable(xexample_DGELS_colmajor example_DGELS_colmajor.c lapacke_example_aux.c lapacke_example_aux.h)

target_link_libraries(xexample_DGESV_rowmajor ${LAPACKELIB})
target_link_libraries(xexample_DGESV_colmajor ${LAPACKELIB})
target_link_libraries(xexample_DGELS_rowmajor ${LAPACKELIB})
target_link_libraries(xexample_DGELS_colmajor ${LAPACKELIB})
target_link_libraries(xexample_DGESV_rowmajor ${LAPACKELIB} ${BLAS_LIBRARIES})
target_link_libraries(xexample_DGESV_colmajor ${LAPACKELIB} ${BLAS_LIBRARIES})
target_link_libraries(xexample_DGELS_rowmajor ${LAPACKELIB} ${BLAS_LIBRARIES})
target_link_libraries(xexample_DGELS_colmajor ${LAPACKELIB} ${BLAS_LIBRARIES})

add_test(example_DGESV_rowmajor ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample_DGESV_rowmajor)
add_test(example_DGESV_colmajor ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample_DGESV_colmajor)
add_test(example_DGELS_rowmajor ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample_DGELS_rowmajor)
add_test(example_DGELS_colmajor ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample_DGELS_colmajor)

if(BUILD_INDEX64_EXT_API)
add_executable(xexample_DGESV_rowmajor_64 example_DGESV_rowmajor_64.c lapacke_example_aux.c lapacke_example_aux.h)
add_executable(xexample_DGESV_colmajor_64 example_DGESV_colmajor_64.c lapacke_example_aux.c lapacke_example_aux.h)
add_executable(xexample_DGELS_rowmajor_64 example_DGELS_rowmajor_64.c lapacke_example_aux.c lapacke_example_aux.h)
add_executable(xexample_DGELS_colmajor_64 example_DGELS_colmajor_64.c lapacke_example_aux.c lapacke_example_aux.h)

target_link_libraries(xexample_DGESV_rowmajor_64 ${LAPACKELIB} ${BLAS_LIBRARIES})
target_link_libraries(xexample_DGESV_colmajor_64 ${LAPACKELIB} ${BLAS_LIBRARIES})
target_link_libraries(xexample_DGELS_rowmajor_64 ${LAPACKELIB} ${BLAS_LIBRARIES})
target_link_libraries(xexample_DGELS_colmajor_64 ${LAPACKELIB} ${BLAS_LIBRARIES})

add_test(example_DGESV_rowmajor_64 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample_DGESV_rowmajor_64)
add_test(example_DGESV_colmajor_64 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample_DGESV_colmajor_64)
add_test(example_DGELS_rowmajor_64 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample_DGELS_rowmajor_64)
add_test(example_DGELS_colmajor_64 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample_DGELS_colmajor_64)
endif()
93 changes: 93 additions & 0 deletions LAPACKE/example/example_DGELS_colmajor_64.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
LAPACKE Example : Calling DGELS using col-major layout
=====================================================
The program computes the solution to the system of linear
equations with a square matrix A and multiple
right-hand sides B, where A is the coefficient matrix
and b is the right-hand side matrix:
Description
===========
In this example, we wish solve the least squares problem min_x || B - Ax ||
for two right-hand sides using the LAPACK routine DGELS. For input we will
use the 5-by-3 matrix
( 1 1 1 )
( 2 3 4 )
A = ( 3 5 2 )
( 4 2 5 )
( 5 4 3 )
and the 5-by-2 matrix
( -10 -3 )
( 12 14 )
B = ( 14 12 )
( 16 16 )
( 18 16 )
We will first store the input matrix as a static C two-dimensional array,
which is stored in col-major layout, and let LAPACKE handle the work space
array allocation. The LAPACK base name for this function is gels, and we
will use double precision (d), so the LAPACKE function name is LAPACKE_dgels.
lda=5 and ldb=5. The output for each right hand side is stored in b as
consecutive vectors of length 3. The correct answer for this problem is
the 3-by-2 matrix
( 2 1 )
( 1 1 )
( 1 2 )
A complete C program for this example is given below. Note that when the arrays
are passed to the LAPACK routine, they must be dereferenced, since LAPACK is
expecting arrays of type double *, not double **.
LAPACKE Interface
=================
LAPACKE_dgels (col-major, high-level) Example Program Results
-- LAPACKE Example routine --
-- LAPACK is a software package provided by Univ. of Tennessee, --
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
*/
/* Calling DGELS using col-major layout */

/* Includes */
#include <stdio.h>
#include <lapacke_64.h>
#include "lapacke_example_aux.h"

/* Main program */
int main (int argc, const char * argv[])
{
/* Locals */
double A[5][3] = {{1,2,3},{4,5,1},{3,5,2},{4,1,4},{2,5,3}};
double b[5][2] = {{-10,12},{14,16},{18,-3},{14,12},{16,16}};
int64_t info,m,n,lda,ldb,nrhs;

/* Initialization */
m = 5;
n = 3;
nrhs = 2;
lda = 5;
ldb = 5;

/* Print Entry Matrix */
print_matrix_colmajor_64( "Entry Matrix A", m, n, *A, lda );
/* Print Right Rand Side */
print_matrix_colmajor_64( "Right Hand Side b", n, nrhs, *b, ldb );
printf( "\n" );

/* Executable statements */
printf( "LAPACKE_dgels_64 (col-major, high-level) Example Program Results\n" );
/* Solve least squares problem*/
info = LAPACKE_dgels_64(LAPACK_COL_MAJOR,'N',m,n,nrhs,*A,lda,*b,ldb);

/* Print Solution */
print_matrix_colmajor_64( "Solution", n, nrhs, *b, ldb );
printf( "\n" );
exit( info );
} /* End of LAPACKE_dgels Example */
93 changes: 93 additions & 0 deletions LAPACKE/example/example_DGELS_rowmajor_64.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
LAPACKE Example : Calling DGELS using row-major layout
=====================================================
The program computes the solution to the system of linear
equations with a square matrix A and multiple
right-hand sides B, where A is the coefficient matrix
and b is the right-hand side matrix:
Description
===========
In this example, we wish solve the least squares problem min_x || B - Ax ||
for two right-hand sides using the LAPACK routine DGELS. For input we will
use the 5-by-3 matrix
( 1 1 1 )
( 2 3 4 )
A = ( 3 5 2 )
( 4 2 5 )
( 5 4 3 )
and the 5-by-2 matrix
( -10 -3 )
( 12 14 )
B = ( 14 12 )
( 16 16 )
( 18 16 )
We will first store the input matrix as a static C two-dimensional array,
which is stored in row-major layout, and let LAPACKE handle the work space
array allocation. The LAPACK base name for this function is gels, and we
will use double precision (d), so the LAPACKE function name is LAPACKE_dgels.
thus lda=3 and ldb=2. The output for each right hand side is stored in b as
consecutive vectors of length 3. The correct answer for this problem is
the 3-by-2 matrix
( 2 1 )
( 1 1 )
( 1 2 )
A complete C program for this example is given below. Note that when the arrays
are passed to the LAPACK routine, they must be dereferenced, since LAPACK is
expecting arrays of type double *, not double **.
LAPACKE Interface
=================
LAPACKE_dgels (row-major, high-level) Example Program Results
-- LAPACKE Example routine --
-- LAPACK is a software package provided by Univ. of Tennessee, --
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
*/
/* Calling DGELS using row-major layout */

/* Includes */
#include <stdio.h>
#include <lapacke_64.h>
#include "lapacke_example_aux.h"

/* Main program */
int main (int argc, const char * argv[])
{
/* Locals */
double A[5][3] = {{1,1,1},{2,3,4},{3,5,2},{4,2,5},{5,4,3}};
double b[5][2] = {{-10,-3},{12,14},{14,12},{16,16},{18,16}};
int64_t info,m,n,lda,ldb,nrhs;

/* Initialization */
m = 5;
n = 3;
nrhs = 2;
lda = 3;
ldb = 2;

/* Print Entry Matrix */
print_matrix_rowmajor_64( "Entry Matrix A", m, n, *A, lda );
/* Print Right Rand Side */
print_matrix_rowmajor_64( "Right Hand Side b", n, nrhs, *b, ldb );
printf( "\n" );

/* Executable statements */
printf( "LAPACKE_dgels_64 (row-major, high-level) Example Program Results\n" );
/* Solve least squares problem*/
info = LAPACKE_dgels_64(LAPACK_ROW_MAJOR,'N',m,n,nrhs,*A,lda,*b,ldb);

/* Print Solution */
print_matrix_rowmajor_64( "Solution", n, nrhs, *b, ldb );
printf( "\n" );
exit( 0 );
} /* End of LAPACKE_dgels Example */
64 changes: 36 additions & 28 deletions LAPACKE/example/example_DGESV_colmajor.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,41 +41,41 @@ int main(int argc, char **argv) {

/* Locals */
lapack_int n, nrhs, lda, ldb, info;
int i, j;
int i, j;
/* Local arrays */
double *A, *b;
lapack_int *ipiv;
double *A, *b;
lapack_int *ipiv;

/* Default Value */
n = 5; nrhs = 1;
n = 5; nrhs = 1;

/* Arguments */
for( i = 1; i < argc; i++ ) {
if( strcmp( argv[i], "-n" ) == 0 ) {
n = atoi(argv[i+1]);
i++;
}
if( strcmp( argv[i], "-nrhs" ) == 0 ) {
nrhs = atoi(argv[i+1]);
i++;
}
}
for( i = 1; i < argc; i++ ) {
if( strcmp( argv[i], "-n" ) == 0 ) {
n = atoi(argv[i+1]);
i++;
}
if( strcmp( argv[i], "-nrhs" ) == 0 ) {
nrhs = atoi(argv[i+1]);
i++;
}
}

/* Initialization */
lda=n, ldb=n;
A = (double *)malloc(n*n*sizeof(double)) ;
if (A==NULL){ printf("error of memory allocation\n"); exit(0); }
b = (double *)malloc(n*nrhs*sizeof(double)) ;
if (b==NULL){ printf("error of memory allocation\n"); exit(0); }
ipiv = (lapack_int *)malloc(n*sizeof(lapack_int)) ;
if (ipiv==NULL){ printf("error of memory allocation\n"); exit(0); }
A = (double *)malloc(n*n*sizeof(double)) ;
if (A==NULL){ printf("error of memory allocation\n"); exit(0); }
b = (double *)malloc(n*nrhs*sizeof(double)) ;
if (b==NULL){ printf("error of memory allocation\n"); free(A); exit(0); }
ipiv = (lapack_int *)malloc(n*sizeof(lapack_int)) ;
if (ipiv==NULL){ printf("error of memory allocation\n"); free(A); free(b); exit(0); }

for( i = 0; i < n; i++ ) {
for( j = 0; j < n; j++ ) A[i+j*lda] = ((double) rand()) / ((double) RAND_MAX) - 0.5;
}
}

for(i=0;i<n*nrhs;i++)
b[i] = ((double) rand()) / ((double) RAND_MAX) - 0.5;
for(i=0;i<n*nrhs;i++)
b[i] = ((double) rand()) / ((double) RAND_MAX) - 0.5;

/* Print Entry Matrix */
print_matrix_colmajor( "Entry Matrix A", n, n, A, lda );
Expand All @@ -91,12 +91,20 @@ int main(int argc, char **argv) {

/* Check for the exact singularity */
if( info > 0 ) {
printf( "The diagonal element of the triangular factor of A,\n" );
printf( "U(%" LAPACK_IFMT ",%" LAPACK_IFMT ") is zero, so that A is singular;\n", info, info );
printf( "the solution could not be computed.\n" );
exit( 1 );
printf( "The diagonal element of the triangular factor of A,\n" );
printf( "U(%" LAPACK_IFMT ",%" LAPACK_IFMT ") is zero, so that A is singular;\n", info, info );
printf( "the solution could not be computed.\n" );
free(A);
free(b);
free(ipiv);
exit( 1 );
}
if (info <0) {
free(A);
free(b);
free(ipiv);
exit( 1 );
}
if (info <0) exit( 1 );
/* Print solution */
print_matrix_colmajor( "Solution", n, nrhs, b, ldb );
/* Print details of LU factorization */
Expand Down
Loading

0 comments on commit c6bc401

Please sign in to comment.