| 1377 |
slepc |
1 |
#
|
|
|
2 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 1672 |
slepc |
3 |
# SLEPc - Scalable Library for Eigenvalue Problem Computations
|
| 2575 |
eromero |
4 |
# Copyright (c) 2002-2011, Universitat Politecnica de Valencia, Spain
|
| 1377 |
slepc |
5 |
#
|
| 1672 |
slepc |
6 |
# This file is part of SLEPc.
|
|
|
7 |
#
|
|
|
8 |
# SLEPc is free software: you can redistribute it and/or modify it under the
|
|
|
9 |
# terms of version 3 of the GNU Lesser General Public License as published by
|
|
|
10 |
# the Free Software Foundation.
|
|
|
11 |
#
|
|
|
12 |
# SLEPc is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
13 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
14 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
|
|
|
15 |
# more details.
|
|
|
16 |
#
|
|
|
17 |
# You should have received a copy of the GNU Lesser General Public License
|
|
|
18 |
# along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
|
| 1377 |
slepc |
19 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
20 |
#
|
|
|
21 |
|
| 808 |
dsic.upv.es!antodo |
22 |
import os
|
|
|
23 |
import sys
|
| 912 |
dsic.upv.es!antodo |
24 |
import commands
|
| 808 |
dsic.upv.es!antodo |
25 |
|
| 912 |
dsic.upv.es!antodo |
26 |
import petscconf
|
| 923 |
dsic.upv.es!antodo |
27 |
import log
|
| 1071 |
slepc |
28 |
|
| 2478 |
jroman |
29 |
def LinkWithOutput(tmpdir,functions,callbacks,flags):
|
| 1100 |
slepc |
30 |
code = '#include "petscksp.h"\n'
|
| 1072 |
slepc |
31 |
code += 'EXTERN_C_BEGIN\n'
|
| 860 |
dsic.upv.es!antodo |
32 |
for f in functions:
|
| 2240 |
jroman |
33 |
code += 'extern int\n' + f + '();\n'
|
| 1072 |
slepc |
34 |
code += 'EXTERN_C_END\n'
|
| 860 |
dsic.upv.es!antodo |
35 |
|
| 808 |
dsic.upv.es!antodo |
36 |
for c in callbacks:
|
| 1072 |
slepc |
37 |
code += 'int '+ c + '() { return 0; } \n'
|
| 860 |
dsic.upv.es!antodo |
38 |
|
| 1072 |
slepc |
39 |
code += 'int main() {\n'
|
| 1093 |
slepc |
40 |
code += 'PetscInitialize(PETSC_NULL,PETSC_NULL,PETSC_NULL,PETSC_NULL);\n'
|
| 1097 |
slepc |
41 |
code += 'VecCreate(PETSC_NULL,PETSC_NULL);\n'
|
|
|
42 |
code += 'MatCreate(PETSC_NULL,PETSC_NULL);\n'
|
|
|
43 |
code += 'KSPCreate(PETSC_NULL,PETSC_NULL);\n'
|
| 808 |
dsic.upv.es!antodo |
44 |
for f in functions:
|
| 1072 |
slepc |
45 |
code += f + '();\n'
|
|
|
46 |
code += 'return 0;\n}\n'
|
|
|
47 |
|
| 2478 |
jroman |
48 |
cfile = open(os.sep.join([tmpdir,'checklink.c']),'w')
|
| 1072 |
slepc |
49 |
cfile.write(code)
|
| 808 |
dsic.upv.es!antodo |
50 |
cfile.close()
|
| 2478 |
jroman |
51 |
(result, output) = commands.getstatusoutput(petscconf.MAKE + ' -C ' + tmpdir + ' checklink TESTFLAGS="'+str.join(' ',flags)+'"')
|
| 2679 |
jroman |
52 |
try: os.remove('checklink.c')
|
|
|
53 |
except OSError: pass
|
| 808 |
dsic.upv.es!antodo |
54 |
if result:
|
| 1072 |
slepc |
55 |
return (0,code + output)
|
| 1071 |
slepc |
56 |
else:
|
| 1072 |
slepc |
57 |
return (1,code + output)
|
| 1071 |
slepc |
58 |
|
| 2478 |
jroman |
59 |
def Link(tmpdir,functions,callbacks,flags):
|
|
|
60 |
(result, output) = LinkWithOutput(tmpdir,functions,callbacks,flags)
|
| 2257 |
jroman |
61 |
log.write(output)
|
| 1071 |
slepc |
62 |
return result
|
| 808 |
dsic.upv.es!antodo |
63 |
|
| 2478 |
jroman |
64 |
def FortranLink(tmpdir,functions,callbacks,flags):
|
| 1072 |
slepc |
65 |
output = '\n=== With linker flags: '+str.join(' ',flags)
|
| 1071 |
slepc |
66 |
|
| 808 |
dsic.upv.es!antodo |
67 |
f = []
|
|
|
68 |
for i in functions:
|
|
|
69 |
f.append(i+'_')
|
|
|
70 |
c = []
|
|
|
71 |
for i in callbacks:
|
| 1071 |
slepc |
72 |
c.append(i+'_')
|
| 2478 |
jroman |
73 |
(result, output1) = LinkWithOutput(tmpdir,f,c,flags)
|
| 1072 |
slepc |
74 |
output1 = '\n====== With underscore Fortran names\n' + output1
|
|
|
75 |
if result: return ('UNDERSCORE',output1)
|
| 1071 |
slepc |
76 |
|
| 808 |
dsic.upv.es!antodo |
77 |
f = []
|
|
|
78 |
for i in functions:
|
|
|
79 |
f.append(i.upper())
|
|
|
80 |
c = []
|
|
|
81 |
for i in callbacks:
|
|
|
82 |
c.append(i.upper())
|
| 2478 |
jroman |
83 |
(result, output2) = LinkWithOutput(tmpdir,f,c,flags)
|
| 1072 |
slepc |
84 |
output2 = '\n====== With capital Fortran names\n' + output2
|
|
|
85 |
if result: return ('CAPS',output2)
|
| 808 |
dsic.upv.es!antodo |
86 |
|
| 2478 |
jroman |
87 |
(result, output3) = LinkWithOutput(tmpdir,functions,callbacks,flags)
|
| 1072 |
slepc |
88 |
output3 = '\n====== With unmodified Fortran names\n' + output3
|
|
|
89 |
if result: return ('STDCALL',output3)
|
| 1071 |
slepc |
90 |
|
| 1072 |
slepc |
91 |
return ('',output + output1 + output2 + output3)
|
| 1071 |
slepc |
92 |
|
| 912 |
dsic.upv.es!antodo |
93 |
def GenerateGuesses(name):
|
| 808 |
dsic.upv.es!antodo |
94 |
installdirs = ['/usr/local','/opt']
|
|
|
95 |
if 'HOME' in os.environ:
|
|
|
96 |
installdirs.insert(0,os.environ['HOME'])
|
|
|
97 |
|
|
|
98 |
dirs = []
|
|
|
99 |
for i in installdirs:
|
|
|
100 |
dirs = dirs + [i + '/lib']
|
|
|
101 |
for d in [name,name.upper(),name.lower()]:
|
|
|
102 |
dirs = dirs + [i + '/' + d]
|
|
|
103 |
dirs = dirs + [i + '/' + d + '/lib']
|
|
|
104 |
dirs = dirs + [i + '/lib/' + d]
|
|
|
105 |
|
| 860 |
dsic.upv.es!antodo |
106 |
for d in dirs[:]:
|
| 808 |
dsic.upv.es!antodo |
107 |
if not os.path.exists(d):
|
|
|
108 |
dirs.remove(d)
|
|
|
109 |
dirs = [''] + dirs
|
|
|
110 |
return dirs
|
|
|
111 |
|
| 2480 |
jroman |
112 |
def FortranLib(tmpdir,conf,vars,cmake,name,dirs,libs,functions,callbacks = []):
|
| 2257 |
jroman |
113 |
log.write('='*80)
|
| 923 |
dsic.upv.es!antodo |
114 |
log.Println('Checking '+name+' library...')
|
| 912 |
dsic.upv.es!antodo |
115 |
|
| 1071 |
slepc |
116 |
error = ''
|
|
|
117 |
mangling = ''
|
| 808 |
dsic.upv.es!antodo |
118 |
for d in dirs:
|
|
|
119 |
for l in libs:
|
|
|
120 |
if d:
|
|
|
121 |
flags = ['-L' + d] + l
|
|
|
122 |
else:
|
|
|
123 |
flags = l
|
| 2478 |
jroman |
124 |
(mangling, output) = FortranLink(tmpdir,functions,callbacks,flags)
|
| 1071 |
slepc |
125 |
error += output
|
| 808 |
dsic.upv.es!antodo |
126 |
if mangling: break
|
|
|
127 |
if mangling: break
|
|
|
128 |
|
| 1072 |
slepc |
129 |
if mangling:
|
| 2257 |
jroman |
130 |
log.write(output)
|
| 1072 |
slepc |
131 |
else:
|
| 2257 |
jroman |
132 |
log.write(error)
|
| 1105 |
slepc |
133 |
log.Println('ERROR: Unable to link with library '+ name)
|
| 2250 |
jroman |
134 |
log.Println('ERROR: In directories '+''.join([s+' ' for s in dirs]))
|
| 2706 |
jroman |
135 |
log.Println('ERROR: With flags '+''.join([s+' ' for s in flags]))
|
| 1105 |
slepc |
136 |
log.Exit('')
|
| 912 |
dsic.upv.es!antodo |
137 |
|
| 808 |
dsic.upv.es!antodo |
138 |
|
| 2265 |
jroman |
139 |
conf.write('#ifndef SLEPC_HAVE_' + name + '\n#define SLEPC_HAVE_' + name + ' 1\n#define SLEPC_' + name + '_HAVE_'+mangling+' 1\n#endif\n\n')
|
|
|
140 |
vars.write(name + '_LIB = '+str.join(' ',flags)+'\n')
|
| 2250 |
jroman |
141 |
cmake.write('set (SLEPC_HAVE_' + name + ' YES)\n')
|
|
|
142 |
libname = ''.join([s.lstrip('-l')+' ' for s in l])
|
| 2753 |
jroman |
143 |
cmake.write('set (' + name + '_LIB "")\nforeach (libname ' + libname + ')\n string (TOUPPER ${libname} LIBNAME)\n find_library (${LIBNAME}LIB ${libname} HINTS '+ d +')\n list (APPEND ' + name + '_LIB "${${LIBNAME}LIB}")\nendforeach()\n')
|
| 1071 |
slepc |
144 |
return flags
|