strumpack: make standalone test for +mpi more robust (#44943)
* strumpack: make standalone test for +mpi more robust * Comment about which MPI launcher being attempted
This commit is contained in:
		| @@ -3,8 +3,13 @@ | |||||||
| # | # | ||||||
| # SPDX-License-Identifier: (Apache-2.0 OR MIT) | # SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||||||
| 
 | 
 | ||||||
|  | import os | ||||||
|  | 
 | ||||||
|  | import llnl.util.tty as tty | ||||||
|  | 
 | ||||||
| from spack.package import * | from spack.package import * | ||||||
| from spack.util.environment import set_env | from spack.util.environment import set_env | ||||||
|  | from spack.util.executable import ProcessError | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Strumpack(CMakePackage, CudaPackage, ROCmPackage): | class Strumpack(CMakePackage, CudaPackage, ROCmPackage): | ||||||
| @@ -205,7 +210,7 @@ def cache_test_sources(self): | |||||||
|         install test subdirectory for use during `spack test run`.""" |         install test subdirectory for use during `spack test run`.""" | ||||||
|         self.cache_extra_test_sources([self.test_data_dir, self.test_src_dir]) |         self.cache_extra_test_sources([self.test_data_dir, self.test_src_dir]) | ||||||
| 
 | 
 | ||||||
|     def _test_example(self, test_prog, test_cmd, test_args): |     def _test_example(self, test_prog, test_cmd, pre_args=[]): | ||||||
|         test_dir = join_path(self.test_suite.current_test_cache_dir, self.test_src_dir) |         test_dir = join_path(self.test_suite.current_test_cache_dir, self.test_src_dir) | ||||||
|         cmake_filename = join_path(test_dir, "CMakeLists.txt") |         cmake_filename = join_path(test_dir, "CMakeLists.txt") | ||||||
|         with open(cmake_filename, "w") as mkfile: |         with open(cmake_filename, "w") as mkfile: | ||||||
| @@ -218,9 +223,7 @@ def _test_example(self, test_prog, test_cmd, test_args): | |||||||
|             ) |             ) | ||||||
| 
 | 
 | ||||||
|         with working_dir(test_dir): |         with working_dir(test_dir): | ||||||
|             opts = self.builder.std_cmake_args |             opts = self.builder.std_cmake_args + self.cmake_args() + ["."] | ||||||
|             opts += self.cmake_args() |  | ||||||
|             opts += ["."] |  | ||||||
|             cmake = self.spec["cmake"].command |             cmake = self.spec["cmake"].command | ||||||
|             cmake(*opts) |             cmake(*opts) | ||||||
| 
 | 
 | ||||||
| @@ -229,29 +232,32 @@ def _test_example(self, test_prog, test_cmd, test_args): | |||||||
| 
 | 
 | ||||||
|             with set_env(OMP_NUM_THREADS="1"): |             with set_env(OMP_NUM_THREADS="1"): | ||||||
|                 exe = which(test_cmd) |                 exe = which(test_cmd) | ||||||
|  |                 test_args = pre_args + [join_path("..", self.test_data_dir, "pde900.mtx")] | ||||||
|                 exe(*test_args) |                 exe(*test_args) | ||||||
| 
 | 
 | ||||||
|     def test_sparse_seq(self): |     def test_sparse_seq(self): | ||||||
|         """Run sequential test_sparse""" |         """Run sequential test_sparse""" | ||||||
|         if "+mpi" in self.spec: |  | ||||||
|             raise SkipTest("Package must be installed with '~mpi'") |  | ||||||
|         test_exe = "test_sparse_seq" |         test_exe = "test_sparse_seq" | ||||||
|         exe_arg = [join_path("..", self.test_data_dir, "pde900.mtx")] |         self._test_example(test_exe, test_exe) | ||||||
|         self._test_example(test_exe, test_exe, exe_arg) |  | ||||||
| 
 | 
 | ||||||
|     def test_sparse_mpi(self): |     def test_sparse_mpi(self): | ||||||
|         """Run parallel test_sparse""" |         """Run parallel test_sparse""" | ||||||
|         if "+mpi" not in self.spec: |         if "+mpi" not in self.spec: | ||||||
|             raise SkipTest("Package must be installed with '+mpi'") |             raise SkipTest("Package must be installed with '+mpi'") | ||||||
|         test_exe_mpi = "test_sparse_mpi" |         test_exe_mpi = "test_sparse_mpi" | ||||||
|         test_args = ["-n", "1", test_exe_mpi, join_path("..", self.test_data_dir, "pde900.mtx")] |         mpi_args = ["-n", "1", test_exe_mpi] | ||||||
|         mpiexe_list = ["srun", "mpirun", "mpiexec"] | 
 | ||||||
|  |         mpi_bin = self.spec["mpi"].prefix.bin | ||||||
|  |         mpiexe_list = ["srun", mpi_bin.mpirun, mpi_bin.mpiexec] | ||||||
|         for exe in mpiexe_list: |         for exe in mpiexe_list: | ||||||
|  |             tty.info(f"Attempting to build and launch with {os.path.basename(exe)}") | ||||||
|             try: |             try: | ||||||
|                 self._test_example(test_exe_mpi, exe, test_args) |                 args = ["--immediate=30"] + mpi_args if exe == "srun" else mpi_args | ||||||
|  |                 self._test_example(test_exe_mpi, exe, args) | ||||||
|                 return |                 return | ||||||
|             except Exception: |             except (Exception, ProcessError) as err: | ||||||
|                 pass |                 tty.info(f"Skipping {exe}: {str(err)}") | ||||||
|  | 
 | ||||||
|         assert False, "No MPI executable was found" |         assert False, "No MPI executable was found" | ||||||
| 
 | 
 | ||||||
|     def check(self): |     def check(self): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Tamara Dahlgren
					Tamara Dahlgren