[cig-commits] [commit] QA: adds subdirectory tests/ for compilation and unit testing; deallocates temporary arrays in check_valence(); uses cudaMemcpy2D for padded array copies (5a5caf0)

cig_noreply at geodynamics.org cig_noreply at geodynamics.org
Tue Feb 4 06:57:41 PST 2014


Repository : ssh://geoshell/specfem3d

On branch  : QA
Link       : https://github.com/geodynamics/specfem3d/compare/56deeb214ac966cde7e955473d9e61288b16d98f...e38ba401e045bc221ec1099e88d3aa31e7b4773c

>---------------------------------------------------------------

commit 5a5caf03be03a49075690ecc6575a1f7bef96749
Author: daniel peter <peterda at ethz.ch>
Date:   Tue Feb 4 11:17:02 2014 +0100

    adds subdirectory tests/ for compilation and unit testing; deallocates temporary arrays in check_valence(); uses cudaMemcpy2D for padded array copies


>---------------------------------------------------------------

5a5caf03be03a49075690ecc6575a1f7bef96749
 src/cuda/prepare_mesh_constants_cuda.cu            | 123 +++++++++++++++++++++
 src/decompose_mesh/decompose_mesh.F90              |  13 ++-
 tests/compilations/0.configure.serial_make.sh      |  45 ++++++++
 tests/compilations/1.configure.default_make.sh     |  44 ++++++++
 .../2.configure.main_binaries_available.sh         |  42 +++++++
 .../3.configure.supplement_binaries_available.sh   |  48 ++++++++
 tests/decompose_mesh/0.compile.default_make.sh     |  46 ++++++++
 tests/decompose_mesh/1.test_read.sh                |  51 +++++++++
 tests/decompose_mesh/2.test_valence.sh             |  51 +++++++++
 tests/decompose_mesh/DATA                          |   1 +
 tests/decompose_mesh/test_read.f90                 |  66 +++++++++++
 tests/decompose_mesh/test_read.makefile            |  19 ++++
 tests/decompose_mesh/test_valence.f90              | 112 +++++++++++++++++++
 tests/decompose_mesh/test_valence.makefile         |  19 ++++
 tests/generate_databases/0.compile.default_make.sh |  46 ++++++++
 tests/meshfem3D/0.compile.default_make.sh          |  46 ++++++++
 tests/run_all_tests.sh                             |  51 +++++++++
 tests/run_tests.sh                                 | 115 +++++++++++++++++++
 tests/specfem3D/0.compile.default_make.sh          |  46 ++++++++
 19 files changed, 983 insertions(+), 1 deletion(-)

diff --git a/src/cuda/prepare_mesh_constants_cuda.cu b/src/cuda/prepare_mesh_constants_cuda.cu
index 16ccb8f..86687d9 100644
--- a/src/cuda/prepare_mesh_constants_cuda.cu
+++ b/src/cuda/prepare_mesh_constants_cuda.cu
@@ -215,6 +215,8 @@ void FC_FUNC_(prepare_constants_device,
   print_CUDA_error_if_any(cudaMalloc((void**) &mp->d_muv, size_padded*sizeof(realw)),1011);
 
   // transfer constant element data with padding
+  /* 
+  // way 1: slow...
   for(int i=0;i < mp->NSPEC_AB;i++) {
     print_CUDA_error_if_any(cudaMemcpy(mp->d_xix + i*NGLL3_PADDED, &h_xix[i*NGLL3],
                                        NGLL3*sizeof(realw),cudaMemcpyHostToDevice),1501);
@@ -239,6 +241,41 @@ void FC_FUNC_(prepare_constants_device,
     print_CUDA_error_if_any(cudaMemcpy(mp->d_muv+i*NGLL3_PADDED,   &h_muv[i*NGLL3],
                                        NGLL3*sizeof(realw),cudaMemcpyHostToDevice),1511);
   }
+  */
+  // way 2: faster ...
+  print_CUDA_error_if_any(cudaMemcpy2D(mp->d_xix, NGLL3_PADDED*sizeof(realw),
+                                       h_xix, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                       mp->NSPEC_AB, cudaMemcpyHostToDevice),1501);
+  print_CUDA_error_if_any(cudaMemcpy2D(mp->d_xiy, NGLL3_PADDED*sizeof(realw),
+                                       h_xiy, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                       mp->NSPEC_AB, cudaMemcpyHostToDevice),1502);
+  print_CUDA_error_if_any(cudaMemcpy2D(mp->d_xiz, NGLL3_PADDED*sizeof(realw),
+                                       h_xiz, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                       mp->NSPEC_AB, cudaMemcpyHostToDevice),1503);
+  print_CUDA_error_if_any(cudaMemcpy2D(mp->d_etax, NGLL3_PADDED*sizeof(realw),
+                                       h_etax, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                       mp->NSPEC_AB, cudaMemcpyHostToDevice),1504);
+  print_CUDA_error_if_any(cudaMemcpy2D(mp->d_etay, NGLL3_PADDED*sizeof(realw),
+                                       h_etay, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                       mp->NSPEC_AB, cudaMemcpyHostToDevice),1505);
+  print_CUDA_error_if_any(cudaMemcpy2D(mp->d_etaz, NGLL3_PADDED*sizeof(realw),
+                                       h_etaz, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                       mp->NSPEC_AB, cudaMemcpyHostToDevice),1506);
+  print_CUDA_error_if_any(cudaMemcpy2D(mp->d_gammax, NGLL3_PADDED*sizeof(realw),
+                                       h_gammax, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                       mp->NSPEC_AB, cudaMemcpyHostToDevice),1507);
+  print_CUDA_error_if_any(cudaMemcpy2D(mp->d_gammay, NGLL3_PADDED*sizeof(realw),
+                                       h_gammay, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                       mp->NSPEC_AB, cudaMemcpyHostToDevice),1508);
+  print_CUDA_error_if_any(cudaMemcpy2D(mp->d_gammaz, NGLL3_PADDED*sizeof(realw),
+                                       h_gammaz, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                       mp->NSPEC_AB, cudaMemcpyHostToDevice),1509);
+  print_CUDA_error_if_any(cudaMemcpy2D(mp->d_kappav, NGLL3_PADDED*sizeof(realw),
+                                       h_kappav, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                       mp->NSPEC_AB, cudaMemcpyHostToDevice),1510);
+  print_CUDA_error_if_any(cudaMemcpy2D(mp->d_muv, NGLL3_PADDED*sizeof(realw),
+                                       h_muv, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                       mp->NSPEC_AB, cudaMemcpyHostToDevice),1511);
 
   // global indexing
   copy_todevice_int((void**)&mp->d_ibool,h_ibool,NGLL3*(mp->NSPEC_AB));
@@ -401,10 +438,18 @@ void FC_FUNC_(prepare_fields_acoustic_device,
   int size_padded = NGLL3_PADDED * mp->NSPEC_AB;
   print_CUDA_error_if_any(cudaMalloc((void**)&(mp->d_rhostore),size_padded*sizeof(realw)),2006);
   // transfer constant element data with padding
+  /*
+  // way 1: slow...
   for(int i=0; i < mp->NSPEC_AB; i++) {
     print_CUDA_error_if_any(cudaMemcpy(mp->d_rhostore+i*NGLL3_PADDED, &rhostore[i*NGLL3],
                                        NGLL3*sizeof(realw),cudaMemcpyHostToDevice),2106);
   }
+  */
+  // way 2: faster ...
+  print_CUDA_error_if_any(cudaMemcpy2D(mp->d_rhostore, NGLL3_PADDED*sizeof(realw),
+                                       rhostore, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                       mp->NSPEC_AB, cudaMemcpyHostToDevice),2106);
+
 
   // non-padded array
   copy_todevice_realw((void**)&mp->d_kappastore,kappastore,NGLL3*mp->NSPEC_AB);
@@ -783,6 +828,8 @@ void FC_FUNC_(prepare_fields_elastic_device,
     print_CUDA_error_if_any(cudaMalloc((void**)&(mp->d_c66store),size_padded*sizeof(realw)),4720);
 
     // transfer constant element data with padding
+    /*
+    // way 1: slower ...
     for(int i=0;i < mp->NSPEC_AB;i++) {
       print_CUDA_error_if_any(cudaMemcpy(mp->d_c11store + i*NGLL3_PADDED, &c11store[i*NGLL3],
                                          NGLL3*sizeof(realw),cudaMemcpyHostToDevice),4800);
@@ -827,6 +874,74 @@ void FC_FUNC_(prepare_fields_elastic_device,
       print_CUDA_error_if_any(cudaMemcpy(mp->d_c66store + i*NGLL3_PADDED, &c66store[i*NGLL3],
                                          NGLL3*sizeof(realw),cudaMemcpyHostToDevice),4820);
     }
+    */
+    // way 2: faster ...
+    print_CUDA_error_if_any(cudaMemcpy2D(mp->d_c11store, NGLL3_PADDED*sizeof(realw),
+                                         c11store, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                         mp->NSPEC_AB, cudaMemcpyHostToDevice),4800);
+    print_CUDA_error_if_any(cudaMemcpy2D(mp->d_c12store, NGLL3_PADDED*sizeof(realw),
+                                         c12store, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                         mp->NSPEC_AB, cudaMemcpyHostToDevice),4800);
+    print_CUDA_error_if_any(cudaMemcpy2D(mp->d_c13store, NGLL3_PADDED*sizeof(realw),
+                                         c13store, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                         mp->NSPEC_AB, cudaMemcpyHostToDevice),4800);
+    print_CUDA_error_if_any(cudaMemcpy2D(mp->d_c14store, NGLL3_PADDED*sizeof(realw),
+                                         c14store, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                         mp->NSPEC_AB, cudaMemcpyHostToDevice),4800);
+    print_CUDA_error_if_any(cudaMemcpy2D(mp->d_c15store, NGLL3_PADDED*sizeof(realw),
+                                         c15store, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                         mp->NSPEC_AB, cudaMemcpyHostToDevice),4800);
+    print_CUDA_error_if_any(cudaMemcpy2D(mp->d_c16store, NGLL3_PADDED*sizeof(realw),
+                                         c16store, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                         mp->NSPEC_AB, cudaMemcpyHostToDevice),4800);
+    print_CUDA_error_if_any(cudaMemcpy2D(mp->d_c22store, NGLL3_PADDED*sizeof(realw),
+                                         c22store, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                         mp->NSPEC_AB, cudaMemcpyHostToDevice),4800);
+    print_CUDA_error_if_any(cudaMemcpy2D(mp->d_c23store, NGLL3_PADDED*sizeof(realw),
+                                         c23store, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                         mp->NSPEC_AB, cudaMemcpyHostToDevice),4800);
+    print_CUDA_error_if_any(cudaMemcpy2D(mp->d_c24store, NGLL3_PADDED*sizeof(realw),
+                                         c24store, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                         mp->NSPEC_AB, cudaMemcpyHostToDevice),4800);
+    print_CUDA_error_if_any(cudaMemcpy2D(mp->d_c25store, NGLL3_PADDED*sizeof(realw),
+                                         c25store, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                         mp->NSPEC_AB, cudaMemcpyHostToDevice),4800);
+    print_CUDA_error_if_any(cudaMemcpy2D(mp->d_c26store, NGLL3_PADDED*sizeof(realw),
+                                         c26store, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                         mp->NSPEC_AB, cudaMemcpyHostToDevice),4800);
+    print_CUDA_error_if_any(cudaMemcpy2D(mp->d_c33store, NGLL3_PADDED*sizeof(realw),
+                                         c33store, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                         mp->NSPEC_AB, cudaMemcpyHostToDevice),4800);
+    print_CUDA_error_if_any(cudaMemcpy2D(mp->d_c34store, NGLL3_PADDED*sizeof(realw),
+                                         c34store, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                         mp->NSPEC_AB, cudaMemcpyHostToDevice),4800);
+    print_CUDA_error_if_any(cudaMemcpy2D(mp->d_c35store, NGLL3_PADDED*sizeof(realw),
+                                         c35store, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                         mp->NSPEC_AB, cudaMemcpyHostToDevice),4800);
+    print_CUDA_error_if_any(cudaMemcpy2D(mp->d_c36store, NGLL3_PADDED*sizeof(realw),
+                                         c36store, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                         mp->NSPEC_AB, cudaMemcpyHostToDevice),4800);
+    print_CUDA_error_if_any(cudaMemcpy2D(mp->d_c44store, NGLL3_PADDED*sizeof(realw),
+                                         c44store, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                         mp->NSPEC_AB, cudaMemcpyHostToDevice),4800);
+    print_CUDA_error_if_any(cudaMemcpy2D(mp->d_c45store, NGLL3_PADDED*sizeof(realw),
+                                         c45store, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                         mp->NSPEC_AB, cudaMemcpyHostToDevice),4800);
+    print_CUDA_error_if_any(cudaMemcpy2D(mp->d_c46store, NGLL3_PADDED*sizeof(realw),
+                                         c46store, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                         mp->NSPEC_AB, cudaMemcpyHostToDevice),4800);
+    print_CUDA_error_if_any(cudaMemcpy2D(mp->d_c55store, NGLL3_PADDED*sizeof(realw),
+                                         c55store, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                         mp->NSPEC_AB, cudaMemcpyHostToDevice),4800);
+    print_CUDA_error_if_any(cudaMemcpy2D(mp->d_c56store, NGLL3_PADDED*sizeof(realw),
+                                         c56store, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                         mp->NSPEC_AB, cudaMemcpyHostToDevice),4800);
+    print_CUDA_error_if_any(cudaMemcpy2D(mp->d_c66store, NGLL3_PADDED*sizeof(realw),
+                                         c66store, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                         mp->NSPEC_AB, cudaMemcpyHostToDevice),4800);
+
+
+    
   }
 
   // ocean load approximation
@@ -1191,10 +1306,18 @@ void FC_FUNC_(prepare_fields_gravity_device,
       // padded array
       print_CUDA_error_if_any(cudaMalloc((void**)&(mp->d_rhostore),size_padded*sizeof(realw)),8006);
       // transfer constant element data with padding
+      /*
+      // way 1: slower ...
       for(int i=0; i < mp->NSPEC_AB; i++) {
         print_CUDA_error_if_any(cudaMemcpy(mp->d_rhostore+i*NGLL3_PADDED, &rhostore[i*NGLL3],
                                            NGLL3*sizeof(realw),cudaMemcpyHostToDevice),8007);
       }
+      */
+      // way 2: faster...
+      print_CUDA_error_if_any(cudaMemcpy2D(mp->d_rhostore, NGLL3_PADDED*sizeof(realw),
+                                           rhostore, NGLL3*sizeof(realw), NGLL3*sizeof(realw),
+                                           mp->NSPEC_AB, cudaMemcpyHostToDevice),4800);
+      
     }
   }
 
diff --git a/src/decompose_mesh/decompose_mesh.F90 b/src/decompose_mesh/decompose_mesh.F90
index 14ba48c..193ef57 100644
--- a/src/decompose_mesh/decompose_mesh.F90
+++ b/src/decompose_mesh/decompose_mesh.F90
@@ -731,29 +731,40 @@ module decompose_mesh
 
   subroutine check_valence
 
+    implicit none
+
+    ! allocates temporary arrays
     allocate(mask_nodes_elmnts(nnodes),stat=ier)
     if( ier /= 0 ) stop 'error allocating array mask_nodes_elmnts'
     allocate(used_nodes_elmnts(nnodes),stat=ier)
     if( ier /= 0 ) stop 'error allocating array used_nodes_elmnts'
+
     mask_nodes_elmnts(:) = .false.
     used_nodes_elmnts(:) = 0
+
     do ispec = 1, nspec
       do inode = 1, NGNOD
         mask_nodes_elmnts(elmnts(inode,ispec)) = .true.
         used_nodes_elmnts(elmnts(inode,ispec)) = used_nodes_elmnts(elmnts(inode,ispec)) + 1
       enddo
     enddo
+
     print *, 'node valence:'
     print *, '  min = ',minval(used_nodes_elmnts(:)),' max = ', maxval(used_nodes_elmnts(:))
+
     do inode = 1, nnodes
       if (.not. mask_nodes_elmnts(inode)) then
         stop 'ERROR: found some unused nodes (weird, but not necessarily fatal; your mesher may have created extra nodes).'
       endif
     enddo
 
-! max number of elements that contain the same node
+    ! max number of elements that contain the same node
     nsize = maxval(used_nodes_elmnts(:))
 
+    ! frees temporary arrays
+    deallocate(mask_nodes_elmnts)
+    deallocate(used_nodes_elmnts)
+
 ! majoration (overestimate) of the maximum number of neighbours per element
 !! DK DK nfaces is a constant equal to 6 (number of faces of a cube).
 !! DK DK I have no idea how this formula works; it was designed by Nicolas Le Goff
diff --git a/tests/compilations/0.configure.serial_make.sh b/tests/compilations/0.configure.serial_make.sh
new file mode 100755
index 0000000..d6ba109
--- /dev/null
+++ b/tests/compilations/0.configure.serial_make.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+testdir=`pwd`
+
+# sets source directory
+cd $ROOT/
+srcdir=`pwd`
+
+cd $testdir/
+
+# title
+echo >> $testdir/results.log
+echo "configure.0.serial_make in: $testdir" >> $testdir/results.log
+echo >> $testdir/results.log
+
+#cleanup
+rm -rf config.log config.status
+rm -rf ./bin ./obj ./setup ./OUTPUT_FILES ./DATA
+
+# default configuration for serial version (without MPI)
+# (out-of-source compilation)
+$srcdir/configure --without-mpi >> $testdir/results.log 2>&1
+
+# checks exit code
+if [[ $? -ne 0 ]]; then
+  echo >> $testdir/results.log
+  echo "configuration failed, please check..." >> $testdir/results.log
+  exit 1
+fi
+
+# default all compilation
+make clean >> $testdir/results.log 2>&1
+
+# parallel make
+make -j 4 all >> $testdir/results.log 2>&1
+
+# checks exit code
+if [[ $? -ne 0 ]]; then
+  echo >> $testdir/results.log
+  echo "compilation failed, please check..." >> $testdir/results.log
+  exit 1
+fi
+
+
+echo "successful compilation" >> $testdir/results.log
+
diff --git a/tests/compilations/1.configure.default_make.sh b/tests/compilations/1.configure.default_make.sh
new file mode 100755
index 0000000..9b381bd
--- /dev/null
+++ b/tests/compilations/1.configure.default_make.sh
@@ -0,0 +1,44 @@
+#!/bin/bash
+testdir=`pwd`
+
+# sets source directory
+cd $ROOT/
+srcdir=`pwd`
+
+cd $testdir/
+
+# title
+echo >> $testdir/results.log
+echo "configure.0.default_make in: $testdir" >> $testdir/results.log
+echo >> $testdir/results.log
+
+#cleanup
+rm -rf config.log config.status
+rm -rf ./bin ./obj ./setup ./OUTPUT_FILES ./DATA
+
+# default configuration
+# (out-of-source compilation)
+$srcdir/configure >> $testdir/results.log 2>&1
+
+# checks exit code
+if [[ $? -ne 0 ]]; then
+  echo >> $testdir/results.log
+  echo "configuration failed, please check..." >> $testdir/results.log
+  exit 1
+fi
+
+# default all compilation
+make clean >> $testdir/results.log 2>&1
+
+# parallel make
+make -j 4 all >> $testdir/results.log 2>&1
+
+# checks exit code
+if [[ $? -ne 0 ]]; then
+  echo >> $testdir/results.log
+  echo "compilation failed, please check..." >> $testdir/results.log
+  exit 1
+fi
+
+echo "successful compilation" >> $testdir/results.log
+
diff --git a/tests/compilations/2.configure.main_binaries_available.sh b/tests/compilations/2.configure.main_binaries_available.sh
new file mode 100755
index 0000000..182d44c
--- /dev/null
+++ b/tests/compilations/2.configure.main_binaries_available.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+testdir=`pwd`
+
+# sets source directory
+cd $ROOT/
+srcdir=`pwd`
+
+cd $testdir/
+
+# title
+echo >> $testdir/results.log
+echo "configure.1" >> $testdir/results.log
+echo >> $testdir/results.log
+
+
+echo "directory: `pwd`" >> $testdir/results.log
+
+# default configuration
+#$srcdir/configure >> $testdir/results.log 2>&1
+
+# checks if all main executables exist
+echo "checking if main binaries exist" >> $testdir/results.log
+exec=( xdecompose_mesh xmeshfem3D xgenerate_databases xspecfem3D )
+for var in ${exec[@]};
+do
+  # single compilation
+  #echo "compilation: $var" >> $testdir/results.log
+  #make clean >> $testdir/results.log 2>&1
+  #make -j 4 $var >> $testdir/results.log 2>&1
+
+  # check
+  if [ ! -e bin/$var ]; then 
+    echo "compilation of $var failed, please check..." >> $testdir/results.log
+    exit 1
+  else
+    echo "binary exists: $var" >> $testdir/results.log
+  fi
+done
+
+cd $testdir/
+echo "successful compilation" >> $testdir/results.log
+
diff --git a/tests/compilations/3.configure.supplement_binaries_available.sh b/tests/compilations/3.configure.supplement_binaries_available.sh
new file mode 100755
index 0000000..dc59c74
--- /dev/null
+++ b/tests/compilations/3.configure.supplement_binaries_available.sh
@@ -0,0 +1,48 @@
+#!/bin/bash
+testdir=`pwd`
+
+# sets source directory
+cd $ROOT/
+srcdir=`pwd`
+
+cd $testdir/
+
+# title
+echo >> $testdir/results.log
+echo "configure.2" >> $testdir/results.log
+echo >> $testdir/results.log
+
+echo "directory: `pwd`" >> $testdir/results.log
+
+# default configuration
+#$srcdir/configure >> $testdir/results.log 2>&1
+
+# checks if all supplement executables exist
+echo "checking if supplement binaries exist" >> $testdir/results.log
+exec=( xcombine_surf_data xcombine_vol_data \
+       xconvolve_source_timefunction \
+       xcreate_movie_shakemap_AVS_DX_GMT \
+       xmodel_update \
+       xsmooth_vol_data \
+       xsum_kernels \
+       xcheck_mesh_quality_CUBIT_Abaqus \
+       xconvert_skewness_to_angle \
+       xmultiply_CUBIT_Abaqus_mesh_by_1000 )
+for var in ${exec[@]};
+do
+  # single compilation
+  #echo "compilation: $var" >> $testdir/results.log
+  #make clean >> $testdir/results.log 2>&1
+  #make -j 4 $var >> $testdir/results.log 2>&1
+
+  # check
+  if [ ! -e bin/$var ]; then 
+    echo "compilation of $var failed, please check..." >> $testdir/results.log
+    exit 1
+  else
+    echo "binary exists: $var" >> $testdir/results.log
+  fi
+done
+
+echo "successful compilation" >> $testdir/results.log
+
diff --git a/tests/decompose_mesh/0.compile.default_make.sh b/tests/decompose_mesh/0.compile.default_make.sh
new file mode 100755
index 0000000..020a20a
--- /dev/null
+++ b/tests/decompose_mesh/0.compile.default_make.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+testdir=`pwd`
+
+#checks if ROOT valid
+if [ -z "${ROOT}" ]; then export ROOT=../../ ; fi
+
+# sets source directory
+cd $ROOT/
+srcdir=`pwd`
+
+cd $testdir/
+
+# title
+echo >> $testdir/results.log
+echo "compile default make" >> $testdir/results.log
+echo >> $testdir/results.log
+
+echo "directory: `pwd`" >> $testdir/results.log
+
+#cleanup
+rm -rf config.log config.status
+rm -rf ./bin ./obj ./setup ./OUTPUT_FILES
+
+# default configuration
+$srcdir/configure >> $testdir/results.log 2>&1
+
+# single compilation
+echo "compilation: xdecompose_mesh" >> $testdir/results.log
+make clean >> $testdir/results.log 2>&1
+
+var=xdecompose_mesh
+make -j 4 $var >> $testdir/results.log 2>&1
+
+# check
+if [ ! -e bin/$var ]; then
+  echo "compilation of $var failed, please check..." >> $testdir/results.log
+  exit 1
+else
+  echo "binary exists: $var" >> $testdir/results.log
+fi
+
+#cleanup
+rm -rf ./bin/* 
+
+echo "successful compilation" >> $testdir/results.log
+
diff --git a/tests/decompose_mesh/1.test_read.sh b/tests/decompose_mesh/1.test_read.sh
new file mode 100755
index 0000000..9e73ff3
--- /dev/null
+++ b/tests/decompose_mesh/1.test_read.sh
@@ -0,0 +1,51 @@
+#!/bin/bash
+testdir=`pwd`
+
+# executable
+var=test_read
+
+# title
+echo >> $testdir/results.log
+echo "test: $var" >> $testdir/results.log
+echo >> $testdir/results.log
+
+echo "directory: `pwd`" >> $testdir/results.log
+
+# clean
+mkdir -p bin
+rm -f ./bin/$var
+
+# single compilation
+echo "compilation: $var" >> $testdir/results.log
+
+make -f $var.makefile $var >> $testdir/results.log 2>&1
+
+# check
+if [ ! -e ./bin/$var ]; then
+  echo "compilation of $var failed, please check..." >> $testdir/results.log
+  exit 1
+fi
+
+# runs test
+echo "run: `date`" >> $testdir/results.log
+cd bin/
+./$var >> $testdir/results.log 2>$testdir/error.log
+
+# checks exit code
+if [[ $? -ne 0 ]]; then
+  exit 1
+fi
+
+# checks error output (note: fortran stop returns with a zero-exit code)
+if [[ -s $testdir/error.log ]]; then
+  echo "returned ERROR output:" >> $testdir/results.log
+  cat $testdir/error.log >> $testdir/results.log
+  exit 1
+fi
+rm -f $testdir/error.log
+
+cd ../
+#cleanup
+rm -f bin/$var
+# done
+echo "successfully tested: `date`" >> $testdir/results.log
diff --git a/tests/decompose_mesh/2.test_valence.sh b/tests/decompose_mesh/2.test_valence.sh
new file mode 100755
index 0000000..cd2f263
--- /dev/null
+++ b/tests/decompose_mesh/2.test_valence.sh
@@ -0,0 +1,51 @@
+#!/bin/bash
+testdir=`pwd`
+
+# executable
+var=test_valence
+
+# title
+echo >> $testdir/results.log
+echo "test: $var" >> $testdir/results.log
+echo >> $testdir/results.log
+
+echo "directory: `pwd`" >> $testdir/results.log
+
+# clean
+mkdir -p bin
+rm -f ./bin/$var
+
+# single compilation
+echo "compilation: $var" >> $testdir/results.log
+
+make -f $var.makefile $var >> $testdir/results.log 2>&1
+
+# check
+if [ ! -e ./bin/$var ]; then
+  echo "compilation of $var failed, please check..." >> $testdir/results.log
+  exit 1
+fi
+
+# runs test
+echo "run: `date`" >> $testdir/results.log
+cd bin/
+./$var >> $testdir/results.log 2>$testdir/error.log
+
+# checks exit code
+if [[ $? -ne 0 ]]; then
+  exit 1
+fi
+
+# checks error output (note: fortran stop returns with a zero-exit code)
+if [[ -s $testdir/error.log ]]; then
+  echo "returned ERROR output:" >> $testdir/results.log
+  cat $testdir/error.log >> $testdir/results.log
+  exit 1
+fi
+rm -f $testdir/error.log
+
+cd ../
+#cleanup
+rm -f bin/$var
+# done
+echo "successfully tested: `date`" >> $testdir/results.log
diff --git a/tests/decompose_mesh/DATA b/tests/decompose_mesh/DATA
new file mode 120000
index 0000000..9b1196b
--- /dev/null
+++ b/tests/decompose_mesh/DATA
@@ -0,0 +1 @@
+../../DATA/
\ No newline at end of file
diff --git a/tests/decompose_mesh/test_read.f90 b/tests/decompose_mesh/test_read.f90
new file mode 100644
index 0000000..e0dfa93
--- /dev/null
+++ b/tests/decompose_mesh/test_read.f90
@@ -0,0 +1,66 @@
+program test_read
+
+  use decompose_mesh
+
+  implicit none
+
+  ! reads ../DATA/Par_file
+  call read_parameter_file(NPROC,NTSTEP_BETWEEN_OUTPUT_SEISMOS,NSTEP,DT,NGNOD,NGNOD2D, &
+                          UTM_PROJECTION_ZONE,SUPPRESS_UTM_PROJECTION,TOMOGRAPHY_PATH, &
+                          ATTENUATION,USE_OLSEN_ATTENUATION,LOCAL_PATH,NSOURCES, &
+                          APPROXIMATE_OCEAN_LOAD,TOPOGRAPHY,ANISOTROPY,STACEY_ABSORBING_CONDITIONS,MOVIE_TYPE, &
+                          MOVIE_SURFACE,MOVIE_VOLUME,CREATE_SHAKEMAP,SAVE_DISPLACEMENT, &
+                          NTSTEP_BETWEEN_FRAMES,USE_HIGHRES_FOR_MOVIES,HDUR_MOVIE, &
+                          SAVE_MESH_FILES,PRINT_SOURCE_TIME_FUNCTION, &
+                          NTSTEP_BETWEEN_OUTPUT_INFO,SIMULATION_TYPE,SAVE_FORWARD, &
+                          NTSTEP_BETWEEN_READ_ADJSRC,NOISE_TOMOGRAPHY, &
+                          USE_FORCE_POINT_SOURCE,STACEY_INSTEAD_OF_FREE_SURFACE, &
+                          USE_RICKER_TIME_FUNCTION,OLSEN_ATTENUATION_RATIO,PML_CONDITIONS, &
+                          PML_INSTEAD_OF_FREE_SURFACE,f0_FOR_PML,IMODEL,FULL_ATTENUATION_SOLID,TRAC_PATH)
+
+  ! punctual check of values for given default Par_file in SPECFEM3D/DATA/ directory
+  print*,'NPROC = ',NPROC
+  if( NPROC /= 4 ) then
+    print*,'ERROR: NPROC value invalid'
+    stop 1
+  else
+    print*,'  result is correct'
+  endif
+
+  print*,'NSTEP = ',NSTEP
+  if( NSTEP /= 200 ) then
+    print*,'ERROR: NSTEP value invalid'
+    stop 1
+  else
+    print*,'  result is correct'
+  endif
+
+  print*,'DT = ',DT
+  if( abs(DT - 0.03) > 1.e-9 ) then
+    print*,'ERROR: DT value invalid'
+    stop 1
+  else
+    print*,'  result is correct'
+  endif
+
+  print*,'NTSTEP_BETWEEN_OUTPUT_INFO = ',NTSTEP_BETWEEN_OUTPUT_INFO
+  if( NTSTEP_BETWEEN_OUTPUT_INFO /= 100 ) then
+    print*,'ERROR: NPROC value invalid'
+    stop 1
+  else
+    print*,'  result is correct'
+  endif
+
+  print*,'USE_RICKER_TIME_FUNCTION = ',USE_RICKER_TIME_FUNCTION
+  if( USE_RICKER_TIME_FUNCTION .neqv. .false. ) then
+    print*,'ERROR: NPROC value invalid'
+    stop 1
+  else
+    print*,'  result is correct'
+  endif
+
+  ! done
+  print*,'test_read done successfully'
+
+end program test_read
+
diff --git a/tests/decompose_mesh/test_read.makefile b/tests/decompose_mesh/test_read.makefile
new file mode 100644
index 0000000..1712f5a
--- /dev/null
+++ b/tests/decompose_mesh/test_read.makefile
@@ -0,0 +1,19 @@
+# includes default Makefile from previous configuration
+include Makefile
+
+# test target
+default: test_read
+
+OBJECTS = \
+	./obj/decompose_mesh.dec.o \
+	./obj/fault_scotch.dec.o \
+	./obj/part_decompose_mesh.dec.o \
+	./obj/get_value_parameters.shared.o \
+	./obj/param_reader.cc.o \
+	./obj/read_parameter_file.shared.o \
+	./obj/read_value_parameters.shared.o \
+	$(EMPTY_MACRO)
+
+test_read:
+	${FC} -o ./bin/test_read test_read.f90 -I./obj $(OBJECTS) $(SCOTCH_LIBS)
+
diff --git a/tests/decompose_mesh/test_valence.f90 b/tests/decompose_mesh/test_valence.f90
new file mode 100644
index 0000000..9f178ba
--- /dev/null
+++ b/tests/decompose_mesh/test_valence.f90
@@ -0,0 +1,112 @@
+program test_valence
+
+  use decompose_mesh
+
+  implicit none
+  integer :: i
+
+  print*,'program: test_valence'
+
+  ! ficticious setup 1
+  print*,'test 1:'
+  print*,'-------'
+  nspec = 12
+  NGNOD = 8
+
+  ! allocates mesh elements
+  allocate(elmnts(NGNOD,nspec),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array elmnts'
+  elmnts(:,:) = 0
+
+  print*,'nspec  = ',nspec
+  print*,'NGNOD  = ',NGNOD
+
+  ! element ids
+  inode = 0
+  do ispec = 1,nspec
+    do i = 1,NGNOD
+      inode = inode + 1
+      elmnts(i,ispec) = inode
+    enddo
+  enddo
+
+  nnodes = inode
+  print*,'nnodes = ',nnodes
+
+  ! initializes
+  nsize = -1
+
+  ! valence routine
+  call check_valence()
+
+  ! checks
+  print*,'nsize = ',nsize
+  if( nsize /= 1 ) then
+    print*,'error valence: nsize =',nsize,'should be 1'
+    stop 1
+  else
+    print*,'  result is correct'
+  endif
+
+  deallocate(elmnts)
+
+  ! ficticious setup 2
+  print*,'test 2:'
+  print*,'-------'
+  nspec = 12
+  NGNOD = 27
+
+  ! allocates mesh elements
+  allocate(elmnts(NGNOD,nspec),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array elmnts'
+  elmnts(:,:) = 0
+  print*,'nspec  = ',nspec
+  print*,'NGNOD  = ',NGNOD
+
+  ! element ids
+  inode = 0
+  do ispec = 1,nspec
+    do i = 1,NGNOD
+      ! connects arbitrary nodes
+      if( ispec == 3 .and. i == 3) then
+        elmnts(i,ispec) = 2
+      else if( ispec == 4 .and. i == 9) then
+        elmnts(i,ispec) = 2
+      else if( ispec == 5 .and. i == 12) then
+        elmnts(i,ispec) = 2
+      else if( ispec == 9 .and. i == 17) then
+        elmnts(i,ispec) = 2
+      else if( ispec == 12 .and. i == 27) then
+        elmnts(i,ispec) = 2
+      else
+        inode = inode + 1
+        elmnts(i,ispec) = inode
+      endif
+    enddo
+  enddo
+
+  nnodes = inode
+  print*,'nnodes = ',nnodes
+
+  ! initializes
+  nsize = -1
+
+  ! valence routine
+  call check_valence()
+
+  ! checks
+  print*,'nsize = ',nsize
+  if( nsize /= 6 ) then
+    print*,'error valence: nsize =',nsize,'should be 6'
+    stop 1
+  else
+    print*,'  result is correct'
+  endif
+
+  deallocate(elmnts)
+
+  ! done
+  print*,'test_valence done successfully'
+
+end program test_valence
+
diff --git a/tests/decompose_mesh/test_valence.makefile b/tests/decompose_mesh/test_valence.makefile
new file mode 100644
index 0000000..5e46f8e
--- /dev/null
+++ b/tests/decompose_mesh/test_valence.makefile
@@ -0,0 +1,19 @@
+# includes default Makefile from previous configuration
+include Makefile
+
+# test target
+default: test_valence
+
+OBJECTS = \
+	./obj/decompose_mesh.dec.o \
+	./obj/fault_scotch.dec.o \
+	./obj/part_decompose_mesh.dec.o \
+	./obj/get_value_parameters.shared.o \
+	./obj/param_reader.cc.o \
+	./obj/read_parameter_file.shared.o \
+	./obj/read_value_parameters.shared.o \
+	$(EMPTY_MACRO)
+
+test_valence:
+	${FC} -o ./bin/test_valence test_valence.f90 -I./obj $(OBJECTS) $(SCOTCH_LIBS)
+
diff --git a/tests/generate_databases/0.compile.default_make.sh b/tests/generate_databases/0.compile.default_make.sh
new file mode 100755
index 0000000..86327d8
--- /dev/null
+++ b/tests/generate_databases/0.compile.default_make.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+testdir=`pwd`
+
+#checks if ROOT valid
+if [ -z "${ROOT}" ]; then export ROOT=../../ ; fi
+
+# sets source directory
+cd $ROOT/
+srcdir=`pwd`
+
+cd $testdir/
+
+# title
+echo >> $testdir/results.log
+echo "compile default make" >> $testdir/results.log
+echo >> $testdir/results.log
+
+echo "directory: `pwd`" >> $testdir/results.log
+
+#cleanup
+rm -rf config.log config.status
+rm -rf ./bin ./obj ./setup ./OUTPUT_FILES
+
+# default configuration
+$srcdir/configure >> $testdir/results.log 2>&1
+
+# single compilation
+echo "compilation: xdecompose_mesh" >> $testdir/results.log
+make clean >> $testdir/results.log 2>&1
+
+var=xgenerate_databases
+make -j 4 $var >> $testdir/results.log 2>&1
+
+# check
+if [ ! -e bin/$var ]; then
+  echo "compilation of $var failed, please check..." >> $testdir/results.log
+  exit 1
+else
+  echo "binary exists: $var" >> $testdir/results.log
+fi
+
+#cleanup
+rm -rf ./bin/* 
+
+echo "successful compilation" >> $testdir/results.log
+
diff --git a/tests/meshfem3D/0.compile.default_make.sh b/tests/meshfem3D/0.compile.default_make.sh
new file mode 100755
index 0000000..bd232d6
--- /dev/null
+++ b/tests/meshfem3D/0.compile.default_make.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+testdir=`pwd`
+
+#checks if ROOT valid
+if [ -z "${ROOT}" ]; then export ROOT=../../ ; fi
+
+# sets source directory
+cd $ROOT/
+srcdir=`pwd`
+
+cd $testdir/
+
+# title
+echo >> $testdir/results.log
+echo "compile default make" >> $testdir/results.log
+echo >> $testdir/results.log
+
+echo "directory: `pwd`" >> $testdir/results.log
+
+#cleanup
+rm -rf config.log config.status
+rm -rf ./bin ./obj ./setup ./OUTPUT_FILES
+
+# default configuration
+$srcdir/configure >> $testdir/results.log 2>&1
+
+# single compilation
+echo "compilation: xdecompose_mesh" >> $testdir/results.log
+make clean >> $testdir/results.log 2>&1
+
+var=xmeshfem3D
+make -j 4 $var >> $testdir/results.log 2>&1
+
+# check
+if [ ! -e bin/$var ]; then
+  echo "compilation of $var failed, please check..." >> $testdir/results.log
+  exit 1
+else
+  echo "binary exists: $var" >> $testdir/results.log
+fi
+
+#cleanup
+rm -rf ./bin/* 
+
+echo "successful compilation" >> $testdir/results.log
+
diff --git a/tests/run_all_tests.sh b/tests/run_all_tests.sh
new file mode 100755
index 0000000..11f1ceb
--- /dev/null
+++ b/tests/run_all_tests.sh
@@ -0,0 +1,51 @@
+#!/bin/bash
+
+# directories
+dir=`pwd`
+
+# changes to subdirectory tests/ if called in root directory SPECFEM3D/
+currentdir=`basename $dir`
+echo "current directory: $currentdir"
+if [ "$currentdir" == "SPECFEM3D" ]; then
+cd tests/
+dir=`pwd`
+fi
+
+# running tests
+echo "all tests"
+echo "`date`"
+echo  
+echo "directory: $dir"
+echo 
+
+# loops over subdirectories
+for testdir in ./*/
+do
+  testdir=${testdir%*/}
+
+  if [[ "$testdir" == *buildbot* ]]; then
+    # skips this test directory
+    :
+  else
+    # runs all bash scripts in test-subdirectory
+    ./run_tests.sh $testdir
+
+    # checks exit code
+    if [[ $? -ne 0 ]]; then
+      dir=`basename $testdir`
+      echo "ERROR"
+      echo "ERROR test failed, please check file results.log in tests/$dir"
+      echo "ERROR"
+      exit 1
+    fi
+
+    cd $dir/
+
+  fi
+  
+done
+
+echo
+echo "all tests completed"
+echo "`date`"
+echo
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
new file mode 100755
index 0000000..bbe2009
--- /dev/null
+++ b/tests/run_tests.sh
@@ -0,0 +1,115 @@
+#!/bin/bash
+#############################################################
+
+# USER parameters
+
+# relative location of SPECFEM3D root directory for tests directories (e.g. SPECFEM3D/tests/compilations)
+export ROOT=../../
+
+# test directory
+testdir=$1
+
+#############################################################
+
+# helper functions
+step() {
+  # output
+  echo -n "$@"
+  STEP_OK=0
+}
+
+try() {
+  # runs command
+  "$@"
+  # Check if command failed and update $STEP_OK if so.
+  local EXIT_CODE=$?
+  if [[ $EXIT_CODE -ne 0 ]]; then
+    STEP_OK=$EXIT_CODE
+    #echo "Command \`$*' failed with exit code $EXIT_CODE."
+  fi
+  return $EXIT_CODE
+}
+
+next() {
+  [[ $STEP_OK -eq 0 ]]  && echo "[  $(tput setaf 2)OK$(tput sgr0)  ]" || echo "[$(tput setaf 1)FAILED$(tput sgr0)]"
+  #echo
+  return $STEP_OK
+}
+
+#############################################################
+
+# checks if argument given
+if [ "$testdir" == "" ]; then echo "usage: ./run_tests.sh testdir[e.g.=compilations]"; exit 1; fi
+
+# changes to subdirectory tests/ if called in root directory SPECFEM3D/
+dir=`pwd`
+currentdir=`basename $dir`
+if [ "$currentdir" == "SPECFEM3D" ]; then
+cd tests/
+fi
+
+# checks if test directory exists
+if [ ! -e $testdir  ]; then
+  #see if argument is e.g. tests/compilations
+  dir=`basename $testdir`
+  if [ ! -e $dir  ]; then
+    echo "test directory given does not exists: $testdir, please check..."
+    exit 1
+  else
+    testdir=$dir
+  fi
+fi
+
+# running tests
+cd $testdir/
+
+#checks if ROOT valid
+if [ ! -e "${ROOT}/src/specfem3D/specfem3D.f90" ]; then echo "please check if ROOT set correctly ..."; exit 1; fi
+
+# user output
+echo "-------------------------------------"
+echo "tests in directory : $testdir "
+echo "-------------------------------------"
+echo "`date`"
+
+# test names
+title="tests in $testdir"
+
+echo "$title" > results.log
+echo "`date`" >> results.log
+echo >> results.log
+
+files=`echo ./*.sh`
+if [ "$files" == "./*.sh" ]; then
+  echo "  directory contains no test-scripts"
+else
+
+  for file in ./*.sh
+  do
+    if [[ "$file" == *run_tests.sh* ]]; then
+      # skips this run script
+      : 
+    else
+      step "  processing $file : "
+      try ./$file
+      next
+
+      # checks exit code
+      if [[ $? -ne 0 ]]; then exit 1; fi
+
+      echo >> results.log
+    fi
+  done
+
+fi
+
+echo >> results.log
+echo "tests completed" >> results.log
+echo "`date`" >> results.log
+
+cd ../
+
+
+#return
+echo
+exit 0
diff --git a/tests/specfem3D/0.compile.default_make.sh b/tests/specfem3D/0.compile.default_make.sh
new file mode 100755
index 0000000..b0c07f1
--- /dev/null
+++ b/tests/specfem3D/0.compile.default_make.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+testdir=`pwd`
+
+#checks if ROOT valid
+if [ -z "${ROOT}" ]; then export ROOT=../../ ; fi
+
+# sets source directory
+cd $ROOT/
+srcdir=`pwd`
+
+cd $testdir/
+
+# title
+echo >> $testdir/results.log
+echo "compile default make" >> $testdir/results.log
+echo >> $testdir/results.log
+
+echo "directory: `pwd`" >> $testdir/results.log
+
+#cleanup
+rm -rf config.log config.status
+rm -rf ./bin ./obj ./setup ./OUTPUT_FILES
+
+# default configuration
+$srcdir/configure >> $testdir/results.log 2>&1
+
+# single compilation
+echo "compilation: xdecompose_mesh" >> $testdir/results.log
+make clean >> $testdir/results.log 2>&1
+
+var=xspecfem3D
+make -j 4 $var >> $testdir/results.log 2>&1
+
+# check
+if [ ! -e bin/$var ]; then
+  echo "compilation of $var failed, please check..." >> $testdir/results.log
+  exit 1
+else
+  echo "binary exists: $var" >> $testdir/results.log
+fi
+
+#cleanup
+rm -rf ./bin/* 
+
+echo "successful compilation" >> $testdir/results.log
+



More information about the CIG-COMMITS mailing list