Skip to content

Commit

Permalink
Merge pull request #61 from aoymt/fix_ilaenv
Browse files Browse the repository at this point in the history
fix call to lapack ilaenv
  • Loading branch information
k-ido authored Sep 15, 2024
2 parents 9bca448 + ef9d66b commit 89e25b6
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/gcc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ set(CMAKE_C_COMPILER "gcc" CACHE STRING "" FORCE)
set(CMAKE_CXX_COMPILER "g++" CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_DEBUG "-g -O0 -Wall -Wformat -Werror=format-security")
set(CMAKE_C_FLAGS_RELEASE "-O3 -Wno-unknown-pragmas ")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wno-unknown-pragmas ")
set(CMAKE_Fortran_COMPILER "gfortran" CACHE STRING "" FORCE)
2 changes: 1 addition & 1 deletion src/ltl2inv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ endif()
include_directories(../common)

# TODO: Move blalink_gemmt.c to other subprojects?
add_library(ltl2inv STATIC ltl2inv.cc blalink_gemmt.c ilaenv_lauum.cc)
add_library(ltl2inv STATIC ltl2inv.cc blalink_gemmt.c ilaenv_lauum.cc ilaenv_wrap.f90)
target_compile_definitions(ltl2inv PRIVATE -D_CC_IMPL)

3 changes: 3 additions & 0 deletions src/ltl2inv/ilaenv.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
extern "C" {
#endif

/*
int ilaenv_(const int *ispec, const char *name, const char *opts, const int *n1, const int *n2, const int *n3, const int *n4);
*/
int ilaenv_wrap(int ispec, const char *name, const char *opts, int n1, int n2, int n3, int n4);

#ifdef __cplusplus
}
Expand Down
29 changes: 29 additions & 0 deletions src/ltl2inv/ilaenv_lauum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
#include "ilaenv.h"
#include "ilaenv_lauum.hh"

/*
* sloppy version exploits that
* ILAENV(ispec=1, xLAUUM, "", dummy, dummy, dummy, dummy)
* returns 64 for x=S,D,C,Z .
*/

#undef SLOPPY_ILAENV
// #define SLOPPY_ILAENV

/*
#define EXPANDMAC(cctype, name) \
template <> int ilaenv_lauum<cctype>(uplo_t uplo, int n) \
{ \
Expand All @@ -15,6 +25,25 @@ template <> int ilaenv_lauum<cctype>(uplo_t uplo, int n) \
int dummy = 0; \
return ilaenv_(&ispec, #name, &uplo_, &n, &dummy, &dummy, &dummy); \
}
*/

#ifndef SLOPPY_ILAENV
#define EXPANDMAC(cctype, name) \
template <> int ilaenv_lauum<cctype>(uplo_t uplo, int n) \
{ \
char uplo_ = uplo2char(uplo); \
int ispec = 1; \
int dummy = -1; \
return ilaenv_wrap(ispec, #name, &uplo_, n, dummy, dummy, dummy); \
}
#else
#define EXPANDMAC(cctype, name) \
template <> int ilaenv_lauum<cctype>(uplo_t uplo, int n) \
{ \
return 64; \
}
#endif

EXPANDMAC( float, SLAUUM )
EXPANDMAC( double, DLAUUM )
EXPANDMAC( ccscmplx, CLAUUM )
Expand Down
37 changes: 37 additions & 0 deletions src/ltl2inv/ilaenv_wrap.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module wrapper
use, intrinsic :: iso_c_binding
implicit none
contains
function c_charptr_to_f_charptr(ccp) result(result)
type(c_ptr),intent(in),value :: ccp
character(:,c_char),pointer :: result
interface
function strlen(p) bind(c)
import c_ptr, c_size_t
type(c_ptr),value :: p
integer(c_size_t) strlen
end function strlen
end interface
result => convert_cptr(ccp,strlen(ccp))
contains
function convert_cptr(p, len)
type(c_ptr),intent(in) :: p
integer(c_size_t),intent(in) :: len
character(len, c_char),pointer :: convert_cptr
call c_f_pointer(p, convert_cptr)
end function convert_cptr
end function c_charptr_to_f_charptr

integer function ilaenv_wrap(ispec, name, opts, n1, n2, n3, n4) bind(c, name="ilaenv_wrap")
implicit none
integer,intent(in),value :: ispec, n1, n2, n3, n4
type(c_ptr),intent(in),value :: name, opts
character(:,c_char),pointer :: namef, optsf
integer ilaenv

namef => c_charptr_to_f_charptr(name)
optsf => c_charptr_to_f_charptr(opts)

ilaenv_wrap = ILAENV(ispec, namef, optsf, n1, n2, n3, n4)
end function ilaenv_wrap
end module wrapper

0 comments on commit 89e25b6

Please sign in to comment.