Update benches

This commit is contained in:
Alejandro Gallo 2021-09-01 21:30:02 +02:00
parent 910c19c510
commit c45c0c4420
7 changed files with 97 additions and 1 deletions

1
bench/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
test_main

67
bench/hauta.h Normal file
View File

@ -0,0 +1,67 @@
#pragma once
#include <string>
#include <algorithm>
#include <vector>
#include <iostream>
#define INSTANTIATE_OPTION(__type, __reader) \
template <> __type option(Args &as, Flag &f) { \
auto const v(option<std::string>(as, f)); \
return __reader(v.c_str()); \
}
namespace hauta {
typedef const std::string Flag;
typedef std::string Arg;
typedef const std::vector<Arg> Args;
bool isFlagPresent(Args &a, Flag &f) {
return std::find(a.begin(), a.end(), f) != a.end();
}
// option
template<typename F> F option(Args &args, Flag &f);
template<> std::string option(Args &a, Flag &f) {
const auto it(std::find(a.begin(), a.end(), f));
if (!isFlagPresent(a, f)) {
std::cerr << "Expecting flag " << f << "\n";
throw "";
}
return std::string(*(it+1));
}
INSTANTIATE_OPTION(size_t, std::atoi)
INSTANTIATE_OPTION(int, std::atoi)
INSTANTIATE_OPTION(double, std::atof)
INSTANTIATE_OPTION(float, std::atof)
template<> bool option(Args &a, Flag &f) { return isFlagPresent(a, f); }
template<typename F> F option(Args &args, Flag &f, F const def) {
return isFlagPresent(args, f)
? option<F>(args, f)
: def
;
}
template<> bool option(Args &args, Flag &f, bool const def) {
return isFlagPresent(args, f)
? !def
: def
;
}
template <typename F>
F option(int argc, char **argv, Flag& f, const F def) {
return option<F>(Args {argv, argv + argc}, f, def);
}
template <typename F>
F option(int argc, char **argv, Flag& f) {
return option<F>(Args {argv, argv + argc}, f);
}
}
#undef INSTANTIATE_OPTION

View File

@ -1,6 +1,34 @@
#include <iostream> #include <iostream>
#include <atrip.hpp>
#include <ctf.hpp>
#include <bench/hauta.h>
int main(int argc, char** argv) {
MPI_Init(&argc, &argv);
CTF::World world(argc, argv);
const int no(hauta::option<int>(argc, argv, "--no"))
, nv(hauta::option<int>(argc, argv, "--nv"))
;
std::vector<int> symmetries(4, NS)
, vo({nv, no})
, vvoo({nv, nv, no, no})
, ooov({no, no, no, nv})
, vvvo({nv, nv, nv, no})
;
CTF::Tensor<double>
ei(1, ooov.data(), symmetries.data(), world)
, ea(1, vo.data(), symmetries.data(), world)
, Tph(2, vo.data(), symmetries.data(), world)
, Tpphh(4, vvoo.data(), symmetries.data(), world)
, Vpphh(4, vvoo.data(), symmetries.data(), world)
, Vhhhp(4, ooov.data(), symmetries.data(), world)
, Vppph(4, vvvo.data(), symmetries.data(), world)
;
int main() {
std::cout << "Hello world" << std::endl; std::cout << "Hello world" << std::endl;
MPI_Finalize();
return 0; return 0;
} }