Skip to content

Commit 18b19d1

Browse files
authored
C_LAPACK: Fixes to make it compile with MSVC (#3605)
* Fix f2c-like support functions to compile with MSVC, and re-enable C_LAPACK for MSVC in CMAKE * Add MSVC&flang build to Azure CI in order to check C_LAPACK correctness
1 parent d09b9dd commit 18b19d1

File tree

2,101 files changed

+243742
-26229
lines changed

Some content is hidden

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

2,101 files changed

+243742
-26229
lines changed

azure-pipelines.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,26 @@ jobs:
119119
cmake --build . --config Release
120120
ctest
121121
122+
- job: Windows_cl_flang
123+
pool:
124+
vmImage: 'windows-2022'
125+
steps:
126+
- script: |
127+
set "PATH=C:\Miniconda\Scripts;C:\Miniconda\Library\bin;C:\Miniconda\Library\usr\bin;C:\Miniconda\condabin;%PATH%"
128+
set "LIB=C:\Miniconda\Library\lib;%LIB%"
129+
set "CPATH=C:\Miniconda\Library\include;%CPATH%"
130+
conda config --add channels conda-forge --force
131+
conda config --set auto_update_conda false
132+
conda install --yes --quiet ninja flang
133+
mkdir build
134+
cd build
135+
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
136+
cmake -G "Ninja" -DCMAKE_C_COMPILER=cl -DCMAKE_Fortran_COMPILER=flang -DC_LAPACK=1 -DCMAKE_MT=mt -DCMAKE_BUILD_TYPE=Release -DMSVC_STATIC_CRT=ON ..
137+
cmake --build . --config Release
138+
ctest
139+
140+
141+
122142
- job: OSX_OpenMP
123143
pool:
124144
vmImage: 'macOS-10.15'

cmake/f_check.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if(CMAKE_Fortran_COMPILER)
2727
else()
2828
set (NOFORTRAN 1)
2929
if (NOT NO_LAPACK)
30-
if (NOT MSVC)
30+
if (NOT XXXXX)
3131
message(STATUS "No Fortran compiler found, can build only BLAS and f2c-converted LAPACK")
3232
set(C_LAPACK 1)
3333
if (INTERFACE64)

cmake/system.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ if (NOT NOFORTRAN)
284284
# Fortran Compiler dependent settings
285285
include("${PROJECT_SOURCE_DIR}/cmake/fc.cmake")
286286
else ()
287-
if (NOT MSVC)
287+
if (NOT XXXX)
288288
set(C_LAPACK 1)
289289
if (INTERFACE64)
290290
set (CCOMMON_OPT "${CCOMMON_OPT} -DLAPACK_ILP64")

lapack-netlib/INSTALL/dlamch.c

Lines changed: 141 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
/* f2c.h -- Standard Fortran to C header file */
2-
3-
/** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed."
4-
5-
- From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */
6-
7-
#ifndef F2C_INCLUDE
8-
#define F2C_INCLUDE
9-
101
#include <math.h>
112
#include <stdlib.h>
123
#include <string.h>
@@ -19,18 +10,46 @@
1910
#undef I
2011
#endif
2112

22-
typedef int integer;
13+
#if defined(_WIN64)
14+
typedef long long BLASLONG;
15+
typedef unsigned long long BLASULONG;
16+
#else
17+
typedef long BLASLONG;
18+
typedef unsigned long BLASULONG;
19+
#endif
20+
21+
#ifdef LAPACK_ILP64
22+
typedef BLASLONG blasint;
23+
#if defined(_WIN64)
24+
#define blasabs(x) llabs(x)
25+
#else
26+
#define blasabs(x) labs(x)
27+
#endif
28+
#else
29+
typedef int blasint;
30+
#define blasabs(x) abs(x)
31+
#endif
32+
33+
typedef blasint integer;
34+
2335
typedef unsigned int uinteger;
2436
typedef char *address;
2537
typedef short int shortint;
2638
typedef float real;
2739
typedef double doublereal;
2840
typedef struct { real r, i; } complex;
2941
typedef struct { doublereal r, i; } doublecomplex;
42+
#ifdef _MSC_VER
43+
static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
44+
static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
45+
static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
46+
static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
47+
#else
3048
static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
3149
static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
3250
static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
3351
static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
52+
#endif
3453
#define pCf(z) (*_pCf(z))
3554
#define pCd(z) (*_pCd(z))
3655
typedef int logical;
@@ -170,8 +189,13 @@ typedef struct Namelist Namelist;
170189
#define abort_() { sig_die("Fortran abort routine called", 1); }
171190
#define c_abs(z) (cabsf(Cf(z)))
172191
#define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
192+
#ifdef _MSC_VER
193+
#define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
194+
#define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
195+
#else
173196
#define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
174197
#define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
198+
#endif
175199
#define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
176200
#define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
177201
#define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
@@ -183,13 +207,13 @@ typedef struct Namelist Namelist;
183207
#define d_atan(x) (atan(*(x)))
184208
#define d_atn2(x, y) (atan2(*(x),*(y)))
185209
#define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
186-
#define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
210+
#define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
187211
#define d_cos(x) (cos(*(x)))
188212
#define d_cosh(x) (cosh(*(x)))
189213
#define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
190214
#define d_exp(x) (exp(*(x)))
191215
#define d_imag(z) (cimag(Cd(z)))
192-
#define r_imag(z) (cimag(Cf(z)))
216+
#define r_imag(z) (cimagf(Cf(z)))
193217
#define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
194218
#define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
195219
#define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
@@ -228,11 +252,11 @@ static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
228252
#define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
229253
#define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
230254
#define myexit_() break;
231-
#define mycycle_() continue;
232-
#define myceiling_(w) ceil(w)
233-
#define myhuge_(w) HUGE_VAL
255+
#define mycycle() continue;
256+
#define myceiling(w) {ceil(w)}
257+
#define myhuge(w) {HUGE_VAL}
234258
//#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
235-
#define mymaxloc_(w,s,e,n) dmaxloc_(w,*(s),*(e),n)
259+
#define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
236260

237261
/* procedure parameter types for -A and -C++ */
238262

@@ -267,6 +291,21 @@ static double dpow_ui(double x, integer n) {
267291
}
268292
return pow;
269293
}
294+
#ifdef _MSC_VER
295+
static _Fcomplex cpow_ui(complex x, integer n) {
296+
complex pow={1.0,0.0}; unsigned long int u;
297+
if(n != 0) {
298+
if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
299+
for(u = n; ; ) {
300+
if(u & 01) pow.r *= x.r, pow.i *= x.i;
301+
if(u >>= 1) x.r *= x.r, x.i *= x.i;
302+
else break;
303+
}
304+
}
305+
_Fcomplex p={pow.r, pow.i};
306+
return p;
307+
}
308+
#else
270309
static _Complex float cpow_ui(_Complex float x, integer n) {
271310
_Complex float pow=1.0; unsigned long int u;
272311
if(n != 0) {
@@ -279,6 +318,22 @@ static _Complex float cpow_ui(_Complex float x, integer n) {
279318
}
280319
return pow;
281320
}
321+
#endif
322+
#ifdef _MSC_VER
323+
static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324+
_Dcomplex pow={1.0,0.0}; unsigned long int u;
325+
if(n != 0) {
326+
if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
327+
for(u = n; ; ) {
328+
if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
329+
if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
330+
else break;
331+
}
332+
}
333+
_Dcomplex p = {pow._Val[0], pow._Val[1]};
334+
return p;
335+
}
336+
#else
282337
static _Complex double zpow_ui(_Complex double x, integer n) {
283338
_Complex double pow=1.0; unsigned long int u;
284339
if(n != 0) {
@@ -291,6 +346,7 @@ static _Complex double zpow_ui(_Complex double x, integer n) {
291346
}
292347
return pow;
293348
}
349+
#endif
294350
static integer pow_ii(integer x, integer n) {
295351
integer pow; unsigned long int u;
296352
if (n <= 0) {
@@ -324,6 +380,22 @@ static integer smaxloc_(float *w, integer s, integer e, integer *n)
324380
}
325381
static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
326382
integer n = *n_, incx = *incx_, incy = *incy_, i;
383+
#ifdef _MSC_VER
384+
_Fcomplex zdotc = {0.0, 0.0};
385+
if (incx == 1 && incy == 1) {
386+
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
387+
zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
388+
zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
389+
}
390+
} else {
391+
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
392+
zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
393+
zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
394+
}
395+
}
396+
pCf(z) = zdotc;
397+
}
398+
#else
327399
_Complex float zdotc = 0.0;
328400
if (incx == 1 && incy == 1) {
329401
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
@@ -336,8 +408,25 @@ static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, c
336408
}
337409
pCf(z) = zdotc;
338410
}
411+
#endif
339412
static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
340413
integer n = *n_, incx = *incx_, incy = *incy_, i;
414+
#ifdef _MSC_VER
415+
_Dcomplex zdotc = {0.0, 0.0};
416+
if (incx == 1 && incy == 1) {
417+
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
418+
zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
419+
zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
420+
}
421+
} else {
422+
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
423+
zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
424+
zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
425+
}
426+
}
427+
pCd(z) = zdotc;
428+
}
429+
#else
341430
_Complex double zdotc = 0.0;
342431
if (incx == 1 && incy == 1) {
343432
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
@@ -349,9 +438,26 @@ static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integ
349438
}
350439
}
351440
pCd(z) = zdotc;
352-
}
441+
}
442+
#endif
353443
static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
354444
integer n = *n_, incx = *incx_, incy = *incy_, i;
445+
#ifdef _MSC_VER
446+
_Fcomplex zdotc = {0.0, 0.0};
447+
if (incx == 1 && incy == 1) {
448+
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
449+
zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
450+
zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
451+
}
452+
} else {
453+
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
454+
zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
455+
zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
456+
}
457+
}
458+
pCf(z) = zdotc;
459+
}
460+
#else
355461
_Complex float zdotc = 0.0;
356462
if (incx == 1 && incy == 1) {
357463
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
@@ -364,8 +470,25 @@ static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, c
364470
}
365471
pCf(z) = zdotc;
366472
}
473+
#endif
367474
static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
368475
integer n = *n_, incx = *incx_, incy = *incy_, i;
476+
#ifdef _MSC_VER
477+
_Dcomplex zdotc = {0.0, 0.0};
478+
if (incx == 1 && incy == 1) {
479+
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
480+
zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
481+
zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
482+
}
483+
} else {
484+
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
485+
zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
486+
zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
487+
}
488+
}
489+
pCd(z) = zdotc;
490+
}
491+
#else
369492
_Complex double zdotc = 0.0;
370493
if (incx == 1 && incy == 1) {
371494
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
@@ -386,6 +509,7 @@ static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integ
386509

387510

388511

512+
389513
/* Table of constant values */
390514

391515
static integer c__1 = 1;

0 commit comments

Comments
 (0)