Skip to content

Commit

Permalink
Merge pull request #2409 from firedrakeproject/ksagiyam/fix_install_f…
Browse files Browse the repository at this point in the history
…or_64bit_int

Ksagiyam/fix install for 64bit int
  • Loading branch information
dham authored Jul 28, 2022
2 parents 91f42df + c3e8cc4 commit 8f746be
Showing 1 changed file with 89 additions and 56 deletions.
145 changes: 89 additions & 56 deletions scripts/firedrake-install
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,38 @@ def resolve_doi_branches(doi):
return branches


def honour_petsc_dir_get_petsc_dir():
try:
petsc_dir = os.environ["PETSC_DIR"]
except KeyError:
raise InstallError("Unable to find installed PETSc (did you forget to set PETSC_DIR?)")
petsc_arch = os.environ.get("PETSC_ARCH", "")
return petsc_dir, petsc_arch


def honour_petsc_dir_fetch_petscconf(name):
# Return the line in "petscconf.h" that starts with name.
petsc_dir, petsc_arch = honour_petsc_dir_get_petsc_dir()
petscconf_h = os.path.join(petsc_dir, petsc_arch, "include", "petscconf.h")
with open(petscconf_h) as fh:
for line in fh.readlines():
if line.startswith(name):
return line


def honour_petsc_dir_get_petsc_int_type():
line = honour_petsc_dir_fetch_petscconf("#define PETSC_USE_64BIT_INDICES")
if line and line.split()[2] == '1':
return "int64"
else:
return "int32"


def honour_petsc_dir_get_petsc_packages():
line = honour_petsc_dir_fetch_petscconf("#define PETSC_HAVE_PACKAGES")
return set(line.split()[2].strip().strip(':"').split(':'))


if mode == "install":
# Handle command line arguments.
parser = ArgumentParser(description="""Install firedrake and its dependencies.""",
Expand Down Expand Up @@ -255,12 +287,11 @@ honoured.""",
help="Minimise the set of petsc dependencies installed. This creates faster build times (useful for build testing).")
group.add_argument("--with-parmetis", action="store_true",
help="Install PETSc with ParMETIS? (Non-free license, see http://glaros.dtc.umn.edu/gkhome/metis/parmetis/download)")
group = parser.add_mutually_exclusive_group()
group.add_argument("--honour-petsc-dir", action="store_true",
help="Usually it is best to let Firedrake build its own PETSc. If you wish to use another PETSc, set PETSC_DIR and pass this option.")
group.add_argument("--petsc-int-type", choices=["int32", "int64"],
default="int32", type=str,
help="The integer type used by PETSc. Use int64 if you need to solve problems with more than 2 billion degrees of freedom. Only takes effect if firedrake-install builds PETSc.")
parser.add_argument("--honour-petsc-dir", action="store_true",
help="Usually it is best to let Firedrake build its own PETSc. If you wish to use another PETSc, set PETSC_DIR and pass this option.")
parser.add_argument("--petsc-int-type", choices=["int32", "int64"],
default="int32", type=str,
help="The integer type used by PETSc. Use int64 if you need to solve problems with more than 2 billion degrees of freedom. Only takes effect if firedrake-install builds PETSc.")

parser.add_argument("--honour-pythonpath", action="store_true",
help="Pointing to external Python packages is usually a user error. Set this option if you know that you want PYTHONPATH set.")
Expand Down Expand Up @@ -342,7 +373,12 @@ honoured.""",
sys.exit(0)
if args.doi:
branches = resolve_doi_branches(args.doi[0])

if args.honour_petsc_dir:
petsc_int_type = honour_petsc_dir_get_petsc_int_type()
if petsc_int_type != args.petsc_int_type:
petsc_dir, petsc_arch = honour_petsc_dir_get_petsc_dir()
log.warning("Provided PETSc (PETSC_DIR=%s, PETSC_ARCH=%s) was compiled for %s, but given --petsc-int-type = %s: setting --petsc-int-type %s." % (petsc_dir, petsc_arch, petsc_int_type, args.petsc_int_type, petsc_int_type))
args.petsc_int_type = petsc_int_type
args.prefix = False # Disabled as untested
args.packages = args.packages or []

Expand Down Expand Up @@ -376,13 +412,12 @@ else:
help="Install OpenCASCADE for CAD integration.")
parser.add_argument("--tinyasm", action="store_true", dest="tinyasm", default=config["options"].get("tinyasm", False),
help="Install TinyASM as backend for ASMPatchPC.")
group = parser.add_mutually_exclusive_group()
group.add_argument("--honour-petsc-dir", action="store_true",
default=config["options"].get("honour_petsc_dir", False),
help="Usually it is best to let Firedrake build its own PETSc. If you wish to use another PETSc, set PETSC_DIR and pass this option.")
group.add_argument("--petsc-int-type", choices=["int32", "int64"],
default="int32", type=str,
help="The integer type used by PETSc. Use int64 if you need to solve problems with more than 2 billion degrees of freedom. Only takes effect if firedrake-install builds PETSc.")
parser.add_argument("--honour-petsc-dir", action="store_true",
default=config["options"]["honour_petsc_dir"],
help="Usually it is best to let Firedrake build its own PETSc. If you wish to use another PETSc, set PETSC_DIR and pass this option.")
parser.add_argument("--petsc-int-type", choices=["int32", "int64"],
default=config["options"]["petsc_int_type"], type=str,
help="The integer type used by PETSc. Use int64 if you need to solve problems with more than 2 billion degrees of freedom. Only takes effect if firedrake-install builds PETSc.")

parser.add_argument("--honour-pythonpath", action="store_true", default=config["options"].get("honour_pythonpath", False),
help="Pointing to external Python packages is usually a user error. Set this option if you know that you want PYTHONPATH set.")
Expand Down Expand Up @@ -416,8 +451,18 @@ else:

args.packages = list(set(args.packages)) # remove duplicates

if args.honour_petsc_dir != config["options"]["honour_petsc_dir"]:
log.error("You installed Firedrake with --honour-petsc-dir=%s, but are trying to update it with --honour-petsc-dir=%s." % (config["options"]["honour_petsc_dir"], args.honour_petsc_dir))
exit(1)
if args.honour_petsc_dir:
# Set int_type to the one found in petscconf.h
petsc_int_type = honour_petsc_dir_get_petsc_int_type()
if petsc_int_type != args.petsc_int_type:
petsc_dir, petsc_arch = honour_petsc_dir_get_petsc_dir()
log.warning("Provided PETSc (PETSC_DIR=%s, PETSC_ARCH=%s) was compiled for %s, but given --petsc-int-type = %s: setting --petsc-int-type %s." % (petsc_dir, petsc_arch, petsc_int_type, args.petsc_int_type, petsc_int_type))
args.petsc_int_type = petsc_int_type
petsc_int_type_changed = False
if config["options"].get("petsc_int_type", "int32") != args.petsc_int_type:
if config["options"]["petsc_int_type"] != args.petsc_int_type:
petsc_int_type_changed = True
args.rebuild = True
if config["options"].get("with_blas") is not None:
Expand Down Expand Up @@ -574,25 +619,38 @@ def brew_gcc_libdir():
return brew_gcc_prefix + "/lib/gcc/" + gcc_major_version


def get_minimal_petsc_packages():
pkgs = set()
# File format
pkgs.add("hdf5")
# Sparse direct solver
pkgs.add("superlu_dist")
# Parallel mesh partitioner
pkgs.add("ptscotch")
# Sparse direct solver
pkgs.add("scalapack") # Needed for mumps
pkgs.add("mumps")
if not options["complex"]:
# AMG
pkgs.add("hypre")
if options["petsc_int_type"] == "int32":
# Serial mesh partitioner
pkgs.add("chaco")
return pkgs


def get_petsc_options(minimal=False):
petsc_options = {"--with-fortran-bindings=0",
"--with-debugging=0",
"--with-shared-libraries=1",
"--with-c2html=0",
"--download-eigen=%s/src/eigen-3.3.3.tgz " % firedrake_env,
# File format
"--download-hdf5",
# AMG
"--download-hypre",
# Sparse direct solver
"--download-superlu_dist",
# Parallel mesh partitioner
"--download-ptscotch",
# Parser generator
"--download-bison",
# For superlu_dist amongst others.
"--with-cxx-dialect=C++11"}

for pkg in get_minimal_petsc_packages():
petsc_options.add("--download-" + pkg)
if osname == "Darwin":
petsc_options.add("--with-x=0")
elif osname == "Linux":
Expand All @@ -618,19 +676,13 @@ def get_petsc_options(minimal=False):
petsc_options.add("--download-parmetis")

if options["petsc_int_type"] == "int32":
# Sparse direct solver
petsc_options.add("--download-scalapack") # Needed for mumps
petsc_options.add("--download-mumps")
# Serial mesh partitioner
petsc_options.add("--download-chaco")
if not options["minimal_petsc"]:
# AMG
petsc_options.add("--download-ml")
else:
petsc_options.add("--with-64-bit-indices")

if options["complex"]:
petsc_options -= {'--download-hypre'}
petsc_options -= {'--download-ml'}
petsc_options.add('--with-scalar-type=complex')

Expand Down Expand Up @@ -678,22 +730,6 @@ def get_petsc_options(minimal=False):
return list(petsc_options)


def get_petsc_packages(minimal=False):
if minimal:
packages = set([
"blaslapack", "chaco", "eigen3", "hdf5", "hypre", "mathlib",
"mpi", "mumps", "ptscotch", "scalapack", "superlu_dist"
])
else:
petsc_dir, petsc_arch = get_petsc_dir()
with open(os.path.join(petsc_dir, petsc_arch, "include", "petscconf.h")) as fh:
for line in fh.readlines():
if line.startswith("#define PETSC_HAVE_PACKAGES"):
packages = set(line.split()[2].strip().strip(':"').split(':'))
break
return packages


def get_petsc_config():
petsc_dir, petsc_arch = get_petsc_dir()
with open(os.path.join(petsc_dir, petsc_arch, "include", "petscconfiginfo.h")) as fh:
Expand Down Expand Up @@ -983,16 +1019,11 @@ def pip_uninstall(package):

def get_petsc_dir():
if args.honour_petsc_dir:
try:
petsc_dir = os.environ["PETSC_DIR"]
except KeyError:
raise InstallError("Unable to find installed PETSc (did you forget to set PETSC_DIR?)")
petsc_arch = os.environ.get("PETSC_ARCH", "")
return honour_petsc_dir_get_petsc_dir()
else:
petsc_dir = os.path.join(os.environ["VIRTUAL_ENV"], "src", "petsc")
petsc_arch = "default"

return petsc_dir, petsc_arch
return petsc_dir, petsc_arch


def get_petsc4py_dir():
Expand Down Expand Up @@ -1430,8 +1461,9 @@ log.debug(check_output(["env"]))
log.debug("\n\n")

if mode == "install" and args.honour_petsc_dir:
minimal_packages = get_petsc_packages(minimal=True)
current_packages = get_petsc_packages()
minimal_packages = get_minimal_petsc_packages()
minimal_packages.update({"blaslapack", "eigen3", "mathlib", "mpi"})
current_packages = honour_petsc_dir_get_petsc_packages()
log.debug("*****************************************************")
log.debug("Specified PETSc was built with the following options:")
log.debug("*****************************************************\n")
Expand All @@ -1448,7 +1480,8 @@ if mode == "install" and args.honour_petsc_dir:
log.error("*********************************************************************\n")
log.error("\n".join(sorted(get_petsc_options(minimal=True))))
log.error("")
log.error("Eigen can be downloaded from https://github.com/eigenteam/eigen-git-mirror/archive/3.3.3.tar.gz\n")
if "eigen3" in (minimal_packages - current_packages):
log.error("Eigen can be downloaded from https://github.com/eigenteam/eigen-git-mirror/archive/3.3.3.tar.gz\n")
log.error('Use --show-petsc-configure-options as an argument to the firedrake-install script to display options if additional functionality is required.\n ')
log.error("FATAL: Unable to install with specified PETSc")
exit(1)
Expand Down

0 comments on commit 8f746be

Please sign in to comment.