Commit d7b7276b authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Merge branch 'cuda-tuning' into develop

parents cb2000e0 797e663a
Loading
Loading
Loading
Loading
+163 −81
Original line number Diff line number Diff line
#!/bin/bash

dofSize=64
dimension=2;
proportions=1

analyticFunction="exp-bump"
timeFunction="cosinus"
device="host"
threadsNumbers="1 2 4 6"
dimensions="1D 2D 3D"
#dimensions="2D"
sizes1D="16 32 64 128 256 512"
#sizes1D="256"
sizes2D="16 32 64 128 256 512"
#sizes2D="8"
sizes3D="16 32 64 128"
testFunction="exp-bump"
snapshotPeriod=0.5
finalTime=0.5
#solverName="tnl-heat-equation"
solverName="tnl-heat-equation-dbg"
#

setupTestFunction()
{
   testFunction=$1
#   if test x${testFunction} = "xexp-bump";
#   then
      origin=-1.0
      proportions=2.0
      amplitude=1.0
      waveLength=1.0
      waveLengthX=1.0
@@ -20,22 +36,31 @@ phase=0.0
      phaseX=0.0
      phaseY=0.0
      phaseZ=0.0
sigma=1.0
      sigma=0.5
#   fi
}

tnl-grid-setup --dimensions ${dimension} \
setupGrid()
{
   dimensions_=$1
   gridSize=$2
   tnl-grid-setup --dimensions ${dimensions_} \
                  --origin-x ${origin} \
                  --origin-y ${origin} \
                  --origin-z ${origin} \
                  --proportions-x ${proportions} \
                  --proportions-y ${proportions} \
                  --proportions-z ${proportions} \
               --origin-x 0 \
               --origin-y 0 \
               --origin-z 0 \
               --size-x ${dofSize} \
               --size-y ${dofSize} \
               --size-z ${dofSize} \
                  --size-x ${gridSize} \
                  --size-y ${gridSize} \
                  --size-z ${gridSize} 
}

tnl-init --mesh mesh.tnl \
         --test-function ${analyticFunction} \
         --output-file initial.tnl \
setInitialCondition()
{
   testFunction=$1
   tnl-init --test-function ${testFunction} \
            --output-file exact-u.tnl \
            --amplitude ${amplitude} \
            --wave-length ${waveLength} \
            --wave-length-x ${waveLengthX} \
@@ -49,42 +74,99 @@ tnl-init --mesh mesh.tnl \
            --phase-x ${phaseX} \
            --phase-y ${phaseY} \
            --phase-z ${phaseZ} \
             --sigma ${sigma} \
            --sigma ${sigma}
}

solve()
{
   timeDiscretisation=$1
   discreteSolver=$2
   threadsNumber=$3
   ${solverName} --device ${device} \
                 --mesh mesh.tnl \
                 --initial-condition exact-u.tnl \
                 --boundary-conditions-file exact-u.tnl \
                 --time-discretisation ${timeDiscretisation} \
                 --time-step 10 \
                 --time-step-order 2 \
                 --discrete-solver ${discreteSolver} \
                 --merson-adaptivity 1.0e-5 \
                 --sor-omega 1.95 \
                 --gmres-restarting 10 \
                 --min-iterations 20 \
                 --convergence-residue 1.0e-12 \
                 --snapshot-period ${snapshotPeriod} \
                 --final-time ${finalTime} \
                 --refresh-rate 50 \
                 --openmp-enabled true \
                 --openmp-max-threads ${threadsNumber}
}
               
tnl-heat-equation --time-discretisation explicit \
                  --boundary-conditions-type dirichlet \
                  --boundary-conditions-constant 0.5 \
                  --discrete-solver merson \
                  --snapshot-period 0.0005 \
                  --final-time 0.1 \
runTest()
{
   for threadsNumber in ${threadsNumbers};
   do
      mkdir -p threads-${threadsNumber}
      cd threads-${threadsNumber}
      setupTestFunction ${testFunction}
     
tnl-view --mesh mesh.tnl \
         --input-files *.tnl \ 
      
seznam=`ls u-*.gplt`
      for dim in ${dimensions};
      do
         mkdir -p $dim
         cd ${dim}
         if test $dim = 1D;
         then 
            sizes=$sizes1D
         fi
         if test $dim = 2D;
         then 
            sizes=$sizes2D
         fi
         if test $dim = 3D;
         then 
            sizes=$sizes3D
         fi
        
for fname in $seznam ; do
   echo "Drawing $fname"
gnuplot << EOF
    set terminal unknown
    #set view 33,33 #3D
    #unset xtics 
    #unset ytics
    #unset ztics
    unset border
    set output '$fname.png'
    set yrange [-1.2:1.2]
    set zrange [0.4:1.1]    
    set terminal png
    set title "Numerical solution" 
    splot '$fname' with line 
EOF
         lastSize=""
         for size in $sizes;
         do
            mkdir -p $size
            cd $size
            echo ""
            echo ""
            echo ""
            if test ! -f computation-done;
            then
               touch computation-in-progress
               echo "========================================================================="
               echo "===                   SETTING UP THE GRID                             ==="
               echo "========================================================================="
               setupGrid $dim $size 
               echo "========================================================================="
               echo "===                WRITING THE EXACT SOLUTION                         ==="
               echo "========================================================================="
               setInitialCondition $testFunction
               echo "========================================================================="
               echo "===                   STARTING THE SOLVER                             ==="
               echo "========================================================================="
               solve explicit merson ${threadsNumber}
               #solve semi-implicit gmres ${threadsNumber}
               mv computation-in-progress computation-done
            fi            
            echo "========================================================================="
            echo "===                     COMPUTATION DONE                              ==="            
            echo "========================================================================="
            cd ..
            lastSize=$size
         done

         cd ..
      done
      cd ..
   done
}

mencoder "mf://u-*.png" -mf fps=22 -o diffusion.avi -ovc lavc -lavcopts vcodec=mpeg4
runTest
 
#rm *.png
#rm *.tnl         
#rm *.gplt      
+25 −25
Original line number Diff line number Diff line
@@ -17,31 +17,31 @@

namespace TNL {

template< typename T > constexpr T tnlMinValue() { Assert( false, ); return T(); };
template<> constexpr char               tnlMinValue< char >() { return CHAR_MIN; }
template<> constexpr unsigned char      tnlMinValue< unsigned char >() { return 0; }
template<> constexpr short int          tnlMinValue< short int >() { return SHRT_MIN; }
template<> constexpr unsigned short int tnlMinValue< unsigned short int >() { return 0; }
template<> constexpr int                tnlMinValue< int >() { return INT_MIN; }
template<> constexpr unsigned int       tnlMinValue< unsigned int >() { return 0; }
template<> constexpr long int           tnlMinValue< long int >() { return LONG_MIN; }
template<> constexpr unsigned long int  tnlMinValue< unsigned long int >() { return 0; }
template<> constexpr float              tnlMinValue< float >() { return -FLT_MAX; }
template<> constexpr double             tnlMinValue< double >() { return -DBL_MAX; }
template<> constexpr long double        tnlMinValue< long double >() { return -LDBL_MAX; }

template< typename T > constexpr T tnlMaxValue() { Assert( false, ); return T(); };
template<> constexpr char               tnlMaxValue< char >() { return CHAR_MAX; }
template<> constexpr unsigned char      tnlMaxValue< unsigned char >() { return UCHAR_MAX; }
template<> constexpr short int          tnlMaxValue< short int >() { return SHRT_MAX; }
template<> constexpr unsigned short int tnlMaxValue< unsigned short int >() { return USHRT_MAX; }
template<> constexpr int                tnlMaxValue< int >() { return INT_MAX; }
template<> constexpr unsigned int       tnlMaxValue< unsigned int >() { return UINT_MAX; }
template<> constexpr long int           tnlMaxValue< long int >() { return LONG_MAX; }
template<> constexpr unsigned long int  tnlMaxValue< unsigned long int >() { return ULONG_MAX; }
template<> constexpr float              tnlMaxValue< float >() { return FLT_MAX; }
template<> constexpr double             tnlMaxValue< double >() { return DBL_MAX; }
template<> constexpr long double        tnlMaxValue< long double >() { return LDBL_MAX; }
template< typename T > constexpr T MinValue() { return T();};
template<> constexpr char               MinValue< char >() { return CHAR_MIN; }
template<> constexpr unsigned char      MinValue< unsigned char >() { return 0; }
template<> constexpr short int          MinValue< short int >() { return SHRT_MIN; }
template<> constexpr unsigned short int MinValue< unsigned short int >() { return 0; }
template<> constexpr int                MinValue< int >() { return INT_MIN; }
template<> constexpr unsigned int       MinValue< unsigned int >() { return 0; }
template<> constexpr long int           MinValue< long int >() { return LONG_MIN; }
template<> constexpr unsigned long int  MinValue< unsigned long int >() { return 0; }
template<> constexpr float              MinValue< float >() { return -FLT_MAX; }
template<> constexpr double             MinValue< double >() { return -DBL_MAX; }
template<> constexpr long double        MinValue< long double >() { return -LDBL_MAX; }

template< typename T > constexpr T MaxValue() { return T();};
template<> constexpr char               MaxValue< char >() { return CHAR_MAX; }
template<> constexpr unsigned char      MaxValue< unsigned char >() { return UCHAR_MAX; }
template<> constexpr short int          MaxValue< short int >() { return SHRT_MAX; }
template<> constexpr unsigned short int MaxValue< unsigned short int >() { return USHRT_MAX; }
template<> constexpr int                MaxValue< int >() { return INT_MAX; }
template<> constexpr unsigned int       MaxValue< unsigned int >() { return UINT_MAX; }
template<> constexpr long int           MaxValue< long int >() { return LONG_MAX; }
template<> constexpr unsigned long int  MaxValue< unsigned long int >() { return ULONG_MAX; }
template<> constexpr float              MaxValue< float >() { return FLT_MAX; }
template<> constexpr double             MaxValue< double >() { return DBL_MAX; }
template<> constexpr long double        MaxValue< long double >() { return LDBL_MAX; }

} // namespace TNL
+1 −1
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ reduce( Operation& operation,
         return Multireduction< Devices::Host >::reduce( operation, n, size, hostArray1, ldInput1, hostArray2, hostResult );
      }
      else {
         return Multireduction< Devices::Host >::reduce( operation, n, size, hostArray1, ldInput1, nullptr, hostResult );
         return Multireduction< Devices::Host >::reduce( operation, n, size, hostArray1, ldInput1, ( RealType* ) nullptr, hostResult );
      }
   }

+5 −5
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ class tnlParallelReductionMin
      return min( current, data1[ idx ] );
   };

   __cuda_callable__ ResultType initialValue() { return tnlMaxValue< ResultType>(); };
   __cuda_callable__ ResultType initialValue() { return MaxValue< ResultType>(); };
 
   __cuda_callable__ void cudaFirstReduction( ResultType& result,
                                              const IndexType& index,
@@ -120,7 +120,7 @@ class tnlParallelReductionMax
      return max( current, data1[ idx ] );
   };

   __cuda_callable__ ResultType initialValue() { return tnlMinValue< ResultType>(); };
   __cuda_callable__ ResultType initialValue() { return MinValue< ResultType>(); };
 
   __cuda_callable__ void cudaFirstReduction( ResultType& result,
                                              const IndexType& index,
@@ -273,7 +273,7 @@ class tnlParallelReductionAbsMin : public tnlParallelReductionMin< Real, Index >
      return min( current, abs( data1[ idx ] ) );
   };

   __cuda_callable__ ResultType initialValue() { return tnlMaxValue< ResultType>(); };
   __cuda_callable__ ResultType initialValue() { return MaxValue< ResultType>(); };
 
   __cuda_callable__ void cudaFirstReduction( ResultType& result,
                                              const IndexType& index,
@@ -517,7 +517,7 @@ class tnlParallelReductionDiffMin : public tnlParallelReductionMin< Real, Index
      return min( current, data1[ idx ] - data2[ idx ] );
   };

   __cuda_callable__ ResultType initialValue() { return tnlMaxValue< ResultType>(); };
   __cuda_callable__ ResultType initialValue() { return MaxValue< ResultType>(); };
 
   __cuda_callable__ void cudaFirstReduction( ResultType& result,
                                              const IndexType& index,
@@ -604,7 +604,7 @@ class tnlParallelReductionDiffAbsMin : public tnlParallelReductionMin< Real, Ind
      return min( current, abs( data1[ idx ] - data2[ idx ] ) );
   };

   __cuda_callable__ ResultType initialValue() { return tnlMaxValue< ResultType>(); };
   __cuda_callable__ ResultType initialValue() { return MaxValue< ResultType>(); };
 
   __cuda_callable__ void cudaFirstReduction( ResultType& result,
                                              const IndexType& index,
+0 −4
Original line number Diff line number Diff line
@@ -304,8 +304,6 @@ GridEntity( const GridType& grid )
  neighbourEntitiesStorage( *this )
{
   this->coordinates = CoordinatesType( ( Index ) 0 );
   this->orientation = EntityOrientationType( ( Index ) 0 );
   this->basis = EntityBasisType( ( Index ) 1 );
}

template< int Dimensions,
@@ -324,8 +322,6 @@ GridEntity( const GridType& grid,
  coordinates( coordinates ),
  neighbourEntitiesStorage( *this )
{
   this->orientation = EntityOrientationType( ( Index ) 0 );
   this->basis = EntityBasisType( ( Index ) 1 );
}

template< int Dimensions,
Loading