-
Notifications
You must be signed in to change notification settings - Fork 0
/
mumps.rb
250 lines (222 loc) · 9.62 KB
/
mumps.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# Script obtained from the https://github.com/Homebrew/homebrew-science repository
'''
Copyright 2009-2016 Homebrew contributors.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'''
class Mumps < Formula
desc "Parallel Sparse Direct Solver"
homepage "http://mumps-solver.org"
url "http://mumps.enseeiht.fr/MUMPS_5.1.1.tar.gz"
mirror "http://graal.ens-lyon.fr/MUMPS/MUMPS_5.1.1.tar.gz"
sha256 "a2a1f89c470f2b66e9982953cbd047d429a002fab9975400cef7190d01084a06"
revision 1
bottle :disable, "needs to be rebuilt with latest open-mpi"
depends_on "open-mpi" => [:cc, :cxx, :f90, :recommended]
depends_on "openblas" => OS.mac? ? :optional : :recommended
depends_on "veclibfort" if build.without?("openblas") && OS.mac?
depends_on "gcc"
if build.with? "mpi"
if OS.mac?
depends_on "scalapack" => build.with?("openblas") ? ["with-openblas"] : []
else
depends_on "scalapack" => build.without?("openblas") ? ["without-openblas"] : []
end
end
depends_on "metis" => :optional if build.without? "mpi"
depends_on "parmetis" => :optional if build.with? "mpi"
depends_on "scotch5" => :optional
depends_on "scotch" => :optional
resource "mumps_simple" do
url "https://github.com/dpo/mumps_simple/archive/v0.4.tar.gz"
sha256 "87d1fc87eb04cfa1cba0ca0a18f051b348a93b0b2c2e97279b23994664ee437e"
end
def install
set_fortran_compiler_linker
make_args = ["RANLIB=echo"]
if OS.mac?
# Building dylibs with mpif90 causes segfaults on 10.8 and 10.10. Use gfortran.
shlibs_args = ["LIBEXT=.dylib",
"AR=#{ENV["FC"]} -dynamiclib -Wl,-install_name -Wl,#{lib}/$(notdir $@) -undefined dynamic_lookup -o "]
else
shlibs_args = ["LIBEXT=.so",
"AR=$(FL) -shared -Wl,-soname -Wl,$(notdir $@) -o "]
end
make_args += ["OPTF=-O", "CDEFS=-DAdd_"]
orderingsf = "-Dpord"
makefile = (build.with? "mpi") ? "Makefile.G95.PAR" : "Makefile.G95.SEQ"
cp "Make.inc/" + makefile, "Makefile.inc"
if build.with? "scotch5"
make_args += ["SCOTCHDIR=#{Formula["scotch5"].opt_prefix}",
"ISCOTCH=-I#{Formula["scotch5"].opt_include}"]
if build.with? "mpi"
scotch_libs = "LSCOTCH=-L$(SCOTCHDIR)/lib -lptesmumps -lptscotch -lptscotcherr"
scotch_libs += " -lptscotchparmetis" if build.with? "parmetis"
make_args << scotch_libs
orderingsf << " -Dptscotch"
else
scotch_libs = "LSCOTCH=-L$(SCOTCHDIR) -lesmumps -lscotch -lscotcherr"
scotch_libs += " -lscotchmetis" if build.with? "metis"
make_args << scotch_libs
orderingsf << " -Dscotch"
end
elsif build.with? "scotch"
make_args += ["SCOTCHDIR=#{Formula["scotch"].opt_prefix}",
"ISCOTCH=-I#{Formula["scotch"].opt_include}"]
if build.with? "mpi"
scotch_libs = "LSCOTCH=-L$(SCOTCHDIR)/lib -lptscotch -lptscotcherr -lptscotcherrexit -lscotch"
scotch_libs += "-lptscotchparmetis" if build.with? "parmetis"
make_args << scotch_libs
orderingsf << " -Dptscotch"
else
scotch_libs = "LSCOTCH=-L$(SCOTCHDIR) -lscotch -lscotcherr -lscotcherrexit"
scotch_libs += "-lscotchmetis" if build.with? "metis"
make_args << scotch_libs
orderingsf << " -Dscotch"
end
end
if build.with? "parmetis"
make_args += ["LMETISDIR=#{Formula["parmetis"].opt_lib}",
"IMETIS=#{Formula["parmetis"].opt_include}",
"LMETIS=-L#{Formula["parmetis"].opt_lib} -lparmetis -L#{Formula["metis"].opt_lib} -lmetis"]
orderingsf << " -Dparmetis"
elsif build.with? "metis"
make_args += ["LMETISDIR=#{Formula["metis"].opt_lib}",
"IMETIS=#{Formula["metis"].opt_include}",
"LMETIS=-L#{Formula["metis"].opt_lib} -lmetis"]
orderingsf << " -Dmetis"
end
make_args << "ORDERINGSF=#{orderingsf}"
if build.with? "mpi"
make_args += ["CC=#{ENV["MPICC"]} -fPIC",
"FC=#{ENV["MPIFC"]} -fPIC",
"FL=#{ENV["MPIFC"]} -fPIC",
"SCALAP=-L#{Formula["scalapack"].opt_lib} -lscalapack",
"INCPAR=", # Let MPI compilers fill in the blanks.
"LIBPAR=$(SCALAP)"]
else
make_args += ["CC=#{ENV["CC"]} -fPIC",
"FC=#{ENV["FC"]} -fPIC",
"FL=#{ENV["FC"]} -fPIC"]
end
if build.with? "openblas"
make_args << "LIBBLAS=-L#{Formula["openblas"].opt_lib} -lopenblas"
elsif build.with? "veclibfort"
make_args << "LIBBLAS=-L#{Formula["veclibfort"].opt_lib} -lvecLibFort"
else
make_args << "LIBBLAS=-lblas -llapack"
end
ENV.deparallelize # Build fails in parallel on Mavericks.
system "make", "alllib", *(shlibs_args + make_args)
lib.install Dir["lib/*"]
lib.install ("libseq/libmpiseq" + (OS.mac? ? ".dylib" : ".so")) if build.without? "mpi"
# Build static libraries (e.g., for Dolfin)
system "make", "alllib", *make_args
(libexec/"lib").install Dir["lib/*.a"]
(libexec/"lib").install "libseq/libmpiseq.a" if build.without? "mpi"
inreplace "examples/Makefile" do |s|
s.change_make_var! "libdir", lib
end
libexec.install "include"
include.install_symlink Dir[libexec/"include/*"]
# The following .h files may conflict with others related to MPI
# in /usr/local/include. Do not symlink them.
(libexec/"include").install Dir["libseq/*.h"] if build.without? "mpi"
doc.install Dir["doc/*.pdf"]
pkgshare.install "examples"
prefix.install "Makefile.inc" # For the record.
File.open(prefix/"make_args.txt", "w") do |f|
f.puts(make_args.join(" ")) # Record options passed to make.
end
if build.with? "mpi"
resource("mumps_simple").stage do
simple_args = ["CC=#{ENV["MPICC"]}", "prefix=#{prefix}", "mumps_prefix=#{prefix}",
"scalapack_libdir=#{Formula["scalapack"].opt_lib}"]
if build.with? "scotch5"
simple_args += ["scotch_libdir=#{Formula["scotch5"].opt_lib}",
"scotch_libs=-L$(scotch_libdir) -lptesmumps -lptscotch -lptscotcherr"]
elsif build.with? "scotch"
simple_args += ["scotch_libdir=#{Formula["scotch"].opt_lib}",
"scotch_libs=-L$(scotch_libdir) -lptscotch -lptscotcherr -lscotch"]
end
if build.with? "openblas"
simple_args += ["blas_libdir=#{Formula["openblas"].opt_lib}",
"blas_libs=-L$(blas_libdir) -lopenblas"]
end
system "make", "SHELL=/bin/bash", *simple_args
lib.install ("libmumps_simple." + (OS.mac? ? "dylib" : "so"))
include.install "mumps_simple.h"
end
end
end
def caveats
s = <<~EOS
MUMPS was built with shared libraries. If required,
static libraries are available in
#{opt_libexec}/lib
EOS
if build.without? "mpi"
s += <<~EOS
You built a sequential MUMPS library.
Please add #{libexec}/include to the include path
when building software that depends on MUMPS.
EOS
end
s
end
def set_fortran_compiler_linker
ENV["FC"] ||= "gfortran"
ENV["FL"] ||= "gfortran"
end
test do
ENV.fortran
cp_r pkgshare/"examples", testpath
opts = ["-I#{opt_include}", "-L#{opt_lib}", "-lmumps_common", "-lpord"]
if Tab.for_name("mumps").with? "openblas"
opts << "-L#{Formula["openblas"].opt_lib}" << "-lopenblas"
elsif OS.mac?
opts << "-L#{Formula["veclibfort"].opt_lib}" << "-lvecLibFort"
else
opts << "-lblas" << "-llapack"
end
if Tab.for_name("mumps").with?("mpi")
f90 = "mpif90"
cc = "mpicc"
mpirun = "mpirun -np 2"
opts << "-lscalapack"
else
f90 = ENV["FC"]
cc = ENV["CC"]
mpirun = ""
end
cd testpath/"examples" do
system f90, "-o", "ssimpletest", "ssimpletest.F", "-lsmumps", *opts
system "#{mpirun} ./ssimpletest < input_simpletest_real"
system f90, "-o", "dsimpletest", "dsimpletest.F", "-ldmumps", *opts
system "#{mpirun} ./dsimpletest < input_simpletest_real"
system f90, "-o", "csimpletest", "csimpletest.F", "-lcmumps", *opts
system "#{mpirun} ./csimpletest < input_simpletest_cmplx"
system f90, "-o", "zsimpletest", "zsimpletest.F", "-lzmumps", *opts
system "#{mpirun} ./zsimpletest < input_simpletest_cmplx"
system cc, "-c", "c_example.c", "-I#{opt_include}"
system f90, "-o", "c_example", "c_example.o", "-ldmumps", *opts
system *(mpirun.split + ["./c_example"] + opts)
end
end
end