5.3.1 : Le fichier main.cpp

Développons le main.cpp :

Comme toujours, on commence pas les includes :
1
2
3
4
5
6
7
#include <iostream>
#include <vector>

#include <algorithm>

//Some doc at : https://en.cppreference.com/w/cpp/header/execution
#include <execution>


Ensuite, la fonction main :
1
int main(int argc, char** argv){


On définit le nombre d'éléments que l'on veut dans nos tableaux :
1
	size_t nbElement(100000000);


On déclare nos tableaux et on les initialise :
1
2
3
4
5
6
	std::vector<float> tabX, tabY, tabRes;
	tabRes.resize(nbElement);
	for(size_t i(0lu); i < nbElement; ++i){
		tabX.push_back(i*19lu%11);
		tabY.push_back(i*27lu%19);
	}


On déclare notre produit de Hadamard noteOui, encore un... :
1
2
	std::transform(std::execution::par_unseq, std::begin(tabX), std::end(tabX), std::begin(tabY), std::begin(tabRes),
			[](float xi, float yi){ return xi * yi; });


On affiche les résulats :
1
	std::cout << "x = " << tabX.front() << ", y = " << tabY.front() << ", res = " << tabRes.front() << std::endl;


Puis on termine la fonction main :
1
2
	return 0;
}


Le fichier main.cpp 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
/***************************************
	Auteur : Pierre Aubert
	Mail : pierre.aubert@lapp.in2p3.fr
	Licence : CeCILL-C
****************************************/
#include <iostream>
#include <vector>

#include <algorithm>

//Some doc at : https://en.cppreference.com/w/cpp/header/execution
#include <execution>
int main(int argc, char** argv){
	size_t nbElement(100000000);
	std::vector<float> tabX, tabY, tabRes;
	tabRes.resize(nbElement);
	for(size_t i(0lu); i < nbElement; ++i){
		tabX.push_back(i*19lu%11);
		tabY.push_back(i*27lu%19);
	}
	std::transform(std::execution::par_unseq, std::begin(tabX), std::end(tabX), std::begin(tabY), std::begin(tabRes),
			[](float xi, float yi){ return xi * yi; });
	std::cout << "x = " << tabX.front() << ", y = " << tabY.front() << ", res = " << tabRes.front() << std::endl;
	return 0;
}


Le fichier main.cpp est disponible ici.