3.2.1.2.1 : Le fichier header

Écrivons le fichier hadamard_product_vectorize.h :



Nous commençons tout d'abord par éviter les inclusions multiples :

1
2
#ifndef __HADAMARD_PRODUCT_VECTORIZE_H__
#define __HADAMARD_PRODUCT_VECTORIZE_H__


Ensuite nous ajoutons un include standard :

1
#include <iostream>


Nous ajoutons le prototype de la fonction (qui à le même nom que le fichier ce qui simplifiera l'écriture du main). Nous devons aussi garantir au compilateur que les pointeurs que nous utilisons correspondent à des espaces mémoire distincts. Cela ce fait avec le mot clé __restrict__, sinon il ne vectorisera pas.

1
void hadamard_product_vectorize(float* __restrict__ ptabResult, const float* __restrict__ ptabX, const float* __restrict__ ptabY, size_t nbElement);


Enfin nous fermons la condition du tout début :

1
#endif


Le fichier hadamard_product_vectorize.h complet :

1
2
3
4
5
6
7
8
9
10
/***************************************
	Auteur : Pierre Aubert
	Mail : pierre.aubert@lapp.in2p3.fr
	Licence : CeCILL-C
****************************************/
#ifndef __HADAMARD_PRODUCT_VECTORIZE_H__
#define __HADAMARD_PRODUCT_VECTORIZE_H__
#include <iostream>
void hadamard_product_vectorize(float* __restrict__ ptabResult, const float* __restrict__ ptabX, const float* __restrict__ ptabY, size_t nbElement);
#endif


Vous pouvez le télécharger ici.