Skip to content

phoenixofhp/dimension_threads

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dimension Threads

This project demonstrates an interesting geometric phenomenon:

In higher-dimensional spaces, most of the volume of a hypersphere is concentrated near its outer shell.

Overview

The program generates random points uniformly distributed within a hypercube and selects those that fall inside a hypersphere of radius RADIUS. It then analyzes how many of these points lie within a thin outer shell of the sphere (between RADIUS - ε and RADIUS).

It uses modern C++17 features including:

  • std::thread and std::atomic for multithreading
  • std::mutex for safe shared state access
  • std::array and std::vector for efficient storage
  • Random number generation with std::mt19937_64

Compilation

You can build the project using the included Makefile:

make

By default, the program uses:

  • C++17

  • Optimization flags like -O3, -march=native, -flto

  • Predefined macros:

    • DIMENSIONS=15
    • AMOUNT=50000

To override them:

make CPPFLAGS='-DDIMENSIONS=20 -DAMOUNT=100000'

Output Example

Using threads: 6
Progress: 100% (50000/50000)
Sphere dimensions: 15
Points total:      50000
Points in outer sphere layer: 39746 (~79.492%)
Time elapsed: 35074.3 ms

Concept

As the number of dimensions increases, most of the points fall into the outer shell of the hypersphere. This program helps visualize this unintuitive result by statistical simulation.

Clean

make clean

License

This project is released under the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors