Skip to content
Snippets Groups Projects
Commit 75de139c authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Writting tutorial on StaticArray.

parent c6b8fc06
No related branches found
No related tags found
1 merge request!41Tutorials
...@@ -21,6 +21,8 @@ IF( BUILD_CUDA ) ...@@ -21,6 +21,8 @@ IF( BUILD_CUDA )
ADD_CUSTOM_COMMAND( COMMAND ElementsAccessing-1 > ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/ElementsAccessing-1.out OUTPUT ElementsAccessing-1.out ) ADD_CUSTOM_COMMAND( COMMAND ElementsAccessing-1 > ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/ElementsAccessing-1.out OUTPUT ElementsAccessing-1.out )
CUDA_ADD_EXECUTABLE( ElementsAccessing-2 ElementsAccessing-2.cu ) CUDA_ADD_EXECUTABLE( ElementsAccessing-2 ElementsAccessing-2.cu )
ADD_CUSTOM_COMMAND( COMMAND ElementsAccessing-2 > ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/ElementsAccessing-2.out OUTPUT ElementsAccessing-2.out ) ADD_CUSTOM_COMMAND( COMMAND ElementsAccessing-2 > ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/ElementsAccessing-2.out OUTPUT ElementsAccessing-2.out )
ADD_EXECUTABLE( StaticArrayExample StaticArrayExample.cpp )
ADD_CUSTOM_COMMAND( COMMAND StaticArrayExample > ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/StaticArrayExample.out OUTPUT StaticArrayExample.out )
ENDIF() ENDIF()
IF( BUILD_CUDA ) IF( BUILD_CUDA )
...@@ -35,5 +37,6 @@ ADD_CUSTOM_TARGET( TutorialsArrays-cuda ALL DEPENDS ...@@ -35,5 +37,6 @@ ADD_CUSTOM_TARGET( TutorialsArrays-cuda ALL DEPENDS
ContainsValue.out ContainsValue.out
ElementsAccessing-1.out ElementsAccessing-1.out
ElementsAccessing-2.out ElementsAccessing-2.out
ArrayViewEvaluate.out ) ArrayViewEvaluate.out
StaticArrayExample.out )
ENDIF() ENDIF()
#include <iostream>
#include <TNL/Containers/StaticArray.h>
#include <TNL/File.h>
using namespace TNL;
using namespace TNL::Containers;
int main( int argc, char* argv[] )
{
StaticArray< 3, int > a1, a2( 1, 2, 3 ), a3{ 4,3,2 };
a1 = 0.0;
std::cout << "a1 = " << a1 << std::endl;
std::cout << "a2 = " << a2 << std::endl;
std::cout << "a3 = " << a3 << std::endl;
File( "static-array-example-file.tnl", std::ios::out ) << a3;
File( "static-array-example-file.tnl", std::ios::in ) >> a1;
std::cout << "a1 = " << a1 << std::endl;
a1.sort();
std::cout << "Sorted a1 = " << a1 << std::endl;
}
...@@ -155,6 +155,12 @@ Static arrays are allocated on stack and thus they can be created even in CUDA k ...@@ -155,6 +155,12 @@ Static arrays are allocated on stack and thus they can be created even in CUDA k
* `Size` is the array size. * `Size` is the array size.
* `Value` is type of data stored in the array. * `Value` is type of data stored in the array.
The interface of StaticArray is very smillar to Array. The interface of StaticArray is very smillar to Array but much simpler. It contains set of common constructors. Array elements can be accessed by the `operator[]` and also using method `x()`, `y()` and `z()` when it makes sense. See the following example for typical use of StaticArray.
\include StaticArrayExample.cpp
The output looks as:
\include StaticArrayExample.out
## Distributed arrays <a name="distributed_arrays"></a> ## Distributed arrays <a name="distributed_arrays"></a>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment