Skip to content

Commit c6bc401

Browse files
authored
Merge pull request #888 from mkrainiuk/lapacke_64
Add Index-64 API as extended API with _64 suffix for LAPACKE
2 parents 50d6890 + bc5d836 commit c6bc401

File tree

4,171 files changed

+54928
-31468
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,171 files changed

+54928
-31468
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ else()
107107
set(LAPACKELIB "lapacke")
108108
set(TMGLIB "tmglib")
109109
endif()
110-
# By default build standard API and extended _64 API
110+
# By default build extended _64 API for supported compilers only
111+
set(INDEX64_EXT_API_COMPILERS "Intel|GNU")
111112
option(BUILD_INDEX64_EXT_API "Build Index-64 API as extended API with _64 suffix" ON)
113+
message(STATUS "Build Index-64 API as extended API with _64 suffix: ${BUILD_INDEX64_EXT_API}")
112114

113115
include(GNUInstallDirs)
114116

INSTALL/droundup_lwork.f

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ DOUBLE PRECISION FUNCTION DROUNDUP_LWORK( LWORK )
7676
*
7777
IF( INT( DROUNDUP_LWORK ) .LT. LWORK ) THEN
7878
* Force round up of LWORK
79-
DROUNDUP_LWORK = DROUNDUP_LWORK * ( 1.0D+0 + EPSILON(0.0D+0) )
79+
DROUNDUP_LWORK = DROUNDUP_LWORK *
80+
$ ( 1.0D+0 + EPSILON(0.0D+0) )
8081
ENDIF
8182
*
8283
RETURN

INSTALL/sroundup_lwork.f

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ REAL FUNCTION SROUNDUP_LWORK( LWORK )
7676
*
7777
IF( INT( SROUNDUP_LWORK ) .LT. LWORK ) THEN
7878
* Force round up of LWORK
79-
SROUNDUP_LWORK = SROUNDUP_LWORK * ( 1.0E+0 + EPSILON(0.0E+0) )
79+
SROUNDUP_LWORK = SROUNDUP_LWORK *
80+
$ ( 1.0E+0 + EPSILON(0.0E+0) )
8081
ENDIF
8182
*
8283
RETURN

LAPACKE/CMakeLists.txt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,35 @@ if(LAPACKE_WITH_TMG)
6767
endif()
6868
list(APPEND SOURCES ${UTILS})
6969

70-
add_library(${LAPACKELIB} ${SOURCES})
70+
add_library(${LAPACKELIB}_obj OBJECT ${SOURCES})
71+
set_target_properties(${LAPACKELIB}_obj PROPERTIES POSITION_INDEPENDENT_CODE ON)
72+
73+
if(BUILD_INDEX64_EXT_API)
74+
# 64bit Integer Extended Interface
75+
set(SOURCES_64_C)
76+
list(APPEND SOURCES_64_C ${SOURCES})
77+
list(REMOVE_ITEM SOURCES_64_C src/lapacke_nancheck.c)
78+
list(REMOVE_ITEM SOURCES_64_C utils/lapacke_make_complex_float.c)
79+
list(REMOVE_ITEM SOURCES_64_C utils/lapacke_make_complex_double.c)
80+
add_library(${LAPACKELIB}_64_obj OBJECT ${SOURCES_64_C})
81+
set_target_properties(${LAPACKELIB}_64_obj PROPERTIES
82+
POSITION_INDEPENDENT_CODE ON)
83+
target_compile_options(${LAPACKELIB}_64_obj PRIVATE
84+
-DLAPACK_ILP64
85+
-DLAPACKE_API64
86+
-DWeirdNEC
87+
-DCBLAS_API64)
88+
endif()
89+
90+
add_library(${LAPACKELIB} $<TARGET_OBJECTS:${LAPACKELIB}_obj>
91+
$<$<BOOL:${BUILD_INDEX64_EXT_API}>: $<TARGET_OBJECTS:${LAPACKELIB}_64_obj>>)
92+
7193
set_target_properties(
7294
${LAPACKELIB} PROPERTIES
7395
LINKER_LANGUAGE C
7496
VERSION ${LAPACK_VERSION}
7597
SOVERSION ${LAPACK_MAJOR_VERSION}
98+
POSITION_INDEPENDENT_CODE ON
7699
)
77100
target_include_directories(${LAPACKELIB} PUBLIC
78101
$<BUILD_INTERFACE:${LAPACK_BINARY_DIR}/include>

LAPACKE/example/CMakeLists.txt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,29 @@ add_executable(xexample_DGESV_colmajor example_DGESV_colmajor.c lapacke_example_
33
add_executable(xexample_DGELS_rowmajor example_DGELS_rowmajor.c lapacke_example_aux.c lapacke_example_aux.h)
44
add_executable(xexample_DGELS_colmajor example_DGELS_colmajor.c lapacke_example_aux.c lapacke_example_aux.h)
55

6-
target_link_libraries(xexample_DGESV_rowmajor ${LAPACKELIB})
7-
target_link_libraries(xexample_DGESV_colmajor ${LAPACKELIB})
8-
target_link_libraries(xexample_DGELS_rowmajor ${LAPACKELIB})
9-
target_link_libraries(xexample_DGELS_colmajor ${LAPACKELIB})
6+
target_link_libraries(xexample_DGESV_rowmajor ${LAPACKELIB} ${BLAS_LIBRARIES})
7+
target_link_libraries(xexample_DGESV_colmajor ${LAPACKELIB} ${BLAS_LIBRARIES})
8+
target_link_libraries(xexample_DGELS_rowmajor ${LAPACKELIB} ${BLAS_LIBRARIES})
9+
target_link_libraries(xexample_DGELS_colmajor ${LAPACKELIB} ${BLAS_LIBRARIES})
1010

1111
add_test(example_DGESV_rowmajor ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample_DGESV_rowmajor)
1212
add_test(example_DGESV_colmajor ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample_DGESV_colmajor)
1313
add_test(example_DGELS_rowmajor ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample_DGELS_rowmajor)
1414
add_test(example_DGELS_colmajor ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample_DGELS_colmajor)
15+
16+
if(BUILD_INDEX64_EXT_API)
17+
add_executable(xexample_DGESV_rowmajor_64 example_DGESV_rowmajor_64.c lapacke_example_aux.c lapacke_example_aux.h)
18+
add_executable(xexample_DGESV_colmajor_64 example_DGESV_colmajor_64.c lapacke_example_aux.c lapacke_example_aux.h)
19+
add_executable(xexample_DGELS_rowmajor_64 example_DGELS_rowmajor_64.c lapacke_example_aux.c lapacke_example_aux.h)
20+
add_executable(xexample_DGELS_colmajor_64 example_DGELS_colmajor_64.c lapacke_example_aux.c lapacke_example_aux.h)
21+
22+
target_link_libraries(xexample_DGESV_rowmajor_64 ${LAPACKELIB} ${BLAS_LIBRARIES})
23+
target_link_libraries(xexample_DGESV_colmajor_64 ${LAPACKELIB} ${BLAS_LIBRARIES})
24+
target_link_libraries(xexample_DGELS_rowmajor_64 ${LAPACKELIB} ${BLAS_LIBRARIES})
25+
target_link_libraries(xexample_DGELS_colmajor_64 ${LAPACKELIB} ${BLAS_LIBRARIES})
26+
27+
add_test(example_DGESV_rowmajor_64 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample_DGESV_rowmajor_64)
28+
add_test(example_DGESV_colmajor_64 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample_DGESV_colmajor_64)
29+
add_test(example_DGELS_rowmajor_64 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample_DGELS_rowmajor_64)
30+
add_test(example_DGELS_colmajor_64 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample_DGELS_colmajor_64)
31+
endif()
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
LAPACKE Example : Calling DGELS using col-major layout
3+
=====================================================
4+
5+
The program computes the solution to the system of linear
6+
equations with a square matrix A and multiple
7+
right-hand sides B, where A is the coefficient matrix
8+
and b is the right-hand side matrix:
9+
10+
Description
11+
===========
12+
13+
In this example, we wish solve the least squares problem min_x || B - Ax ||
14+
for two right-hand sides using the LAPACK routine DGELS. For input we will
15+
use the 5-by-3 matrix
16+
17+
( 1 1 1 )
18+
( 2 3 4 )
19+
A = ( 3 5 2 )
20+
( 4 2 5 )
21+
( 5 4 3 )
22+
and the 5-by-2 matrix
23+
24+
( -10 -3 )
25+
( 12 14 )
26+
B = ( 14 12 )
27+
( 16 16 )
28+
( 18 16 )
29+
We will first store the input matrix as a static C two-dimensional array,
30+
which is stored in col-major layout, and let LAPACKE handle the work space
31+
array allocation. The LAPACK base name for this function is gels, and we
32+
will use double precision (d), so the LAPACKE function name is LAPACKE_dgels.
33+
34+
lda=5 and ldb=5. The output for each right hand side is stored in b as
35+
consecutive vectors of length 3. The correct answer for this problem is
36+
the 3-by-2 matrix
37+
38+
( 2 1 )
39+
( 1 1 )
40+
( 1 2 )
41+
42+
A complete C program for this example is given below. Note that when the arrays
43+
are passed to the LAPACK routine, they must be dereferenced, since LAPACK is
44+
expecting arrays of type double *, not double **.
45+
46+
47+
LAPACKE Interface
48+
=================
49+
50+
LAPACKE_dgels (col-major, high-level) Example Program Results
51+
52+
-- LAPACKE Example routine --
53+
-- LAPACK is a software package provided by Univ. of Tennessee, --
54+
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
55+
*/
56+
/* Calling DGELS using col-major layout */
57+
58+
/* Includes */
59+
#include <stdio.h>
60+
#include <lapacke_64.h>
61+
#include "lapacke_example_aux.h"
62+
63+
/* Main program */
64+
int main (int argc, const char * argv[])
65+
{
66+
/* Locals */
67+
double A[5][3] = {{1,2,3},{4,5,1},{3,5,2},{4,1,4},{2,5,3}};
68+
double b[5][2] = {{-10,12},{14,16},{18,-3},{14,12},{16,16}};
69+
int64_t info,m,n,lda,ldb,nrhs;
70+
71+
/* Initialization */
72+
m = 5;
73+
n = 3;
74+
nrhs = 2;
75+
lda = 5;
76+
ldb = 5;
77+
78+
/* Print Entry Matrix */
79+
print_matrix_colmajor_64( "Entry Matrix A", m, n, *A, lda );
80+
/* Print Right Rand Side */
81+
print_matrix_colmajor_64( "Right Hand Side b", n, nrhs, *b, ldb );
82+
printf( "\n" );
83+
84+
/* Executable statements */
85+
printf( "LAPACKE_dgels_64 (col-major, high-level) Example Program Results\n" );
86+
/* Solve least squares problem*/
87+
info = LAPACKE_dgels_64(LAPACK_COL_MAJOR,'N',m,n,nrhs,*A,lda,*b,ldb);
88+
89+
/* Print Solution */
90+
print_matrix_colmajor_64( "Solution", n, nrhs, *b, ldb );
91+
printf( "\n" );
92+
exit( info );
93+
} /* End of LAPACKE_dgels Example */
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
LAPACKE Example : Calling DGELS using row-major layout
3+
=====================================================
4+
5+
The program computes the solution to the system of linear
6+
equations with a square matrix A and multiple
7+
right-hand sides B, where A is the coefficient matrix
8+
and b is the right-hand side matrix:
9+
10+
Description
11+
===========
12+
13+
In this example, we wish solve the least squares problem min_x || B - Ax ||
14+
for two right-hand sides using the LAPACK routine DGELS. For input we will
15+
use the 5-by-3 matrix
16+
17+
( 1 1 1 )
18+
( 2 3 4 )
19+
A = ( 3 5 2 )
20+
( 4 2 5 )
21+
( 5 4 3 )
22+
and the 5-by-2 matrix
23+
24+
( -10 -3 )
25+
( 12 14 )
26+
B = ( 14 12 )
27+
( 16 16 )
28+
( 18 16 )
29+
We will first store the input matrix as a static C two-dimensional array,
30+
which is stored in row-major layout, and let LAPACKE handle the work space
31+
array allocation. The LAPACK base name for this function is gels, and we
32+
will use double precision (d), so the LAPACKE function name is LAPACKE_dgels.
33+
34+
thus lda=3 and ldb=2. The output for each right hand side is stored in b as
35+
consecutive vectors of length 3. The correct answer for this problem is
36+
the 3-by-2 matrix
37+
38+
( 2 1 )
39+
( 1 1 )
40+
( 1 2 )
41+
42+
A complete C program for this example is given below. Note that when the arrays
43+
are passed to the LAPACK routine, they must be dereferenced, since LAPACK is
44+
expecting arrays of type double *, not double **.
45+
46+
47+
LAPACKE Interface
48+
=================
49+
50+
LAPACKE_dgels (row-major, high-level) Example Program Results
51+
52+
-- LAPACKE Example routine --
53+
-- LAPACK is a software package provided by Univ. of Tennessee, --
54+
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
55+
*/
56+
/* Calling DGELS using row-major layout */
57+
58+
/* Includes */
59+
#include <stdio.h>
60+
#include <lapacke_64.h>
61+
#include "lapacke_example_aux.h"
62+
63+
/* Main program */
64+
int main (int argc, const char * argv[])
65+
{
66+
/* Locals */
67+
double A[5][3] = {{1,1,1},{2,3,4},{3,5,2},{4,2,5},{5,4,3}};
68+
double b[5][2] = {{-10,-3},{12,14},{14,12},{16,16},{18,16}};
69+
int64_t info,m,n,lda,ldb,nrhs;
70+
71+
/* Initialization */
72+
m = 5;
73+
n = 3;
74+
nrhs = 2;
75+
lda = 3;
76+
ldb = 2;
77+
78+
/* Print Entry Matrix */
79+
print_matrix_rowmajor_64( "Entry Matrix A", m, n, *A, lda );
80+
/* Print Right Rand Side */
81+
print_matrix_rowmajor_64( "Right Hand Side b", n, nrhs, *b, ldb );
82+
printf( "\n" );
83+
84+
/* Executable statements */
85+
printf( "LAPACKE_dgels_64 (row-major, high-level) Example Program Results\n" );
86+
/* Solve least squares problem*/
87+
info = LAPACKE_dgels_64(LAPACK_ROW_MAJOR,'N',m,n,nrhs,*A,lda,*b,ldb);
88+
89+
/* Print Solution */
90+
print_matrix_rowmajor_64( "Solution", n, nrhs, *b, ldb );
91+
printf( "\n" );
92+
exit( 0 );
93+
} /* End of LAPACKE_dgels Example */

LAPACKE/example/example_DGESV_colmajor.c

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,41 +41,41 @@ int main(int argc, char **argv) {
4141

4242
/* Locals */
4343
lapack_int n, nrhs, lda, ldb, info;
44-
int i, j;
44+
int i, j;
4545
/* Local arrays */
46-
double *A, *b;
47-
lapack_int *ipiv;
46+
double *A, *b;
47+
lapack_int *ipiv;
4848

4949
/* Default Value */
50-
n = 5; nrhs = 1;
50+
n = 5; nrhs = 1;
5151

5252
/* Arguments */
53-
for( i = 1; i < argc; i++ ) {
54-
if( strcmp( argv[i], "-n" ) == 0 ) {
55-
n = atoi(argv[i+1]);
56-
i++;
57-
}
58-
if( strcmp( argv[i], "-nrhs" ) == 0 ) {
59-
nrhs = atoi(argv[i+1]);
60-
i++;
61-
}
62-
}
53+
for( i = 1; i < argc; i++ ) {
54+
if( strcmp( argv[i], "-n" ) == 0 ) {
55+
n = atoi(argv[i+1]);
56+
i++;
57+
}
58+
if( strcmp( argv[i], "-nrhs" ) == 0 ) {
59+
nrhs = atoi(argv[i+1]);
60+
i++;
61+
}
62+
}
6363

6464
/* Initialization */
6565
lda=n, ldb=n;
66-
A = (double *)malloc(n*n*sizeof(double)) ;
67-
if (A==NULL){ printf("error of memory allocation\n"); exit(0); }
68-
b = (double *)malloc(n*nrhs*sizeof(double)) ;
69-
if (b==NULL){ printf("error of memory allocation\n"); exit(0); }
70-
ipiv = (lapack_int *)malloc(n*sizeof(lapack_int)) ;
71-
if (ipiv==NULL){ printf("error of memory allocation\n"); exit(0); }
66+
A = (double *)malloc(n*n*sizeof(double)) ;
67+
if (A==NULL){ printf("error of memory allocation\n"); exit(0); }
68+
b = (double *)malloc(n*nrhs*sizeof(double)) ;
69+
if (b==NULL){ printf("error of memory allocation\n"); free(A); exit(0); }
70+
ipiv = (lapack_int *)malloc(n*sizeof(lapack_int)) ;
71+
if (ipiv==NULL){ printf("error of memory allocation\n"); free(A); free(b); exit(0); }
7272

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

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

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

9292
/* Check for the exact singularity */
9393
if( info > 0 ) {
94-
printf( "The diagonal element of the triangular factor of A,\n" );
95-
printf( "U(%" LAPACK_IFMT ",%" LAPACK_IFMT ") is zero, so that A is singular;\n", info, info );
96-
printf( "the solution could not be computed.\n" );
97-
exit( 1 );
94+
printf( "The diagonal element of the triangular factor of A,\n" );
95+
printf( "U(%" LAPACK_IFMT ",%" LAPACK_IFMT ") is zero, so that A is singular;\n", info, info );
96+
printf( "the solution could not be computed.\n" );
97+
free(A);
98+
free(b);
99+
free(ipiv);
100+
exit( 1 );
101+
}
102+
if (info <0) {
103+
free(A);
104+
free(b);
105+
free(ipiv);
106+
exit( 1 );
98107
}
99-
if (info <0) exit( 1 );
100108
/* Print solution */
101109
print_matrix_colmajor( "Solution", n, nrhs, b, ldb );
102110
/* Print details of LU factorization */

0 commit comments

Comments
 (0)