Commit 142c2e5c authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Improved documentation for ParallelFor

parent 410ed20c
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
#include <iostream>
#include <cstdlib>
#include <TNL/Containers/Vector.h>
#include <TNL/Algorithms/ParallelFor.h>

@@ -13,10 +12,12 @@ void initMeshFunction( const int xSize,
                       Vector< double, Device >& v,
                       const double& c )
{
   auto view = v1.getConstView();
   auto init = [=] __cuda_callable__  ( int i, int j, const int xSize, const double c ) mutable {
      view[ j * xSize + i ] =  c; };
   ParallelFor2D< Device >::exec( 0, 0, xSize, ySize, init, xSize, c );
   auto view = v.getView();
   auto init = [=] __cuda_callable__ ( int i, int j ) mutable
   {
      view[ j * xSize + i ] = c;
   };
   ParallelFor2D< Device >::exec( 0, 0, xSize, ySize, init );
}

int main( int argc, char* argv[] )
@@ -42,4 +43,3 @@ int main( int argc, char* argv[] )
#endif
   return EXIT_SUCCESS;
}
+7 −7
Original line number Diff line number Diff line
#include <iostream>
#include <cstdlib>
#include <TNL/Containers/Vector.h>
#include <TNL/Algorithms/ParallelFor.h>

@@ -14,16 +13,18 @@ void initMeshFunction( const int xSize,
                       Vector< double, Device >& v,
                       const double& c )
{
   auto view = v1.getConstView();
   auto init = [=] __cuda_callable__  ( int i, int j, int k, const int xSize, const int ySize, const double c ) mutable {
      view[ ( k * ySize + j ) * xSize + i ] =  c; };
   ParallelFor3D< Device >::exec( 0, 0, xSize, ySize, init, xSize, ySize, c );
   auto view = v.getView();
   auto init = [=] __cuda_callable__ ( int i, int j, int k ) mutable
   {
      view[ ( k * ySize + j ) * xSize + i ] = c;
   };
   ParallelFor3D< Device >::exec( 0, 0, 0, xSize, ySize, zSize, init );
}

int main( int argc, char* argv[] )
{
   /***
    * Define dimensions of 2D mesh function.
    * Define dimensions of a 3D mesh function.
    */
   const int xSize( 10 ), ySize( 10 ), zSize( 10 );
   const int size = xSize * ySize * zSize;
@@ -43,4 +44,3 @@ int main( int argc, char* argv[] )
#endif
   return EXIT_SUCCESS;
}
+6 −6
Original line number Diff line number Diff line
#include <iostream>
#include <cstdlib>
#include <TNL/Containers/Vector.h>
#include <TNL/Algorithms/ParallelFor.h>

using namespace TNL;
using namespace TNL::Containers;
using namespace TNL::Algorithms;

/****
 * Set all elements of the vector v to the constant c.
@@ -14,10 +14,11 @@ void initVector( Vector< double, Device >& v,
                 const double& c )
{
   auto view = v.getView();
   auto init = [=] __cuda_callable__  ( int i, const double c ) mutable {
      view[ i ] = c; };

   Algorithms::ParallelFor< Device >::exec( 0, v.getSize(), init, c );
   auto init = [=] __cuda_callable__ ( int i ) mutable
   {
      view[ i ] = c;
   };
   ParallelFor< Device >::exec( 0, v.getSize(), init );
}

int main( int argc, char* argv[] )
@@ -39,4 +40,3 @@ int main( int argc, char* argv[] )
#endif
   return EXIT_SUCCESS;
}
+3 −15
Original line number Diff line number Diff line
IF( BUILD_CUDA )
   CUDA_ADD_EXECUTABLE( ParallelForExample ParallelForExample.cu )
   ADD_CUSTOM_COMMAND( COMMAND ParallelForExample > ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/ParallelForExample.out OUTPUT ParallelForExample.out )
   CUDA_ADD_EXECUTABLE( ParallelForExample-2D ParallelForExample-2D.cu )
   CUDA_ADD_EXECUTABLE( ParallelForExample-3D ParallelForExample-3D.cu )
ELSE()
   ADD_EXECUTABLE( ParallelForExample-2D ParallelForExample-2D_ug.cpp )
   ADD_EXECUTABLE( ParallelForExample-3D ParallelForExample-3D_ug.cpp )
ENDIF()

ADD_EXECUTABLE( StaticForExample StaticForExample_ug.cpp )
ADD_CUSTOM_COMMAND( COMMAND StaticForExample > ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/StaticForExample.out OUTPUT StaticForExample.out )

ADD_EXECUTABLE( TemplateStaticForExample TemplateStaticForExample_ug.cpp )
ADD_CUSTOM_COMMAND( COMMAND TemplateStaticForExample > ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/TemplateStaticForExample.out OUTPUT TemplateStaticForExample.out )

IF( BUILD_CUDA )
ADD_CUSTOM_TARGET( ForLoops-cuda ALL DEPENDS
   ParallelForExample.out
ADD_CUSTOM_TARGET( ForLoops ALL DEPENDS
   StaticForExample.out
   TemplateStaticForExample.out )
ENDIF()
   TemplateStaticForExample.out
)
+0 −1
Original line number Diff line number Diff line
ParallelForExample-2D_ug.cpp
 No newline at end of file
Loading