Created
September 17, 2012 16:44
-
-
Save sandello/3738412 to your computer and use it in GitHub Desktop.
Snippets for EMA-course in Yandex Data Analysis School
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stxxl/vector> | |
| #include <stxxl/random_shuffle> | |
| #include <boost/random/uniform_int.hpp> | |
| #include <boost/random/uniform_real.hpp> | |
| #include <boost/random/variate_generator.hpp> | |
| #include <boost/generator_iterator.hpp> | |
| class Profiler | |
| { | |
| private: | |
| stxxl::stats_data StatsBefore; | |
| stxxl::stats_data StatsAfter; | |
| public: | |
| Profiler() | |
| { | |
| StatsBefore = *stxxl::stats::get_instance(); | |
| } | |
| ~Profiler() | |
| { | |
| StatsAfter = *stxxl::stats::get_instance(); | |
| Dump(); | |
| } | |
| private: | |
| void Dump() | |
| { | |
| std::cerr << (StatsAfter - StatsBefore) << std::endl; | |
| } | |
| }; | |
| int main(int argc, const char** argv) | |
| { | |
| try { | |
| (void)stxxl::block_manager::get_instance(); | |
| } catch (const std::exception& ex) { | |
| std::cerr << "Error while initializing STXXL: " << ex.what(); | |
| } | |
| typedef stxxl::VECTOR_GENERATOR< | |
| float, | |
| 1, // Number of blocks in a page | |
| 1, // Number of pages kept in memory | |
| 2 * 1024 * 1024, // Block size | |
| stxxl::RC, // Allocation strategy | |
| stxxl::lru>::result FloatVector; | |
| unsigned int M = 32 * 1024 * 1024; | |
| unsigned int Nb= 64 * 1024 * 1024; | |
| unsigned int N = Nb / sizeof(float); | |
| FloatVector v(N); | |
| std::cerr << "M(b) = " << M << " ; N(b) = " << Nb << " ; N = " << N << std::endl; | |
| boost::uniform_real<> uniformDistribution(0,1); | |
| boost::mt19937 generator(42); | |
| boost::variate_generator< boost::mt19937&, boost::uniform_real<> > uniform(generator, uniformDistribution); | |
| { | |
| std::cerr << " * Generating data..." << std::endl;; | |
| for (size_t i = 0; i < v.size(); ++i) { | |
| v[i] = uniform(); | |
| } | |
| } | |
| { | |
| Profiler profiler; | |
| std::cerr << " * Shuffling data..." << std::endl;; | |
| stxxl::random_shuffle(v.begin(), v.end(), M); | |
| } | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| STXXL_ROOT ?= ../stxxl | |
| STXXL_CONFIG ?= stxxl_boost.mk | |
| include $(STXXL_ROOT)/$(STXXL_CONFIG) | |
| CXX = $(STXXL_CXX) | |
| CPPFLAGS += $(STXXL_CPPFLAGS) | |
| LDLIBS += $(STXXL_LDLIBS) | |
| CPPFLAGS += -O3 -Wall -g | |
| my.bin: main.o | |
| $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) main.o -o $@ $(LDLIBS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment