4.1.6.3.1 : Le fichier header
Écrivons le fichier temporary_alloc.h :
Nous commençons par la classique définition de macro pour éviter les inclusions multiples de notre header :
1 2 |
#ifndef __TEMPORARY_ALLOC_H__ #define __TEMPORARY_ALLOC_H__ |
Ensuite nous incluons le header qui nous permettra de manipuler des tenseurs :
1 |
#include "PTensor.h"
|
Nous ajoutons une petite fonction template bonus pour interchanger des valeurs (on les utilisera plus tard avec des pointeurs) :
1 2 3 4 5 6 7 8 9 10 |
///Swap two values /** @param[out] a : value will be b * @param[out] b : value will be a */ template<typename T> void swapValue(T & a, T & b){ T c(a); a = b; b = c; } |
Nous définissons le prototype de notre fonction d'initialisation de temporaires. Ils sont très utiles pour éviter les allocations redondantes et inutile dans un programme. Nous passons donc 4 temporaires la matrice U entrée/sortie et la la matrice V entrée/sortie.
Nous passons 4 pointeur car ils seront simple à interchanger et 4 PTensor car ils géreront la désallocation pour nous.
Enfin nous passons la taille des images temporaires (nbRow, nbCol) :
1 2 3 |
void allocate_temporary(float *& tmpU1, float *& tmpU2, float *& tmpV1, float *& tmpV2, PTensor<float> & tmpInU, PTensor<float> & tmpInV, PTensor<float> & tmpOutU, PTensor<float> & tmpOutV, size_t nbRow, size_t nbCol); |
Finalement nous fermons la condition du preprocesseur pour éviter les inclusions multiples de notre header :
1 |
#endif
|
Le fichier temporary_alloc.h complet :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
/*************************************** Auteur : Pierre Aubert Mail : pierre.aubert@lapp.in2p3.fr Licence : CeCILL-C ****************************************/ #ifndef __TEMPORARY_ALLOC_H__ #define __TEMPORARY_ALLOC_H__ #include "PTensor.h" ///Swap two values /** @param[out] a : value will be b * @param[out] b : value will be a */ template<typename T> void swapValue(T & a, T & b){ T c(a); a = b; b = c; } void allocate_temporary(float *& tmpU1, float *& tmpU2, float *& tmpV1, float *& tmpV2, PTensor<float> & tmpInU, PTensor<float> & tmpInV, PTensor<float> & tmpOutU, PTensor<float> & tmpOutV, size_t nbRow, size_t nbCol); #endif |
Vous pouvez le télécharger ici.