IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 4ea9ea77 authored by Antonio Augusto Alves Junior's avatar Antonio Augusto Alves Junior
Browse files

example

parent 116f3a78
No related branches found
No related tags found
No related merge requests found
......@@ -65,7 +65,7 @@ include_directories( ${CATCH_HEADER_DIR})
add_custom_target(examples)
include(${RANDOMITERATOR_CMAKE_DIR}/AddExample.cmake)
#add_subdirectory(examples/)
add_subdirectory(examples)
#+++++++++++++++++++++++++++
# TESTING +
......
......@@ -9,8 +9,11 @@ INPUT = /home/augalves/Development/Release/RandomIterator/rando
USE_MDFILE_AS_MAINPAGE = /home/augalves/Development/Release/RandomIterator/random_iterator/README.md
OUTPUT_DIRECTORY = /home/augalves/Development/Release/RandomIterator/random_iterator_proj/docs
OUTPUT_DIRECTORY = /home/augalves/Development/Release/RandomIterator/random_iterator_proj/documentation/reference
VERBATIM_HEADERS = NO
GENERATE_LATEX = NO
RECURSIVE = YES
GENERATE_XML = YES
#---------------------------------------------------------------------------
# Project related configuration options
#---------------------------------------------------------------------------
......@@ -174,7 +177,7 @@ FILE_PATTERNS = *.c \
*.js \
*.cu \
*.cuh
RECURSIVE = YES
#RECURSIVE = YES
EXCLUDE =
EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS = *random_iterator/detail*
......@@ -199,7 +202,7 @@ REFERENCES_RELATION = YES
REFERENCES_LINK_SOURCE = YES
SOURCE_TOOLTIPS = YES
USE_HTAGS = NO
VERBATIM_HEADERS = YES
#VERBATIM_HEADERS = YES
CLANG_ASSISTED_PARSING = NO
CLANG_OPTIONS =
CLANG_DATABASE_PATH =
......@@ -273,7 +276,7 @@ EXTRA_SEARCH_MAPPINGS =
#---------------------------------------------------------------------------
# Configuration options related to the LaTeX output
#---------------------------------------------------------------------------
GENERATE_LATEX = NO
#GENERATE_LATEX = NO
LATEX_OUTPUT = latex
LATEX_CMD_NAME = latex
MAKEINDEX_CMD_NAME = makeindex
......@@ -314,7 +317,7 @@ MAN_LINKS = NO
#---------------------------------------------------------------------------
# Configuration options related to the XML output
#---------------------------------------------------------------------------
GENERATE_XML = NO
#GENERATE_XML = NO
XML_OUTPUT = xml
XML_PROGRAMLISTING = YES
XML_NS_MEMB_FILE_SCOPE = NO
......
project(examples)
#----------------------------
message(STATUS "Adding target to examples. Executable file name: histogram")
add_executable( histogram histogram.cpp )
target_link_libraries( histogram -L/usr/lib64 )
add_dependencies(examples histogram )
/*----------------------------------------------------------------------------
*
* Copyright (C) 2021 Antonio Augusto Alves Junior
*
* This file is part of RandomIterator.
*
* RandomIterator is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RandomIterator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RandomIterator. If not, see <http://www.gnu.org/licenses/>.
*
*---------------------------------------------------------------------------*/
/*
* example.cpp
*
* Created on: 11/05/2021
* Author: Antonio Augusto Alves Junior
*/
/**
* \example example.cpp
*
*/
#include <iostream>
#include <random>
#include <vector>
#include <string>
#include <random_iterator/Stream.hpp>
//command line
#define TCLAP_SETBASE_ZERO 1
#include <tclap/CmdLine.h>
//set a global seed
static const uint64_t default_seed= 0x548c9decbce65295 ;
int main(int argv, char** argc)
{
uint64_t seed = default_seed;
uint32_t stream = 0;
size_t nentries = 0;
try {
TCLAP::CmdLine cmd("Command line arguments for ", '=');
TCLAP::ValueArg<size_t> NEntriesArg("n", "nentries", "Number of entries.", false, 0, "size_t");
cmd.add(NEntriesArg);
TCLAP::ValueArg<uint64_t> SeedArg("s", "seed", "RNG seed.", false, default_seed, "uint64_t");
cmd.add(SeedArg);
TCLAP::ValueArg<uint32_t> StreamArg("S", "stream", "Stream number.", false, 0, "uint32_t") ;
cmd.add(StreamArg);
// Parse the argv array.
cmd.parse(argv, argc);
// Get the value parsed by each arg.
seed = SeedArg.getValue();
stream = StreamArg.getValue();
nentries = NEntriesArg.getValue();
}
catch (TCLAP::ArgException &e) {
std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl;
}
random_iterator::philox RNG(seed);
std::uniform_real_distribution<double> dist(0.0, 10.0);
auto rng_stream = random_iterator::make_stream( dist, RNG, stream);
//histogram as a simple vector
std::vector<size_t> histogram(10);
//fill histogram
do {
++histogram[ size_t(rng_stream()) ];
} while( ( --nentries ) > 0 );
//print histogram nicely
size_t i =0;
size_t maxe = *std::max_element(histogram.begin(), histogram.end());
std::cout <<maxe << std::endl ;
std::cout << "--------"<< std::string(50 , '-') << std::endl ;
for(auto n: histogram){
double bin = 50.0*double(n)/maxe;
std::cout << "["<< i<<", "<< ++i << ") "<<
std::string( bin, '=') << ": "<< n <<std::endl;
}
std::cout << "--------"<< std::string(50, '-') << std::endl ;
}
......@@ -33,7 +33,7 @@
#include <cstdio>
#include <cstdint>
//hydra
//
#include <random_iterator/Stream.hpp>
#include <random>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment