File trlan.spec of Package trlan

#
# spec file for package trlan
#
# Copyright (c) 2024 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


%global flavor @BUILD_FLAVOR@%{nil}

%define so_ver 0

%if !0%{?is_opensuse} && 0%{?sle_version:1} && 0%{?sle_version} < 150200
%define DisOMPI3 ExclusiveArch:  do_not_build
%endif
%if 0%{?is_opensuse} && 0%{?suse_version} >= 1600
%define DisOMPI2 ExclusiveArch:  do_not_build
%define DisOMPI3 ExclusiveArch:  do_not_build
%endif

%if "%flavor" == ""
ExclusiveArch:  do_not_build
%endif

%if "%flavor" == "serial"
%{bcond_with hpc}
%endif

%if "%flavor" == "openmpi2"
%{?DisOMPI2}
%define mpi_family openmpi
%define mpi_ver 2
%{bcond_with hpc}
%endif

%if "%flavor" == "openmpi3"
%{?DisOMPI3}
%define mpi_family openmpi
%define mpi_ver 3
%{bcond_with hpc}
%endif

%if "%flavor" == "openmpi4"
%{?DisOMPI4}
%define mpi_family openmpi
%define mpi_ver 4
%{bcond_with hpc}
%endif

%if 0%{?mpi_family:1}
%{bcond_without mpi}
%define pkgname   trlan-%{mpi_family}%{?mpi_ver}
%define libprefix libtrlan_mpi
%define libname() libtrlan_mpi%{so_ver}-%{mpi_family}%{?mpi_ver}
%global my_prefix %{_libdir}/mpi/gcc/%{mpi_family}%{?mpi_ver}
%global my_libdir %{my_prefix}/%{_lib}
%global my_incdir %{my_prefix}/include
%else
%{bcond_with mpi}
%define pkgname   trlan
%define libprefix libtrlan
%define libname() libtrlan%{so_ver}
%global my_prefix %{_prefix}
%global my_libdir %{_libdir}
%global my_incdir %{_includedir}
%endif

Name:           %{pkgname}
Version:        201009
Release:        0
Summary:        A Dynamic Thick Restart Lanczos solver
License:        BSD-2-Clause
Group:          Development/Libraries/C and C++
URL:            https://sdm.lbl.gov/~kewu/trlan.html
Source0:        trlan-%{version}.tar.bz2
# PATCH-FIX-UPSTREAM
Patch0:         0001-Fix-trlan77-prototype-declaration-in-simplec-example.patch
BuildRequires:  fdupes
BuildRequires:  gcc-fortran
BuildRequires:  lapack-devel
%if %{with mpi}
BuildRequires:  %{mpi_family}%{?mpi_ver}-devel
BuildRequires:  %{mpi_family}%{?mpi_ver}-macros-devel
# mmap failures in MPI communication
ExcludeArch:    %{ix86}
%endif

%description
This software package implements the thick-restart Lanczos method.
It can be used on either a single address space machine or a distributed
parallel machine. The user can choose to implement or use a matrix-vector
multiplication routine in any form convenient. Most of the arithmetic
computations in the software are done through calls to BLAS and LAPACK.

%package -n %{libname}
Summary:        A Dynamic Thick Restart Lanczos solver
Group:          System/Libraries
%if %{with mpi}
Requires:       %{mpi_family}%{?mpi_ver}-libs
%endif

%description -n %{libname}
This software package implements the thick-restart Lanczos method.
It can be used on either a single address space machine or a distributed
parallel machine. The user can choose to implement or use a matrix-vector
multiplication routine in any form convenient. Most of the arithmetic
computations in the software are done through calls to BLAS and LAPACK.

%package devel
Summary:        Development and header files for %{name}
Group:          Development/Libraries/C and C++
Requires:       %{libname} = %{version}
%if %{with mpi}
Requires:       %{mpi_family}%{?mpi_ver}-devel
%endif

%description devel
This package contains the development and header files for %{name}.


%prep
%autosetup -p1 -n trlan-%{version}

%build
%if %{with mpi}
%setup_openmpi
export CC=%{my_prefix}/bin/mpicc
export FC=%{my_prefix}/bin/mpif77
export F90=%{my_prefix}/bin/mpif90

# GCC 10+ does not like MPI_Allreduce being called with changing types for the send/recv buffers
%if 0%{?suse_version} >= 1550
make plib FC=${FC} F90=${F90} CFLAGS="%{optflags} -fPIC" FFLAGS="%{optflags} -fallow-argument-mismatch -fPIC"
%else
make plib FC=${FC} F90=${F90} CFLAGS="%{optflags} -fPIC" FFLAGS="%{optflags} -fPIC"
%endif

%else

export F90=%{my_prefix}/bin/gfortran
make lib CFLAGS="%{optflags} -fPIC" FFLAGS="%{optflags} -fPIC"
%endif

gfortran -shared -Wl,-soname=%{libprefix}.so.0 -o %{libprefix}.so.0.0 -Wl,-whole-archive %{libprefix}.a -Wl,-no-whole-archive

# Build test binary
%if %{with mpi}
mpifort -o simplef -I ./SRC/ ./examples/T3E/simple.f90 -ltrlan_mpi -llapack -lblas -lm -L .
%else
gfortran -o simplec ./examples/SUN/simplec.c -ltrlan -llapack -lblas -lm -L .
%endif

%install
install -m 755 -Dpt %{buildroot}%{my_libdir} %{libprefix}.so.0.0
ln -s %{libprefix}.so.0.0 %{buildroot}%{my_libdir}/%{libprefix}.so.0
ln -s %{libprefix}.so.0.0 %{buildroot}%{my_libdir}/%{libprefix}.so

install -m 644 -Dpt %{buildroot}%{my_incdir} SRC/*.mod

%fdupes -s %{buildroot}%{my_incdir}

%check
%if %{with mpi}
%setup_openmpi
mpirun --np 2 --use-hwthread-cpus --display-map --mca btl vader,self ./simplef
%else
./simplec
%endif

%post -n %{libname} -p /sbin/ldconfig

%postun -n %{libname} -p /sbin/ldconfig

%files -n %{libname}
%{my_libdir}/%{libprefix}.so.*

%files devel
%doc README doc/*.html
%{my_incdir}/*
%{my_libdir}/%{libprefix}.so

%changelog
openSUSE Build Service is sponsored by