Commit de286542 authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Add barycenter 1d and 2d

parent 8e2a43de
......@@ -4,4 +4,4 @@ cmake_minimum_required(VERSION 2.8)
add_subdirectory(hadamard)
add_subdirectory(saxpy)
add_subdirectory(barycenter)
add_subdirectory(barycenter2d)
project(Phoenix)
cmake_minimum_required(VERSION 2.8)
set(CONFIG_BARYCENTER_2D "1000, 2000, 3000, 4000, 5000, 10000, 50000, 100000, 200000, 500000, 1000000, 5000000, 10000000")
set(progSrc barycenter2d.cpp main.cpp)
phoenix_compileAndRunExample(perf_barycenter2d_par_O0 "-O0" "${CONFIG_BARYCENTER_2D}" ${progSrc})
phoenix_compileAndRunExample(perf_barycenter2d_par_O1 "-O1" "${CONFIG_BARYCENTER_2D}" ${progSrc})
phoenix_compileAndRunExample(perf_barycenter2d_par_O2 "-O2" "${CONFIG_BARYCENTER_2D}" ${progSrc})
phoenix_compileAndRunExample(perf_barycenter2d_par_O3 "-O3" "${CONFIG_BARYCENTER_2D}" ${progSrc})
phoenix_compileAndRunExample(perf_barycenter2d_par_Ofast "-Ofast" "${CONFIG_BARYCENTER_2D}" ${progSrc})
phoenix_compileAndRunExample(perf_barycenter2d_par_vectorize_O3 "-O3 -ftree-vectorize -march=native -mtune=native -mavx2" "${CONFIG_BARYCENTER_2D}" ${progSrc})
phoenix_compileAndRunExample(perf_barycenter2d_par_vectorize_Ofast "-Ofast -ftree-vectorize -march=native -mtune=native -mavx2" "${CONFIG_BARYCENTER_2D}" ${progSrc})
phoenix_plotPerfLogX("barycenter2d_parBase" perf_barycenter2d_par_O0 perf_barycenter2d_par_O1 perf_barycenter2d_par_O2 perf_barycenter2d_par_O3 perf_barycenter2d_par_Ofast)
phoenix_plotPerfLogX("barycenter2d_parVectorize" perf_barycenter2d_par_O3 perf_barycenter2d_par_vectorize_O3 perf_barycenter2d_par_vectorize_Ofast)
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
//some doc at : https://en.cppreference.com/w/cpp/header/algorithm
#include <algorithm>
//Some doc at : https://en.cppreference.com/w/cpp/header/execution
#include <execution>
#include "barycenter2d.h"
///Do a classical barycenter
/** @param[out] res : result
* @param tabX : talbe of x values
* @param tabY : talbe of y values
* @param nbElement : number of elements in the tables
*/
void barycenter2d(float & res, const float* tabX, const float* tabY, size_t nbElement){
res = std::transform_reduce(std::execution::par_unseq,
tabX, tabX + nbElement, tabY,
0.0f, std::plus<float>(),
[](float xi, float yi){ return xi*yi; });
res /= (float)nbElement;
}
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
#ifndef __BARYCENTER2D_H__
#define __BARYCENTER2D_H__
#include <iostream>
void barycenter2d(float & res, const float* tabX, const float* tabY, size_t nbElement);
#endif
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
#include <iostream>
#include "micro_benchmark.h"
#include "PTensor.h"
#include "barycenter2d.h"
///Get the number of nanoseconds per elements
/** @param nbElement : number of elements of the tables
*/
void evaluateBarycenter2d(size_t nbElement){
PTensor<float> tabX(AllocMode::ALIGNED, nbElement);
PTensor<float> tabY(AllocMode::ALIGNED, nbElement);
for(size_t i(0lu); i < nbElement; ++i){
tabX[i] = i*19lu%11;
tabY[i] = i*27lu%19;
}
float res(0.0f);
micro_benchmarkAutoNsPrint("evaluate barycenter2d", nbElement, barycenter2d, res, tabX.getData(), tabY.getData(), nbElement);
}
int main(int argc, char** argv){
return micro_benchmarkParseArg(argc, argv, evaluateBarycenter2d);
}
......@@ -4,5 +4,6 @@ cmake_minimum_required(VERSION 2.8)
add_subdirectory(hadamard)
add_subdirectory(saxpy)
add_subdirectory(barycenter)
add_subdirectory(barycenter2d)
project(Phoenix)
cmake_minimum_required(VERSION 2.8)
set(CONFIG_BARYCENTER_2D "1000, 2000, 3000, 4000, 5000, 10000")
set(progSrc barycenter2d.cpp main.cpp)
phoenix_compileAndRunExample(perf_barycenter2d_seq_O0 "-O0" "${CONFIG_BARYCENTER_2D}" ${progSrc})
phoenix_compileAndRunExample(perf_barycenter2d_seq_O1 "-O1" "${CONFIG_BARYCENTER_2D}" ${progSrc})
phoenix_compileAndRunExample(perf_barycenter2d_seq_O2 "-O2" "${CONFIG_BARYCENTER_2D}" ${progSrc})
phoenix_compileAndRunExample(perf_barycenter2d_seq_O3 "-O3" "${CONFIG_BARYCENTER_2D}" ${progSrc})
phoenix_compileAndRunExample(perf_barycenter2d_seq_Ofast "-Ofast" "${CONFIG_BARYCENTER_2D}" ${progSrc})
phoenix_compileAndRunExample(perf_barycenter2d_seq_vectorize_O3 "-O3 -ftree-vectorize -march=native -mtune=native -mavx2" "${CONFIG_BARYCENTER_2D}" ${progSrc})
phoenix_compileAndRunExample(perf_barycenter2d_seq_vectorize_Ofast "-Ofast -ftree-vectorize -march=native -mtune=native -mavx2" "${CONFIG_BARYCENTER_2D}" ${progSrc})
phoenix_plotPerf("barycenter2d_seqBase" perf_barycenter2d_seq_O0 perf_barycenter2d_seq_O1 perf_barycenter2d_seq_O2 perf_barycenter2d_seq_O3 perf_barycenter2d_seq_Ofast)
phoenix_plotPerf("barycenter2d_seqVectorize" perf_barycenter2d_seq_O3 perf_barycenter2d_seq_vectorize_O3 perf_barycenter2d_seq_vectorize_Ofast)
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
//some doc at : https://en.cppreference.com/w/cpp/header/algorithm
#include <algorithm>
//Some doc at : https://en.cppreference.com/w/cpp/header/execution
#include <execution>
#include "barycenter2d.h"
///Do a classical barycenter
/** @param[out] res : result
* @param tabX : talbe of x values
* @param tabY : talbe of y values
* @param nbElement : number of elements in the tables
*/
void barycenter2d(float & res, const float* tabX, const float* tabY, size_t nbElement){
res = std::transform_reduce(std::execution::unseq,
tabX, tabX + nbElement, tabY,
0.0f, std::plus<float>(),
[](float xi, float yi){ return xi*yi; });
res /= (float)nbElement;
}
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
#ifndef __BARYCENTER2D_H__
#define __BARYCENTER2D_H__
#include <iostream>
void barycenter2d(float & res, const float* tabX, const float* tabY, size_t nbElement);
#endif
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
#include <iostream>
#include "micro_benchmark.h"
#include "PTensor.h"
#include "barycenter2d.h"
///Get the number of nanoseconds per elements
/** @param nbElement : number of elements of the tables
*/
void evaluateBarycenter2d(size_t nbElement){
PTensor<float> tabX(AllocMode::ALIGNED, nbElement);
PTensor<float> tabY(AllocMode::ALIGNED, nbElement);
for(size_t i(0lu); i < nbElement; ++i){
tabX[i] = i*19lu%11;
tabY[i] = i*27lu%19;
}
float res(0.0f);
micro_benchmarkAutoNsPrint("evaluate barycenter2d", nbElement, barycenter2d, res, tabX.getData(), tabY.getData(), nbElement);
}
int main(int argc, char** argv){
return micro_benchmarkParseArg(argc, argv, evaluateBarycenter2d);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment