From a13dccf9e79dc7c0d00b2f5a3aba36fcd4c0cf5d Mon Sep 17 00:00:00 2001 From: ksagiyam Date: Sat, 9 Apr 2022 02:20:35 +0100 Subject: [PATCH 1/3] firedrake-install: get petsc_int_type from petscconf.h --- scripts/firedrake-install | 79 ++++++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 22 deletions(-) diff --git a/scripts/firedrake-install b/scripts/firedrake-install index 834650fe1a..b8151416af 100755 --- a/scripts/firedrake-install +++ b/scripts/firedrake-install @@ -216,6 +216,33 @@ 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" + + if mode == "install": # Handle command line arguments. parser = ArgumentParser(description="""Install firedrake and its dependencies.""", @@ -255,12 +282,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.") @@ -342,7 +368,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 [] @@ -376,13 +407,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.") @@ -416,8 +446,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: @@ -983,16 +1023,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(): From cc252bfcc53ceffc4f692fd4aceed2bb2137efa3 Mon Sep 17 00:00:00 2001 From: ksagiyam Date: Fri, 8 Apr 2022 22:15:08 +0100 Subject: [PATCH 2/3] firedrake-install: factor minimal petsc packages --- scripts/firedrake-install | 66 +++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/scripts/firedrake-install b/scripts/firedrake-install index b8151416af..23a8cea12d 100755 --- a/scripts/firedrake-install +++ b/scripts/firedrake-install @@ -243,6 +243,11 @@ def honour_petsc_dir_get_petsc_int_type(): 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.""", @@ -614,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") + if not options["complex"]: + # AMG + pkgs.add("hypre") + if options["petsc_int_type"] == "int32": + # Sparse direct solver + pkgs.add("scalapack") # Needed for mumps + pkgs.add("mumps") + # 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": @@ -658,11 +676,6 @@ 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") @@ -670,7 +683,6 @@ def get_petsc_options(minimal=False): 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') @@ -718,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: @@ -1465,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") @@ -1483,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) From c3e8cc42a3c929fb6b949d9e0a2a12d6d9bc70dd Mon Sep 17 00:00:00 2001 From: ksagiyam Date: Fri, 8 Apr 2022 22:17:45 +0100 Subject: [PATCH 3/3] firedrake-install: can now use mumps with 64bit int --- scripts/firedrake-install | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/firedrake-install b/scripts/firedrake-install index 23a8cea12d..3cb765c751 100755 --- a/scripts/firedrake-install +++ b/scripts/firedrake-install @@ -627,13 +627,13 @@ def get_minimal_petsc_packages(): 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": - # Sparse direct solver - pkgs.add("scalapack") # Needed for mumps - pkgs.add("mumps") # Serial mesh partitioner pkgs.add("chaco") return pkgs