From 937c04ae94a923ef137225a26da6570afa86ee7c Mon Sep 17 00:00:00 2001
From: Christopher Subich <csubich@uwaterloo.ca>
Date: Thu, 2 Sep 2021 14:12:50 -0400
Subject: [PATCH] Update dependencies to Blitz 1.0.2 and update to new MPI
 standard

This commit updates make_deps.sh to build newer versions of Blitz (1.0)
and fftw (3.3.9).  The 2010 version of Blitz no longer builds with the
newest versions of GCC, and there is no harm in updating FFTW.

The newest versions of Blitz (github head) require cmake to
build, and some systems still in use have old, incompatible versions of
cmake.  Blitz 1.0.2 requires python to complete its build process (some
files are auto-generated).

The new version of Blitz dropped the blitz::Vector type, being
equivalent to a 1-dimensional array, so it was replaced with
blitz::Array<type,1> instead.

Additionally, the Parformer (parallel transpose) code was adjusted to no
longer use MPI_UB to define the upper bound of the array section
datatype.  MPI_UB was deprecated in the MPI-2 standard and removed in
the MPI-3 standard, so SPINS could fail to build with some new MPI
libraries (OpenMPI 4.0.3 is confirmed to break).

Because this commit updates dependencies, the patch version is
incremented.
---
 make_deps.sh      | 16 ++++++++--------
 src/ESolver.cpp   |  1 -
 src/Parformer.cpp |  1 -
 src/Sorter.cpp    |  1 -
 src/Splits.cpp    | 20 +++++++++++++++++---
 src/TArray.cpp    |  1 -
 src/T_util.cpp    |  1 -
 src/VERSION       |  2 +-
 src/gmres.hpp     |  6 +++---
 src/multigrid.cpp |  7 +++----
 10 files changed, 32 insertions(+), 24 deletions(-)

diff --git a/make_deps.sh b/make_deps.sh
index 5c8da67..de423e7 100755
--- a/make_deps.sh
+++ b/make_deps.sh
@@ -70,11 +70,11 @@ if [ ! "$BUILD_BLITZ" = "yes" ]; then
 else
 	echo "Building Blitz++"
 	# Download the Blitz tarball if necessary
-	if [ ! -e "blitz_2010.tgz" ]; then
-      mv redist_libs/blitz_2010.tgz ./
+	if [ ! -e "blitz_1.0.2.tar.gz" ]; then
+		mv redist_libs/blitz_1.0.2.tar.gz ./
 	fi
-	(tar -xzvf blitz_2010.tgz > /dev/null) || (echo "Untar of Blitz FAILED"; exit 1);
-	pushd blitz
+	(tar -xzvf blitz_1.0.2.tar.gz > /dev/null) || (echo "Untar of Blitz FAILED"; exit 1);
+	pushd blitz-1.0.2
 	(./configure --prefix="$CWD" --disable-fortran "${BLITZ_OPTIONS}" > /dev/null) && \
 		(make lib > /dev/null) && \
 		pushd blitz && (make install > /dev/null) && popd  && \
@@ -92,14 +92,14 @@ if [ ! "$BUILD_FFTW" = "yes" ]; then
 else
 	echo "Building FFTW"
 	# Download FFTW if necessary
-	if [ ! -e "fftw-3.3.3.tar.gz" ]; then
-      mv redist_libs/fftw-3.3.3.tar.gz ./
+	if [ ! -e "fftw-3.3.9.tar.gz" ]; then
+      mv redist_libs/fftw-3.3.9.tar.gz ./
 	fi
-	(tar -xzvf fftw-3.3.3.tar.gz > /dev/null)
+	(tar -xzvf fftw-3.3.9.tar.gz > /dev/null)
    if [ 0 -ne $? ]; then
       echo "Untar of FFTW FAILED"; exit 1
    fi
-	pushd fftw-3.3.3
+	pushd fftw-3.3.9
    # The "${FFTW_OPTIONS[@]}" syntax expands FFTW_OPTIONS as an array variable;
    # this allows for multi-word arguments like 'CFLAGS="-O3 --fast-math"' to
    # work properly as a single argument from configure's perspective.
diff --git a/src/ESolver.cpp b/src/ESolver.cpp
index 656e4ea..4eab409 100644
--- a/src/ESolver.cpp
+++ b/src/ESolver.cpp
@@ -1,6 +1,5 @@
 #include "TArray.hpp"
 #include "blitz/array.h"
-#include "blitz/tinyvec-et.h"
 #include "ESolver.hpp"
 #include "gmres_1d_solver.hpp"
 #include "gmres_2d_solver.hpp"
diff --git a/src/Parformer.cpp b/src/Parformer.cpp
index 331a292..383bde7 100644
--- a/src/Parformer.cpp
+++ b/src/Parformer.cpp
@@ -2,7 +2,6 @@
 
 #include "Parformer.hpp"
 #include "Par_util.hpp"
-#include <blitz/tinyvec-et.h>
 #include <stdio.h>
 #include <iostream>
 
diff --git a/src/Sorter.cpp b/src/Sorter.cpp
index 2783692..21b008b 100644
--- a/src/Sorter.cpp
+++ b/src/Sorter.cpp
@@ -10,7 +10,6 @@
 #include <vector>
 #include <algorithm>
 #include <stdlib.h>
-#include <blitz/tinyvec-et.h>
 
 #include "Sorter.hpp"
 
diff --git a/src/Splits.cpp b/src/Splits.cpp
index 1e366be..afb5162 100644
--- a/src/Splits.cpp
+++ b/src/Splits.cpp
@@ -2,7 +2,6 @@
 
 #include <vector>
 #include <blitz/array.h> 
-#include <blitz/tinyvec-et.h>
 #include <stdio.h>
 #include <iostream>
 #include <complex>
@@ -121,7 +120,7 @@ src_temp(0), dst_temp(0), issue_warning(true) {
    rec_types.resize(num_proc);  // make sure our vector can hold everything
 
    for (int i = 0; i < num_proc; i++) {
-      // We'll have to use the MPI_Type_struct syntax, so build arrays:
+      /*// We'll have to use the MPI_Type_struct syntax, so build arrays:
       MPI_Datatype types[2] = {vec_type,MPI_UB};
       int counts[2]; counts[0] = extent_from[i]; counts[1] = 1;
       // Now, set displacements to set the "end" of the datatype a full
@@ -129,8 +128,23 @@ src_temp(0), dst_temp(0), issue_warning(true) {
       MPI_Aint displs[2] = {0,sizeof(T)*sizes[untouched_dim]*sizes[from_dim]};
 
       // And make the type
-      MPI_Type_struct(2,counts,displs,types,&rec_types[i]);
+      MPI_Type_struct(2,counts,displs,types,&rec_types[i]);*/
+		
+		// This code formerly used the MPI_UB marker to define the upper bound
+		// of the derived datatype.  This was deprecated as part of the MPI-2
+		// standard, and it was removed in MPI-3.  The replacement is to use
+		// MPI_Type_create_resized to create a resized type directly.
+		
+		// First, create the multi-vector containing the data:
+		MPI_Datatype multivec;
+		MPI_Type_contiguous(extent_from[i],vec_type,&multivec);
+
+		MPI_Type_create_resized(multivec, 0,  // base type, lower bound
+				sizeof(T)*sizes[untouched_dim]*sizes[from_dim], // extent
+				&rec_types[i]); // new type
+
       MPI_Type_commit(&rec_types[i]);
+		MPI_Type_free(&multivec);
       /* Impelementation note: one optimization possible here is to collapse
          this typelist.  This impelementation makes no assumptions about how
          many part-rows are received per processor, but our default splitting
diff --git a/src/TArray.cpp b/src/TArray.cpp
index 5137e92..d10b09d 100644
--- a/src/TArray.cpp
+++ b/src/TArray.cpp
@@ -1,6 +1,5 @@
 #include "TArray.hpp"
 #include "Plan_holder.hpp"
-#include <blitz/tinyvec-et.h>
 #include <assert.h>
 #include <fftw3.h> // FFTW
 /* Implementation of TArray transform functions for the relevant cases.
diff --git a/src/T_util.cpp b/src/T_util.cpp
index 7503f13..7913ee7 100644
--- a/src/T_util.cpp
+++ b/src/T_util.cpp
@@ -1,7 +1,6 @@
 #include "T_util.hpp"
 #include "TArray.hpp"
 #include <blitz/array.h>
-#include <blitz/tinyvec-et.h>
 #include "Par_util.hpp"
 #include <complex>
 #include <string>
diff --git a/src/VERSION b/src/VERSION
index 2944c9e..882b025 100644
--- a/src/VERSION
+++ b/src/VERSION
@@ -1,3 +1,3 @@
 MAJOR_VERSION=2
 MINOR_VERSION=1
-PATCH_VERSION=6
+PATCH_VERSION=7
diff --git a/src/gmres.hpp b/src/gmres.hpp
index 1499ae3..863eed3 100644
--- a/src/gmres.hpp
+++ b/src/gmres.hpp
@@ -269,8 +269,8 @@ template <class Controller> class GMRES_Solver {
 
          /* Perform the inner iteration */
          /*  First, allocate vectors for residuals and the Krylov basis */
-         blitz::Vector<RType> resid_vec(num_its+1);
-         blitz::Vector<BType> basis_vec(num_its); // Note, these are base 0
+         blitz::Array<RType,1> resid_vec(num_its+1);
+         blitz::Array<BType,1> basis_vec(num_its); // Note, these are base 0
          for (int k = 0; k < num_its; k++) {
             resid_vec(k) = ops->alloc_resid();
             basis_vec(k) = ops->alloc_basis();
@@ -406,7 +406,7 @@ template <class Controller> class GMRES_Solver {
          return my_it-1;
       }
 
-      void build_x(BType out_x, blitz::Vector<BType> & basis_vec,
+      void build_x(BType out_x, blitz::Array<BType,1> & basis_vec,
             blitz::Array<double,1> & rhs_vec, double starting_norm,
             int my_it) {
          /* Now, the Krylov basis is in basis_vec, and the proper multiples are in
diff --git a/src/multigrid.cpp b/src/multigrid.cpp
index 7df6709..4683667 100644
--- a/src/multigrid.cpp
+++ b/src/multigrid.cpp
@@ -3,7 +3,6 @@
 
 #include <blitz/array.h>
 #include <iostream>
-#include <blitz/tinyvec-et.h>
 
 #include "umfpack.h"
 #include "timing.hpp"
@@ -1897,14 +1896,14 @@ void MG_Solver::_cycle(CYCLE_TYPE cycle, Array<double,2> & f, Array<double,2> &
             that the problem is really of size (1+size_x*size_z);
             this doesn't actually fit in u or f.  So, allocate
             static blitz-vectors for the data, if necessary. */
-         static blitz::Vector<double> extra_u(0), extra_f(0);
+         static blitz::Array<double,1> extra_u(0), extra_f(0);
 //         fprintf(stderr,"CG: Input residual\n");
 //         cerr << f;
          if (indefinite_problem) {
 //            fprintf(stderr,"Solving indefinite problem on coarse grid\n");
-            if (extra_u.length() != (size_x*size_z+1))
+            if (extra_u.length(firstDim) != (size_x*size_z+1))
                extra_u.resize(size_x*size_z+1);
-            if (extra_f.length() != (size_x*size_z+1))
+            if (extra_f.length(firstDim) != (size_x*size_z+1))
                extra_f.resize(size_x*size_z+1);
             // Copy the f-problem to extra_f
             
-- 
GitLab