From 67f15df6ece06ebe1241c654c6eddd52e8543b3a Mon Sep 17 00:00:00 2001
From: badshah400 <>
Date: Aug 11 2022 16:45:33 +0000
Subject: Update wannier90 to version 3.1.0 / rev 1 via SR 994407
https://build.opensuse.org/request/show/994407
by user badshah400 + dimstar_suse
New package: A library for generating maximally-localized Wannier functions, will be needed for future quantum-espresso updates
---
diff --git a/.files b/.files
new file mode 100644
index 0000000..409bd65
Binary files /dev/null and b/.files differ
diff --git a/.meta b/.meta
new file mode 100644
index 0000000..53f63fa
--- /dev/null
+++ b/.meta
@@ -0,0 +1,10 @@
+
+ A library for generating maximally-localized Wannier functions
+ Wannier90 is a library for generating maximally-localized Wannier functions and
+using them to compute advanced electronic properties of materials with high
+efficiency and accuracy.
+
+
+
+ http://www.wannier.org/
+
diff --git a/.rev b/.rev
new file mode 100644
index 0000000..82339c7
--- /dev/null
+++ b/.rev
@@ -0,0 +1,10 @@
+
+
+ 2850c884c31e7857fecb3cf3d647800b
+ 3.1.0
+
+ dimstar_suse
+ New package: A library for generating maximally-localized Wannier functions, will be needed for future quantum-espresso updates
+ 994407
+
+
diff --git a/_multibuild b/_multibuild
new file mode 100644
index 0000000..b332aa7
--- /dev/null
+++ b/_multibuild
@@ -0,0 +1,6 @@
+
+ openmpi1
+ openmpi2
+ openmpi3
+ openmpi4
+
diff --git a/a75344b646227c9d7f12d90af4a35a902e940dca.patch b/a75344b646227c9d7f12d90af4a35a902e940dca.patch
new file mode 100644
index 0000000..45944ea
--- /dev/null
+++ b/a75344b646227c9d7f12d90af4a35a902e940dca.patch
@@ -0,0 +1,107 @@
+From 8ede1ab6e585c475eaa63b1e64211f43bc4fdff8 Mon Sep 17 00:00:00 2001
+From: Junfeng Qiao
+Date: Thu, 21 Jan 2021 19:26:33 +0100
+Subject: [PATCH 1/2] Allocate arrays on non-root nodes to avoid SIGSEG
+
+Although these arrays are not used by the non-root nodes, in some
+versions of OpenMPI (e.g. 4.0), SIGSEGV may occur when doing
+MPI_scatterv. Allocating 0-sized arrays could bypass the issue.
+---
+ src/disentangle.F90 | 2 ++
+ src/overlap.F90 | 12 ++++++++----
+ 2 files changed, 10 insertions(+), 4 deletions(-)
+
+diff --git a/src/disentangle.F90 b/src/disentangle.F90
+index d2fbd3e2..ff3b9516 100644
+--- a/src/disentangle.F90
++++ b/src/disentangle.F90
+@@ -204,6 +204,8 @@ subroutine dis_main()
+ if (on_root) then
+ allocate (m_matrix(num_wann, num_wann, nntot, num_kpts), stat=ierr)
+ if (ierr /= 0) call io_error('Error in allocating m_matrix in dis_main')
++ else
++ allocate (m_matrix(0, 0, 0, 0), stat=ierr)
+ endif
+ allocate (m_matrix_local(num_wann, num_wann, nntot, counts(my_node_id)), stat=ierr)
+ if (ierr /= 0) call io_error('Error in allocating m_matrix_local in dis_main')
+diff --git a/src/overlap.F90 b/src/overlap.F90
+index 457405c7..c3fd6dae 100644
+--- a/src/overlap.F90
++++ b/src/overlap.F90
+@@ -64,6 +64,8 @@ subroutine overlap_allocate()
+ if (on_root) then
+ allocate (m_matrix_orig(num_bands, num_bands, nntot, num_kpts), stat=ierr)
+ if (ierr /= 0) call io_error('Error in allocating m_matrix_orig in overlap_read')
++ else
++ allocate (m_matrix_orig(0, 0, 0, 0))
+ endif
+ allocate (m_matrix_orig_local(num_bands, num_bands, nntot, counts(my_node_id)), stat=ierr)
+ if (ierr /= 0) call io_error('Error in allocating m_matrix_orig_local in overlap_read')
+@@ -76,6 +78,8 @@ subroutine overlap_allocate()
+ allocate (m_matrix(num_wann, num_wann, nntot, num_kpts), stat=ierr)
+ if (ierr /= 0) call io_error('Error in allocating m_matrix in overlap_read')
+ m_matrix = cmplx_0
++ else
++ allocate (m_matrix(0, 0, 0, 0))
+ endif
+ allocate (m_matrix_local(num_wann, num_wann, nntot, counts(my_node_id)), stat=ierr)
+ if (ierr /= 0) call io_error('Error in allocating m_matrix_local in overlap_read')
+@@ -563,12 +567,12 @@ subroutine overlap_dealloc()
+ deallocate (a_matrix, stat=ierr)
+ if (ierr /= 0) call io_error('Error deallocating a_matrix in overlap_dealloc')
+ end if
+- if (on_root) then
++! if (on_root) then
+ if (allocated(m_matrix_orig)) then
+ deallocate (m_matrix_orig, stat=ierr)
+ if (ierr /= 0) call io_error('Error deallocating m_matrix_orig in overlap_dealloc')
+ endif
+- endif
++! endif
+ if (allocated(m_matrix_orig_local)) then
+ deallocate (m_matrix_orig_local, stat=ierr)
+ if (ierr /= 0) call io_error('Error deallocating m_matrix_orig_local in overlap_dealloc')
+@@ -588,12 +592,12 @@ subroutine overlap_dealloc()
+ ! if (ierr/=0) call io_error('Error deallocating m_matrix_local in overlap_dealloc')
+ ! deallocate ( u_matrix, stat=ierr )
+ ! if (ierr/=0) call io_error('Error deallocating u_matrix in overlap_dealloc')
+- if (on_root) then
++! if (on_root) then
+ if (allocated(m_matrix)) then
+ deallocate (m_matrix, stat=ierr)
+ if (ierr /= 0) call io_error('Error deallocating m_matrix in overlap_dealloc')
+ endif
+- endif
++! endif
+ if (allocated(m_matrix_local)) then
+ deallocate (m_matrix_local, stat=ierr)
+ if (ierr /= 0) call io_error('Error deallocating m_matrix_local in overlap_dealloc')
+
+From a8a10661c9dcd461706d39387c822d0effb1b964 Mon Sep 17 00:00:00 2001
+From: Junfeng Qiao
+Date: Mon, 12 Jul 2021 22:53:56 +0200
+Subject: [PATCH 2/2] Format code to pass pre-commit
+
+---
+ src/overlap.F90 | 8 ++++----
+ 1 file changed, 4 insertions(+), 4 deletions(-)
+
+diff --git a/src/overlap.F90 b/src/overlap.F90
+index c3fd6dae..0b0f84cf 100644
+--- a/src/overlap.F90
++++ b/src/overlap.F90
+@@ -593,10 +593,10 @@ subroutine overlap_dealloc()
+ ! deallocate ( u_matrix, stat=ierr )
+ ! if (ierr/=0) call io_error('Error deallocating u_matrix in overlap_dealloc')
+ ! if (on_root) then
+- if (allocated(m_matrix)) then
+- deallocate (m_matrix, stat=ierr)
+- if (ierr /= 0) call io_error('Error deallocating m_matrix in overlap_dealloc')
+- endif
++ if (allocated(m_matrix)) then
++ deallocate (m_matrix, stat=ierr)
++ if (ierr /= 0) call io_error('Error deallocating m_matrix in overlap_dealloc')
++ endif
+ ! endif
+ if (allocated(m_matrix_local)) then
+ deallocate (m_matrix_local, stat=ierr)
diff --git a/wannier90-3.1.0.tar.gz b/wannier90-3.1.0.tar.gz
new file mode 120000
index 0000000..ee3fc01
--- /dev/null
+++ b/wannier90-3.1.0.tar.gz
@@ -0,0 +1 @@
+/ipfs/bafybeiboy5yjkzcslyd5ittzjx2dy4e6u43ajvprcrpsb4yrvcaf5haljm
\ No newline at end of file
diff --git a/wannier90-fix-parallel-compilation.patch b/wannier90-fix-parallel-compilation.patch
new file mode 100644
index 0000000..42743ed
--- /dev/null
+++ b/wannier90-fix-parallel-compilation.patch
@@ -0,0 +1,26 @@
+Index: wannier90-3.1.0/config/make.inc.gfort
+===================================================================
+--- wannier90-3.1.0.orig/config/make.inc.gfort
++++ wannier90-3.1.0/config/make.inc.gfort
+@@ -7,7 +7,7 @@ F90 = gfortran
+ #COMMS = mpi
+ #MPIF90 = mpgfortran #mpif90
+
+-FCOPTS = -O3
++FCOPTS = -O3 -fallow-argument-mismatch
+ LDOPTS =
+
+ #Next two lines are good for debugging
+Index: wannier90-3.1.0/config/make.inc.gfort.dynlib
+===================================================================
+--- wannier90-3.1.0.orig/config/make.inc.gfort.dynlib
++++ wannier90-3.1.0/config/make.inc.gfort.dynlib
+@@ -7,7 +7,7 @@ F90 = gfortran
+ #COMMS = mpi
+ #MPIF90 = mpgfortran #mpif90
+
+-FCOPTS = -O3 -fPIC
++FCOPTS = -O3 -fPIC -fallow-argument-mismatch
+ LDOPTS = -fPIC
+
+ #Next two lines are good for debugging
diff --git a/wannier90-install-pkgconfig.patch b/wannier90-install-pkgconfig.patch
new file mode 100644
index 0000000..2050e12
--- /dev/null
+++ b/wannier90-install-pkgconfig.patch
@@ -0,0 +1,106 @@
+From 8526b232e0c21e75e61bd57764fee1d4df6ba1ee Mon Sep 17 00:00:00 2001
+From: Pierre Kestener
+Date: Wed, 16 Mar 2022 10:21:43 +0100
+Subject: [PATCH] Update Makefile to install a package config file.
+
+---
+ Makefile | 51 ++++++++++++++++++++++++++++++++++++++-------------
+ 1 file changed, 38 insertions(+), 13 deletions(-)
+
+Index: wannier90-3.1.0/Makefile
+===================================================================
+--- wannier90-3.1.0.orig/Makefile
++++ wannier90-3.1.0/Makefile
+@@ -10,6 +10,13 @@ default: wannier post
+
+ PREFIX ?= /usr
+
++VERSION_MAJOR = 3
++VERSION_MINOR = 1
++VERSION_PATCH = 0
++
++VERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH)
++VERSION_SHORT = $(VERSION_MAJOR).$(VERSION_MINOR)
++
+ install: default
+ install -d $(DESTDIR)$(PREFIX)/bin/
+ for x in wannier90.x postw90.x w90chk2chk.x w90spn2spn.x ; do \
+@@ -19,6 +26,7 @@ install: default
+ if [ -f "utility/w90vdw/w90vdw.x" ]; then install -m755 "utility/w90vdw/w90vdw.x" "$(DESTDIR)$(PREFIX)/bin/w90vdw.x"; fi;
+ install -d $(DESTDIR)$(PREFIX)/lib/
+ if [ -f "libwannier.a" ]; then install -m644 "libwannier.a" "$(DESTDIR)$(PREFIX)/lib/libwannier.a"; fi;
++ if [ -f "libwannier.a" ]; then $(MAKE) pkgconfig; fi;
+
+ all: wannier lib post w90chk2chk w90pov w90vdw w90spn2spn
+
+@@ -50,12 +58,29 @@ w90vdw:
+
+ libs: lib
+
++PKGCONFIG_FILENAME = wannier.pc
++pkgconfig:
++ $(file > $(PKGCONFIG_FILENAME),prefix=$(DESTDIR)$(PREFIX))
++ $(file >> $(PKGCONFIG_FILENAME),exec_prefix=$(DESTDIR)$(PREFIX)/bin)
++ $(file >> $(PKGCONFIG_FILENAME),libdir=$(DESTDIR)$(PREFIX)/lib)
++ $(file >> $(PKGCONFIG_FILENAME),includedir=$(DESTDIR)$(PREFIX)/include)
++ $(file >> $(PKGCONFIG_FILENAME),)
++ $(file >> $(PKGCONFIG_FILENAME),Name: wannier)
++ $(file >> $(PKGCONFIG_FILENAME),Description: Compute maximally-localised Wannier functions.)
++ $(file >> $(PKGCONFIG_FILENAME),Requires: )
++ $(file >> $(PKGCONFIG_FILENAME),Version: $(VERSION))
++ $(file >> $(PKGCONFIG_FILENAME),Libs: -L$${libdir} -lwannier)
++ $(file >> $(PKGCONFIG_FILENAME),Cflags: -I$${includedir})
++ install -D -m644 "$(PKGCONFIG_FILENAME)" "$(DESTDIR)$(PREFIX)/lib/pkgconfig/$(PKGCONFIG_FILENAME)"
++ cd $(ROOTDIR) && rm -f $(PKGCONFIG_FILENAME)
++
+ post: objdirp
+ (cd $(ROOTDIR)/src/objp && $(MAKE) -f $(REALMAKEFILE) post)
+
+ clean:
+ cd $(ROOTDIR) && rm -f *~
+ cd $(ROOTDIR) && rm -f src/*~
++ cd $(ROOTDIR) && rm -f $(PKGCONFIG_FILENAME)
+ @( cd $(ROOTDIR) && if [ -d src/obj ] ; \
+ then cd src/obj && \
+ $(MAKE) -f $(REALMAKEFILE) clean && \
+@@ -76,17 +101,17 @@ veryclean: clean
+ cd $(ROOTDIR) && rm -f wannier90.x postw90.x libwannier.a w90chk2chk.x w90spn2spn.x
+ cd $(ROOTDIR)/doc && rm -f user_guide.pdf tutorial.pdf
+ cd $(ROOTDIR)/doc/user_guide && rm -f user_guide.ps
+- cd $(ROOTDIR)/doc/tutorial && rm -f tutorial.ps
++ cd $(ROOTDIR)/doc/tutorial && rm -f tutorial.ps
+ cd $(ROOTDIR)/test-suite && ./clean_tests -i
+
+ thedoc:
+- $(MAKE) -C $(ROOTDIR)/doc/user_guide
+- $(MAKE) -C $(ROOTDIR)/doc/tutorial
++ $(MAKE) -C $(ROOTDIR)/doc/user_guide
++ $(MAKE) -C $(ROOTDIR)/doc/tutorial
+
+ # For now hardcoded to 3.1.0, and using HEAD
+ # Better to get the version from the io.F90 file and use
+ # the tag (e.g. v3.1.0) instead of HEAD
+-dist:
++dist:
+ cd $(ROOTDIR) && git archive HEAD --prefix=wannier90-3.1.0/ -o wannier90-3.1.0.tar.gz
+
+ dist-legacy:
+@@ -182,10 +207,10 @@ dist-legacy:
+ ./CHANGE.log \
+ )
+
+-test-serial: w90chk2chk wannier post
++test-serial: w90chk2chk wannier post
+ (cd $(ROOTDIR)/test-suite && ./run_tests --category=default )
+
+-test-parallel: w90chk2chk wannier post
++test-parallel: w90chk2chk wannier post
+ (cd $(ROOTDIR)/test-suite && ./run_tests --category=default --numprocs=4 )
+
+ # Alias
+@@ -217,4 +242,4 @@ objdirp:
+ then mkdir src/objp ; \
+ fi ) ;
+
+-.PHONY: wannier default all doc lib libs post clean veryclean thedoc dist test-serial test-parallel dist-lite objdir objdirp serialobjs tests w90spn2spn install
++.PHONY: wannier default all doc lib libs post clean veryclean thedoc dist test-serial test-parallel dist-lite objdir objdirp serialobjs tests w90spn2spn install pkgconfi
diff --git a/wannier90.changes b/wannier90.changes
new file mode 100644
index 0000000..fe73d87
--- /dev/null
+++ b/wannier90.changes
@@ -0,0 +1,18 @@
+-------------------------------------------------------------------
+Tue Aug 2 16:10:45 UTC 2022 - Atri Bhattacharya
+
+- Add patches:
+ * wannier90-install-pkgconfig.patch -- Update Makefile to
+ install a package config file
+ * a75344b646227c9d7f12d90af4a35a902e940dca.patch -- Allocate
+ arrays on non-root nodes to avoid SIGSEG
+ [gh#wannier-developers/wannier90#373]
+ * wannier90-fix-parallel-compilation.patch -- Ignore rank
+ mismatch issues when building openmpi flavours with gfortran,
+ as recommended in upstream bug report
+ [gh#wannier-developers/wannier90#371]
+
+-------------------------------------------------------------------
+Tue Aug 2 13:05:55 UTC 2022 - Atri Bhattacharya
+
+- Initial package.
diff --git a/wannier90.spec b/wannier90.spec
new file mode 100644
index 0000000..3b83f93
--- /dev/null
+++ b/wannier90.spec
@@ -0,0 +1,147 @@
+#
+# spec file for package wannier90
+#
+# Copyright (c) 2022 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 pname wannier90
+
+# SECTION MPI DEFINITIONS
+%if "%{flavor}" == ""
+%define package_name %{pname}
+%endif
+
+%if "%{flavor}" == "openmpi1"
+%global mpi_flavor openmpi
+%define mpi_vers 1
+%endif
+
+%if "%{flavor}" == "openmpi2"
+%global mpi_flavor openmpi
+%define mpi_vers 2
+%endif
+
+%if "%{flavor}" == "openmpi3"
+%global mpi_flavor openmpi
+%define mpi_vers 3
+%endif
+
+%if "%{flavor}" == "openmpi4"
+%global mpi_flavor openmpi
+%define mpi_vers 4
+%endif
+
+%{?mpi_flavor:%{bcond_without mpi}}%{!?mpi_flavor:%{bcond_with mpi}}
+%{?with_mpi:%{!?mpi_flavor:error "No MPI family specified!"}}
+
+%if %{with mpi}
+%define my_prefix %{_libdir}/mpi/gcc/%{mpi_flavor}%{?mpi_vers}
+%define my_bindir %{my_prefix}/bin
+%define my_libdir %{my_prefix}/%{_lib}
+%define my_incdir %{my_prefix}/include
+%define my_datadir %{my_prefix}/share
+%define my_suffix -%{mpi_flavor}%{?mpi_vers}
+%else
+%define my_prefix %{_prefix}
+%define my_bindir %{_bindir}
+%define my_libdir %{_libdir}
+%define my_incdir %{_includedir}
+%define my_datadir %{_datadir}
+%endif
+# /SECTION MPI DEFINITIONS
+
+Name: %{pname}%{?my_suffix}
+Version: 3.1.0
+Release: 0
+Summary: A library for generating maximally-localized Wannier functions
+License: GPL-2.0-only
+URL: http://www.wannier.org/
+Source: https://github.com/wannier-developers/wannier90/archive/refs/tags/v%{version}.tar.gz#/%{pname}-%{version}.tar.gz
+# PATCH-FIX-UPSTREAM wannier90-install-pkgconfig.patch badshah400@gmail.com -- Update Makefile to install a package config file
+Patch0: wannier90-install-pkgconfig.patch
+# PATCH-FIX-UPSTREAM gh#wannier-developers/wannier90#373 badshah400@gmail.com -- Allocate arrays on non-root nodes to avoid SIGSEG
+Patch1: https://github.com/wannier-developers/wannier90/commit/a75344b646227c9d7f12d90af4a35a902e940dca.patch
+# PATCH-FIX-UPSTREAM gh#wannier-developers/wannier90#371 badshah400@gmail.com -- Ignore rank mismatch issues when building openmpi flavours with gfortran, as recommended in upstream bug report
+Patch2: wannier90-fix-parallel-compilation.patch
+BuildRequires: blas-devel
+BuildRequires: gcc-fortran
+BuildRequires: lapack-devel
+%if %{with mpi}
+BuildRequires: %{mpi_flavor}%{?mpi_vers}-devel
+%if 0%{?suse_version} >= 1550 && "%{mpi_flavor}" == "openmpi"
+# hackish workaround for multiple openmpiX-config all providing openmpi-runtime-config
+BuildRequires: %{mpi_flavor}%{?mpi_vers}-config
+%endif
+%endif
+
+
+%description
+Wannier90 is a library for generating maximally-localized Wannier functions and
+using them to compute advanced electronic properties of materials with high
+efficiency and accuracy.
+
+%package devel
+Summary: Devel files for %{name}
+
+%description devel
+This package provides files needed for developing against wannier90.
+
+%prep
+%setup -q -n %{pname}-%{version}
+%patch0 -p1
+%patch1 -p1
+%if 0%{?suse_version} >= 1550
+%patch2 -p1
+%endif
+
+%build
+# No configure script
+cp ./config/make.inc.gfort.dynlib make.inc
+
+%if %{with mpi}
+source %{my_bindir}/mpivars.sh
+sed -i "s/^#COMMS\s*=\s*mpi/COMMS = mpi/" make.inc
+sed -i "s/^#MPIF90\s*=\s*mpgfortran #mpif90/MPIF90 = mpif90/" make.inc
+cat make.inc
+%endif
+
+%make_build all dynlib
+
+%install
+%make_install PREFIX=%{my_prefix} pkgconfig
+
+rm %{buildroot}%{my_prefix}/lib/*.a
+mkdir -p %{buildroot}%{my_libdir}/pkgconfig
+find ./ -name "*.so" -print -exec install {} %{buildroot}%{my_libdir}/ \;
+if [ "%{_lib}" != "lib" ]
+then
+ mv %{buildroot}%{my_prefix}/lib/pkgconfig/*.pc %{buildroot}%{my_libdir}/pkgconfig/
+fi
+sed -i "s|%{buildroot}||g" %{buildroot}%{my_libdir}/pkgconfig/*.pc
+
+%post -p /sbin/ldconfig
+%postun -p /sbin/ldconfig
+
+%files
+%license LICENSE
+%doc CHANGELOG.md README.rst
+%{my_bindir}/*
+
+%files devel
+%{my_libdir}/*.so
+%{my_libdir}/pkgconfig/*.pc
+
+%changelog