.. _ogn_tutorial_advanced_compute_vectorized_node:

Tutorial 30 - Node with more advanced computeVectorized
=======================================================

This tutorial demonstrates how to compose nodes that implements a computeVectorized function. It shows how to access the raw vectorized data,
and how it can be used to write a performant tight loop using SIMD instructions.

OgnTutorialSIMDAdd.ogn
--------------------------------
The *ogn* file shows the implementation of a node named "omni.graph.tutorials.TutorialSIMDFloatAdd", which takes inputs
of 2 floating point values, and performs a sum.

.. literalinclude:: ../../../../../source/extensions/omni.graph.tutorials/tutorials/tutorial30/OgnTutorialSIMDAdd.ogn
    :linenos:
    :language: json

OgnTutorialSIMDAdd.cpp
---------------------------------
The *cpp* file contains the implementation of the node. It takes two floating point inputs and performs a sum,
demonstrating how to handle a vectorized compute. It shows how to retrieve the vectorized array of inputs and output,
how to reason about the number of instances provided, and how to optimize the compute taking advantage of those vectorized inputs.
Since a SIMD instruction requires a given alignment for its arguments, the compute is divided in 3 sections:
- a first section that does a regular sum input on the few first instances that don't have a proper alignment
- a second, the heart of the function, that does as much SIMD adds as it can, performing them 4 elements by 4 elements
- a last section that perform regular sum on the few remaining items that did not fit in the SIMD register

.. literalinclude:: ../../../../../source/extensions/omni.graph.tutorials/tutorials/tutorial30/OgnTutorialSIMDAdd.cpp
    :linenos:
    :language: c++
