3.1.3 : Le main.cpp

Comme toujours, on commence pas les includes :
1
2
3
4
5
6
7
#include <iostream>
#include <vector>
#include <numeric>
#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
	std::vector<float> tabX(nbElement), tabY(nbElement), tabRes(nbElement);


On initialise tabX avec std::generate :
1
2
3
4
5
	std::generate(std::execution::par_unseq, tabX.begin(), tabX.end(), [i = 0] () mutable {
		float val(i*19lu%11);
		i++;
		return val;
	});


On initialise tabY :
1
2
3
4
5
	std::generate(std::execution::par_unseq, tabY.begin(), tabY.end(), [i = 0] () mutable {
		float val(i*27lu%19);
		i++;
		return val;
	});


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 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
26
27
28
29
30
/***************************************
	Auteur : Pierre Aubert
	Mail : pierre.aubert@lapp.in2p3.fr
	Licence : CeCILL-C
****************************************/
#include <iostream>
#include <vector>
#include <numeric>
#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(nbElement), tabY(nbElement), tabRes(nbElement);
	std::generate(std::execution::par_unseq, tabX.begin(), tabX.end(), [i = 0] () mutable {
		float val(i*19lu%11);
		i++;
		return val;
	});
	std::generate(std::execution::par_unseq, tabY.begin(), tabY.end(), [i = 0] () mutable {
		float val(i*27lu%19);
		i++;
		return val;
	});
	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.