├── .appveyor.yml ├── .export.lua ├── .gitignore ├── .package.yml ├── .travis.yml ├── .zenodo.json ├── LICENSE.md ├── Pipfile ├── README.md ├── bsp ├── bsp.licenseheader └── include │ └── bsp │ ├── barrier.h │ ├── barrierType.h │ ├── bsp.h │ ├── bspAbort.h │ ├── bspClass.h │ ├── bspExt.h │ ├── bspProf.h │ ├── communicationQueues.h │ ├── condVarBarrier.h │ ├── historyRecorder.h │ ├── historyRecorderType.h │ ├── mixedBarrier.h │ ├── processorData.h │ ├── registerMapType.h │ ├── requestVector.h │ ├── requests.h │ ├── spinLock.h │ ├── stackAllocator.h │ ├── threadRegisterMap.h │ ├── threadRegisterVector.h │ ├── util.h │ └── voidRecorder.h ├── codecov.yml ├── docs ├── CNAME ├── bsp.pdf ├── classic.md ├── com │ ├── get.md │ ├── getContainer.md │ ├── getPrimitive.md │ ├── getPtrs.md │ ├── put.md │ ├── putContainer.md │ ├── putPrimitive.md │ └── putPtrs.md ├── halting │ └── abort.md ├── hp │ ├── hpget.md │ ├── hpmove.md │ ├── hpput.md │ └── hpsend.md ├── index.md ├── logic │ ├── begin.md │ ├── end.md │ ├── execute.md │ └── init.md ├── messaging │ ├── move.md │ ├── qsize.md │ ├── send.md │ ├── sendContainer.md │ ├── sendIterator.md │ ├── sendPrimitive.md │ ├── sendPtrs.md │ └── sendTagContainer.md ├── messagingutil │ ├── gettag.md │ └── settagsize.md ├── regdereg │ ├── pop.md │ └── push.md ├── sync │ └── sync.md └── util │ ├── nprocs.md │ ├── procid.md │ └── time.md ├── edupack ├── LICENSE ├── Makefile ├── README ├── bench.h ├── bspBenchModern.cpp ├── bspbench.cpp ├── bspedupack.cpp ├── bspedupack.h ├── bspfft.cpp ├── bspfft_test.cpp ├── bspinprod.cpp ├── bsplu.cpp ├── bsplu_test.cpp ├── bspmv.cpp ├── bspmv_test.cpp ├── modernFft.h └── modernFftTest.cpp ├── mkdocs.yml ├── test ├── .package.yml ├── bsp.licenseheader ├── helper.h ├── main.cpp ├── testBarrier.cpp ├── testClassic.h ├── testContainer.cpp ├── testExtra.cpp ├── testIterators.cpp ├── testPrimitive.h ├── testPtrs.cpp └── zpm.lua ├── zpm.lock └── zpm.lua /.appveyor.yml: -------------------------------------------------------------------------------- 1 | platform: 2 | - Win32 3 | build: off 4 | environment: 5 | PYTHON: "C:\\Python35" 6 | PROJECT: BSPLib 7 | PROJECT_DIRECTORY: bsp 8 | matrix: 9 | - TYPE: zpm 10 | - BUILD_CONFIG: release 11 | BUILD_ARCHITECTURE: x86 12 | - BUILD_CONFIG: debug 13 | BUILD_ARCHITECTURE: x86 14 | - BUILD_CONFIG: release 15 | BUILD_ARCHITECTURE: x86_64 16 | - BUILD_CONFIG: debug 17 | BUILD_ARCHITECTURE: x86_64 18 | - BUILD_CONFIG: release 19 | BUILD_ARCHITECTURE: x86_64 20 | - BUILD_CONFIG: release 21 | BUILD_ARCHITECTURE: x86_64 22 | install: 23 | - powershell -command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri https://raw.githubusercontent.com/Zefiros-Software/ZPM/dev/script/install-zpm.bat -OutFile %TEMP%/install-zpm.bat;" && %TEMP%/install-zpm.bat 24 | - "SET PATH=%PATH%;%USERPROFILE%/zpm/bin" 25 | test_script: 26 | - zpm run build-ci-library 27 | deploy_script: 28 | - zpm run deploy-ci-library 29 | -------------------------------------------------------------------------------- /.export.lua: -------------------------------------------------------------------------------- 1 | -- [[ 2 | -- @cond ___LICENSE___ 3 | -- 4 | -- Copyright (c) 2016-2018 Zefiros Software. 5 | -- 6 | -- Permission is hereby granted, free of charge, to any person obtaining a copy 7 | -- of this software and associated documentation files (the "Software"), to deal 8 | -- in the Software without restriction, including without limitation the rights 9 | -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | -- copies of the Software, and to permit persons to whom the Software is 11 | -- furnished to do so, subject to the following conditions: 12 | -- 13 | -- The above copyright notice and this permission notice shall be included in 14 | -- all copies or substantial portions of the Software. 15 | -- 16 | -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | -- THE SOFTWARE. 23 | -- 24 | -- @endcond 25 | -- ]] 26 | 27 | 28 | project "BSPLib" 29 | kind "StaticLib" 30 | 31 | if zpm.setting( "profiler" ) and zpm.uses "Zefiros-Software/PlotLib" then 32 | defines "PLOTLIB_USE_ZPM_ANACONDA" 33 | end 34 | 35 | zpm.export [[ 36 | includedirs "bsp/include/" 37 | cppdialect "C++11" 38 | 39 | filter "system:not windows" 40 | links "pthread" 41 | ]] 42 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | -- artifacts 2 | bin/* 3 | test/obj/* 4 | test/bin/* 5 | 6 | -- zpm 7 | .config.json 8 | .config.yml 9 | 10 | -- git 11 | *.orig 12 | 13 | -- make 14 | Makefile 15 | *.make 16 | 17 | -- visual studio code 18 | */.vs/* 19 | 20 | -- visual studio 21 | *.sdf 22 | *.sln 23 | *.suo 24 | *.VC.* 25 | *.opensdf 26 | *.vcxproj* 27 | 28 | -- Intel Tools 29 | *Amplifier* 30 | 31 | -- Docs 32 | *.chi 33 | *.chm 34 | 35 | -- Astyle 36 | .astylerc -------------------------------------------------------------------------------- /.package.yml: -------------------------------------------------------------------------------- 1 | description: BSPLib is a fast, and easy to use C++ implementation of the Bulk Synchronous Parallel (BSP) threading model. This model is mainly used in the scientific computing field, but can also be applied more general in computer science. This library includes an extended version the standard BSP interface to perform better, and made it more easy to use. 2 | keywords: 3 | - C++ 4 | - BSP 5 | - easy 6 | - fast 7 | website: 'http://bsplib.eu/' 8 | license: MIT 9 | authors: 10 | - name: Mick van Duijn 11 | email: m.vanduijn@zefiros.eu 12 | website: 'https://zefiros.eu/' 13 | - name: Paul Visscher 14 | email: p.e.visscher@zefiros.eu 15 | website: 'https://zefiros.eu/' 16 | - name: Koen Visscher 17 | email: k.m.visscher@zefiros.eu 18 | website: 'https://zefiros.eu/' 19 | public: 20 | libraries: 21 | - name: Zefiros-Software/PlotLib 22 | optional: true 23 | version: ^2.0.0 24 | development: 25 | modules: 26 | - name: Zefiros-Software/Defaults 27 | version: '@head' 28 | - name: Zefiros-Software/Miniconda 29 | version: '@head' 30 | assets: 31 | - name: Zefiros-Software/Zefiros-Mkdocs-Style 32 | version: ^1.0.0 33 | public: 34 | libraries: 35 | - name: Zefiros-Software/Armadillo 36 | version: '^8.300.0' 37 | - name: Zefiros-Software/PlotLib 38 | optional: false 39 | version: ^2.0.0 40 | settings: 41 | profiler: 42 | default: false 43 | reduce: anyTrue -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | language: generic 3 | matrix: 4 | include: 5 | - os: osx 6 | osx_image: xcode9.2 7 | language: generic 8 | env: 9 | - BUILD_CONFIG=release 10 | - BUILD_ARCHITECTURE=x86_64 11 | - os: osx 12 | osx_image: xcode9.2 13 | language: generic 14 | env: 15 | - BUILD_CONFIG=debug 16 | - BUILD_ARCHITECTURE=x86_64 17 | - os: linux 18 | dist: trusty 19 | env: 20 | - BUILD_CONFIG=coverage 21 | - BUILD_ARCHITECTURE=x86_64 22 | - GCC_VERSION=7 23 | - os: linux 24 | dist: trusty 25 | env: 26 | - BUILD_CONFIG=release 27 | - BUILD_ARCHITECTURE=x86_64 28 | - GCC_VERSION=7 29 | - os: linux 30 | dist: trusty 31 | env: 32 | - BUILD_CONFIG=debug 33 | - BUILD_ARCHITECTURE=x86_64 34 | - GCC_VERSION=7 35 | - os: linux 36 | dist: trusty 37 | env: 38 | - BUILD_CONFIG=release 39 | - BUILD_ARCHITECTURE=x86 40 | - GCC_VERSION=7 41 | - os: linux 42 | dist: trusty 43 | env: 44 | - BUILD_CONFIG=release 45 | - BUILD_ARCHITECTURE=x86_64 46 | - GCC_VERSION=6 47 | - os: linux 48 | dist: trusty 49 | env: 50 | - BUILD_CONFIG=debug 51 | - BUILD_ARCHITECTURE=x86_64 52 | - GCC_VERSION=6 53 | - os: linux 54 | dist: trusty 55 | env: 56 | - BUILD_CONFIG=release 57 | - BUILD_ARCHITECTURE=x86 58 | - GCC_VERSION=6 59 | - os: linux 60 | dist: trusty 61 | env: 62 | - BUILD_CONFIG=zpm 63 | - GCC_VERSION=6 64 | global: 65 | env: 66 | - PROJECT=BSPLib 67 | - PROJECT_DIRECTORY=bsp 68 | install: 69 | - source /dev/stdin <<< "$(curl -s https://raw.githubusercontent.com/Zefiros-Software/ZPM/dev/script/install-zpm.sh)" 70 | script: 71 | - zpm run build-ci-library 72 | after_success: 73 | - zpm run deploy-ci-library 74 | notifications: 75 | slack: 76 | secure: p2/koHdeVJyGte6N5ecYQIwKORdjj6V6f19X1CVulnUmhefIcsX1QHZ5rKIS7+xss4sPOvFXLN8yT9n+pRCjqEWzh927meyLINiVx19+Isl1R042m4qutmCpr0TrqsOqwJQc5HhMRusiz7tXeClhUZ6fOxZ3dGjzZmibs3jg8ntO+OSYJm2Wv9CcbR81xdYKzwGu+ujBI55QaXFuXn0QDRVl5amLYFQYb3RMSaY5ozEkmvhY5dO7Ha+zFesLmh4vlYyulWzT/wa8Pws+vuVd7Wweek1DTOIn+PQxn6JxtDKmtNthYJD8Mg8YR618NMjUUj6UvW9PozeWi+Vtja/giqHMgYrXqH7RaSDLV1S4jPexqlAQYaMJYuEcyeFWCyV783G+jkPD13x4as9gRCXqh9CMNEv7h+vQI/fLWuN4hQV1BkAWt0JEuLUZMq6zShzHOvbeueywtxlktPpEsKDk8pDqUUEenrvhx4H/eYMv4/wiIwzn+4KO4uhdm8uM4kV+Px8ipTfGSLFOieiPomSq09IbcmTj0fFGF3MlHpPaCoOJuZ1Sgt7r/CPUdzihyHr7paxYs/1QxmJKtKyJFDNkaOsrSjDyY8E6S7213vE9FQLu9MvaTeHbEOuo/u+oI4aEJjxog2Zpf1AX5XoK9BftJUhG0YbFSp31D6EY0H/m80E= 77 | -------------------------------------------------------------------------------- /.zenodo.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "BSPLib is a fast, and easy to use C++ implementation of the Bulk Synchronous Parallel (BSP) threading model.", 3 | "license": "MIT License", 4 | "title": "Zefiros-Software/BSPLib 1.1.11", 5 | "upload_type": "software", 6 | "publication_date": "2017-10-29", 7 | "creators": [ 8 | { 9 | "affiliation": "@Zefiros-Software", 10 | "name": "P E Visscher" 11 | }, 12 | { 13 | "affiliation": "@Zefiros-Software", 14 | "name": "MickVanDuijn" 15 | }, 16 | { 17 | "name": "K M Visscher" 18 | } 19 | ], 20 | "access_right": "open", 21 | "license": "mit-license", 22 | "related_identifiers": [ 23 | { 24 | "scheme": "url", 25 | "identifier": "https://github.com/Zefiros-Software/BSPLib/tree/1.1.11", 26 | "relation": "isSupplementTo" 27 | }, 28 | { 29 | "scheme": "doi", 30 | "identifier": "10.5281/zenodo.1038558", 31 | "relation": "isPartOf" 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016-2018 Zefiros Software. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | url = "https://pypi.python.org/simple" 3 | verify_ssl = true 4 | 5 | [dev-packages] 6 | mkdocs = "*" 7 | mkdocs-bootswatch = "*" 8 | pymdown-extensions = "*" 9 | markdown-checklist = "*" 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BSPLib 2 | [BSPLib](http://bsplib.eu) is a fast, and easy to use C++ implementation of the Bulk Synchronous Parallel (BSP) threading model. This model is mainly used in the scientific computing field, but can also be applied more general in computer science. This library includes an extended version the standard BSP interface to perform better, and made it more easy to use. 3 | 4 | # Status 5 | Type | Status 6 | ----------- | ------- 7 | Linux & OSX | [![Build Status](https://travis-ci.org/Zefiros-Software/BSPLib.svg?branch=master)](https://travis-ci.org/Zefiros-Software/BSPLib) 8 | Windows | [![Build status](https://ci.appveyor.com/api/projects/status/g2aduvs6k7u3640r?svg=true)](https://ci.appveyor.com/project/PaulVisscher/bsplib) 9 | Coverage | [![codecov](https://codecov.io/gh/Zefiros-Software/BSPLib/branch/master/graph/badge.svg)](https://codecov.io/gh/Zefiros-Software/BSPLib) 10 | DOI | [![DOI](https://zenodo.org/badge/47649492.svg)](https://zenodo.org/badge/latestdoi/47649492) 11 | 12 | 13 | #Documentation 14 | The complete documentation can be found [here](http://bsplib.eu/). 15 | 16 | ## Why BSPLib? 17 | * Fast: All our code is hand optimised using profilers, to ensure maximum performance. 18 | * Reliable: We have an extensive testing suite, making sure we do not break forward and backward compatiblity. 19 | * Easy to use: The library is completely header only. Also next to our improved c++ interface, we shipped the 20 | classic BSP C interface. 21 | * Cross platform: Designed to only use C++11, with no external dependencies. 22 | * Warning free, compiled on the highest warning level. 23 | 24 | ## Bugs 25 | When a bug is found, please insert it in the issue tracker, so we can resolve it as quickly as we can. 26 | 27 | ## Contributing 28 | 1. Fork it! 29 | 2. Create your feature branch: `git checkout -b my-new-feature` 30 | 3. Commit your changes: `git commit -am 'Add some feature'` 31 | 4. Push to the branch: `git push origin my-new-feature` 32 | 5. Submit a pull request 33 | 34 | ## License 35 | This project is licensed under the MIT license by [Zefiros Software](https://zefiros.eu). 36 | 37 | ``` 38 | Copyright (c) 2017 Zefiros Software. 39 | 40 | Permission is hereby granted, free of charge, to any person obtaining a copy 41 | of this software and associated documentation files (the "Software"), to deal 42 | in the Software without restriction, including without limitation the rights 43 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 44 | copies of the Software, and to permit persons to whom the Software is 45 | furnished to do so, subject to the following conditions: 46 | 47 | The above copyright notice and this permission notice shall be included in 48 | all copies or substantial portions of the Software. 49 | 50 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 51 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 52 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 53 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 54 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 55 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 56 | THE SOFTWARE. 57 | ``` 58 | -------------------------------------------------------------------------------- /bsp/bsp.licenseheader: -------------------------------------------------------------------------------- 1 | extensions: .h .cpp .cc .hpp 2 | /** 3 | * @cond ___LICENSE___ 4 | * 5 | * Copyright (c) %CurrentYear% Zefiros Software. 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * @endcond 26 | * 27 | */ 28 | -------------------------------------------------------------------------------- /bsp/include/bsp/barrier.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @cond ___LICENSE___ 3 | * 4 | * Copyright (c) 2016-2018 Zefiros Software. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * @endcond 25 | */ 26 | #pragma once 27 | #ifndef __BSPLIB_BARRIER_H__ 28 | #define __BSPLIB_BARRIER_H__ 29 | 30 | #include "bsp/bspAbort.h" 31 | 32 | namespace BSPInternal 33 | { 34 | /** 35 | * A lock free barrier implementation. It spins until all threads reach the barrier. 36 | * This barrier uses busy waiting, and thus the performance is unstable, but fast. 37 | */ 38 | 39 | class Barrier 40 | { 41 | public: 42 | 43 | /** 44 | * Constructor. 45 | * 46 | * @param count Number of threads to wait for. 47 | */ 48 | 49 | explicit Barrier(uint32_t count) : 50 | mCount(count), 51 | mSpaces(count), 52 | mGeneration(0) 53 | { 54 | } 55 | 56 | /** 57 | * Sets the size of the barrier, thus the number of threads to wait for on a sync point. 58 | * 59 | * @param count Number of threads to wait on. 60 | * 61 | * @post The amount of threads the barriers waits on equals count. 62 | */ 63 | 64 | void SetSize(uint32_t count) 65 | { 66 | mCount = count; 67 | mSpaces = count; 68 | mGeneration = 0; 69 | } 70 | 71 | /** 72 | * Waits for all the threads to reach the sync point, however the process can be aborted when `aborted` equals to 73 | * true. 74 | * 75 | * @param [in,out] aborted Check whether the process should be aborted. 76 | * 77 | * @pre if aborted == true, all threads quit computations. 78 | * 79 | * @post all threads have waited for each other to reach the barrier. 80 | */ 81 | 82 | void Wait(const std::atomic_bool &aborted) 83 | { 84 | const uint32_t myGeneration = mGeneration; 85 | 86 | if (!--mSpaces) 87 | { 88 | mSpaces = mCount; 89 | ++mGeneration; 90 | } 91 | else 92 | { 93 | while (mGeneration == myGeneration) 94 | { 95 | if (aborted) 96 | { 97 | throw BspAbort("Aborted"); 98 | } 99 | } 100 | } 101 | } 102 | 103 | void NotifyAbort() 104 | { 105 | ++mGeneration; 106 | } 107 | 108 | private: 109 | 110 | /// The amount of threads to wait for in total 111 | uint32_t mCount; 112 | 113 | /// The amount of threads filling the barrier currently 114 | std::atomic_uint_fast32_t mSpaces; 115 | 116 | /// The current waiting generation, so we can reuse the barrier 117 | std::atomic_uint_fast32_t mGeneration; 118 | }; 119 | } 120 | 121 | #endif -------------------------------------------------------------------------------- /bsp/include/bsp/barrierType.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @cond ___LICENSE___ 3 | * 4 | * Copyright (c) 2016-2018 Zefiros Software. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * @endcond 25 | */ 26 | #pragma once 27 | #ifndef __BSPLIB_BARRIERTYPE_H__ 28 | #define __BSPLIB_BARRIERTYPE_H__ 29 | 30 | #include "bsp/condVarBarrier.h" 31 | #include "bsp/mixedBarrier.h" 32 | #include "bsp/barrier.h" 33 | 34 | #ifndef BSP_BARRIER_TYPE 35 | typedef BSPInternal::MixedBarrier tBarrier; 36 | #else 37 | typedef BSP_BARRIER_TYPE tBarrier; 38 | #endif 39 | 40 | #endif -------------------------------------------------------------------------------- /bsp/include/bsp/bsp.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @cond ___LICENSE___ 3 | * 4 | * Copyright (c) 2016-2018 Zefiros Software. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * @endcond 25 | */ 26 | #pragma once 27 | #ifndef __BSPLIB_BSP_H__ 28 | #define __BSPLIB_BSP_H__ 29 | 30 | #ifndef DEBUG 31 | # define BSP_SKIP_CHECKS 32 | #endif 33 | 34 | #include "bsp/bspExt.h" 35 | 36 | #ifndef BSP_DISABLE_NAMESPACE 37 | # define BSP_FULL_NAMESPACE BSP_NAMESPACE::Classic 38 | #else 39 | # define BSP_FULL_NAMESPACE ::Classic 40 | #endif 41 | 42 | #ifndef BSP_DISABLE_LEGACY 43 | 44 | /// Provides and overload to the old legacy interface 45 | 46 | #define bsp_init BSP_FULL_NAMESPACE::Init 47 | #define bsp_begin BSP_FULL_NAMESPACE::Begin 48 | #define bsp_end BSP_FULL_NAMESPACE::End 49 | #define bsp_pid BSP_FULL_NAMESPACE::ProcId 50 | #define bsp_nprocs BSP_FULL_NAMESPACE::NProcs 51 | #define bsp_abort BSP_FULL_NAMESPACE::Abort 52 | #define bsp_vabort BSP_FULL_NAMESPACE::VAbort 53 | #define bsp_sync BSP_FULL_NAMESPACE::Sync 54 | #define bsp_time BSP_FULL_NAMESPACE::Time 55 | #define bsp_push_reg BSP_FULL_NAMESPACE::Push 56 | #define bsp_pop_reg BSP_FULL_NAMESPACE::Pop 57 | #define bsp_put BSP_FULL_NAMESPACE::Put 58 | #define bsp_get BSP_FULL_NAMESPACE::Get 59 | #define bsp_set_tagsize BSP_FULL_NAMESPACE::SetTagSize 60 | #define bsp_send BSP_FULL_NAMESPACE::Send 61 | #define bsp_hpsend BSP_FULL_NAMESPACE::HPSend 62 | #define bsp_qsize BSP_FULL_NAMESPACE::QSize 63 | #define bsp_get_tag BSP_FULL_NAMESPACE::GetTag 64 | #define bsp_move BSP_FULL_NAMESPACE::Move 65 | #define bsp_hpmove BSP_FULL_NAMESPACE::HPMove 66 | #define bsp_hpput BSP_FULL_NAMESPACE::HPPut 67 | #define bsp_hpget BSP_FULL_NAMESPACE::HPGet 68 | 69 | #endif 70 | 71 | #endif -------------------------------------------------------------------------------- /bsp/include/bsp/bspAbort.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @cond ___LICENSE___ 3 | * 4 | * Copyright (c) 2016-2018 Zefiros Software. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * @endcond 25 | */ 26 | #pragma once 27 | #ifndef __BSPLIB_BSPABORT_H__ 28 | #define __BSPLIB_BSPABORT_H__ 29 | 30 | #include 31 | #include 32 | 33 | namespace BSPInternal 34 | { 35 | /** 36 | * A bsp abort exception. By inherriting from std::exception we can throw 37 | * this exception to abort all threads from continuing easily. 38 | * 39 | * @sa std::exception 40 | */ 41 | 42 | class BspAbort 43 | : public std::exception 44 | { 45 | public: 46 | 47 | /** 48 | * Constructor. 49 | * 50 | * @param m The error message. 51 | */ 52 | 53 | explicit BspAbort(std::string m) 54 | : msg(m) 55 | { 56 | } 57 | 58 | ~BspAbort() throw() 59 | { 60 | } 61 | 62 | virtual const char *what() const throw() override 63 | { 64 | return msg.c_str(); 65 | } 66 | 67 | private: 68 | 69 | std::string msg; 70 | }; 71 | }; 72 | 73 | #endif -------------------------------------------------------------------------------- /bsp/include/bsp/bspProf.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @cond ___LICENSE___ 3 | * 4 | * Copyright (c) 2016-2018 Zefiros Software. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * @endcond 25 | */ 26 | #pragma once 27 | #ifndef __BSPLIB_BSPPROF_H__ 28 | #define __BSPLIB_BSPPROF_H__ 29 | 30 | #include "bsp/bspClass.h" 31 | #include "bsp/util.h" 32 | 33 | #include 34 | 35 | namespace BSPProf 36 | { 37 | inline void MarkSuperstep() 38 | { 39 | BSP::GetInstance().MarkSuperstep(); 40 | } 41 | 42 | inline void MarkSuperstep(uint32_t superstep) 43 | { 44 | BSP::GetInstance().MarkSuperstep(superstep); 45 | } 46 | 47 | inline void PauseRecording() 48 | { 49 | BSP::GetInstance().PauseRecording(); 50 | } 51 | 52 | inline void ResumeRecording() 53 | { 54 | BSP::GetInstance().ResumeRecording(); 55 | } 56 | 57 | inline void InitCommunication() 58 | { 59 | BSP::GetInstance().InitCommunication(); 60 | } 61 | 62 | inline void FinishCommunication() 63 | { 64 | BSP::GetInstance().FinishCommunication(); 65 | } 66 | } 67 | 68 | #endif -------------------------------------------------------------------------------- /bsp/include/bsp/communicationQueues.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @cond ___LICENSE___ 3 | * 4 | * Copyright (c) 2016-2018 Zefiros Software. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * @endcond 25 | */ 26 | #pragma once 27 | #ifndef __BSPLIB_COMMUNICATIONQUEUES_H__ 28 | #define __BSPLIB_COMMUNICATIONQUEUES_H__ 29 | 30 | #include 31 | 32 | 33 | namespace BSPInternal 34 | { 35 | /** 36 | * A communication queue implementation. Allows easier 37 | * implementation of communication queues of various types. 38 | * 39 | * @tparam tQueue Type of the queue. 40 | */ 41 | 42 | template< typename tQueue > 43 | class CommunicationQueues 44 | { 45 | public: 46 | 47 | CommunicationQueues() 48 | : mProcCount(0) 49 | { 50 | } 51 | 52 | /** 53 | * Constructor. 54 | * 55 | * @param nProcs The amount of processors that can use the queue. 56 | */ 57 | 58 | explicit CommunicationQueues(std::size_t nProcs) 59 | : mQueues(0), 60 | mProcCount(nProcs) 61 | { 62 | ResetResize(nProcs); 63 | } 64 | 65 | /** 66 | * Resets the queues, and set the maximum amount of threads that may 67 | * use the communication queue. 68 | * 69 | * @param maxProcs The maximum number of processors. 70 | */ 71 | 72 | void ResetResize(std::size_t maxProcs) 73 | { 74 | //std::size_t maxProcsSqr = maxProcs * maxProcs; 75 | mQueues.clear(); 76 | mQueues.resize(maxProcs); 77 | 78 | for (auto &queue : mQueues) 79 | { 80 | queue.resize(maxProcs); 81 | } 82 | 83 | mProcCount = maxProcs; 84 | } 85 | 86 | /** 87 | * Gets the queues of the source processor communicating to the current processor. 88 | * 89 | * @param source Source to get the queues from. 90 | * @param me Processors to get the queues to. 91 | * 92 | * @return The queue. 93 | */ 94 | 95 | inline tQueue &GetQueueToMe(std::size_t source, std::size_t me) 96 | { 97 | return GetQueue(source, me); 98 | } 99 | 100 | /** 101 | * Gets the queues of the current processor communicating to the source processor. 102 | * 103 | * @param target The processor to get the queues for. 104 | * @param me The processor to get the queues from. 105 | * 106 | * @return The queue. 107 | */ 108 | 109 | inline tQueue &GetQueueFromMe(std::size_t target, std::size_t me) 110 | { 111 | return GetQueue(me, target); 112 | } 113 | 114 | private: 115 | 116 | std::vector< std::vector< tQueue >> mQueues; 117 | 118 | /// The amount of processors that may use the queue 119 | std::size_t mProcCount; 120 | 121 | tQueue &GetQueue(std::size_t owner, std::size_t target) 122 | { 123 | return mQueues[owner][target]; 124 | } 125 | }; 126 | } 127 | 128 | #endif -------------------------------------------------------------------------------- /bsp/include/bsp/condVarBarrier.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @cond ___LICENSE___ 3 | * 4 | * Copyright (c) 2016-2018 Zefiros Software. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * @endcond 25 | */ 26 | #pragma once 27 | #ifndef __BSPLIB_CONDVARBARRIER_H__ 28 | #define __BSPLIB_CONDVARBARRIER_H__ 29 | 30 | #include "bsp/bspAbort.h" 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | namespace BSPInternal 37 | { 38 | /** 39 | * A condition variable barrier implementation. This barrier 40 | * does not use busy waiting, but relies on events in stead. 41 | * The advantage of this approach is that is more reliable, 42 | * however there is a lot of overhead. 43 | */ 44 | 45 | class CondVarBarrier 46 | { 47 | public: 48 | 49 | /** 50 | * Constructor. 51 | * 52 | * @param count Number of threads to wait for. 53 | */ 54 | 55 | explicit CondVarBarrier(std::size_t count) 56 | : mCurrentCon(&mConVar1), 57 | mPreviousCon(&mConVar2), 58 | mCount(count), 59 | mMax(count) 60 | { 61 | } 62 | 63 | /** 64 | * Sets the size of the barrier, thus the number of threads to wait for on a sync point. 65 | * 66 | * @param count Number of threads to wait on. 67 | * 68 | * @post The amount of threads the barriers waits on equals count. 69 | */ 70 | 71 | void SetSize(size_t count) 72 | { 73 | mCount = count; 74 | mMax = count; 75 | } 76 | 77 | /** 78 | * Waits for all the threads to reach the sync point, however the process can be aborted when `aborted` equals to 79 | * true. 80 | * 81 | * @param [in,out] aborted Check whether the process should be aborted. 82 | * 83 | * @pre if aborted == true, all threads quit computations. 84 | * 85 | * @post all threads have waited for each other to reach the barrier. 86 | */ 87 | 88 | void Wait(const std::atomic_bool &aborted) 89 | { 90 | std::unique_lock lock(mMutex); 91 | 92 | if (aborted) 93 | { 94 | mCurrentCon->notify_all(); 95 | throw BspAbort("Aborted"); 96 | } 97 | 98 | if (--mCount == 0) 99 | { 100 | Reset(); 101 | } 102 | else 103 | { 104 | mCurrentCon->wait(lock); 105 | } 106 | } 107 | 108 | private: 109 | 110 | std::mutex mMutex; 111 | std::condition_variable mConVar1; 112 | std::condition_variable mConVar2; 113 | 114 | std::condition_variable *mCurrentCon; 115 | std::condition_variable *mPreviousCon; 116 | 117 | size_t mCount; 118 | size_t mMax; 119 | 120 | /** 121 | * Resets the barrier for reuse. 122 | */ 123 | 124 | void Reset() 125 | { 126 | mCount = mMax; 127 | std::condition_variable *tmpCon = mCurrentCon; 128 | mCurrentCon = mPreviousCon; 129 | mPreviousCon = tmpCon; 130 | 131 | tmpCon->notify_all(); 132 | } 133 | }; 134 | } 135 | 136 | #endif -------------------------------------------------------------------------------- /bsp/include/bsp/historyRecorderType.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @cond ___LICENSE___ 3 | * 4 | * Copyright (c) 2016-2018 Zefiros Software. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * @endcond 25 | */ 26 | #pragma once 27 | #ifndef __BSPLIB_HISTORYRECORDERTYPE_H__ 28 | #define __BSPLIB_HISTORYRECORDERTYPE_H__ 29 | 30 | #include "bsp/historyRecorder.h" 31 | #include "bsp/voidRecorder.h" 32 | 33 | #ifndef BSP_USE_PROFILER 34 | typedef VoidRecorder tHistoryRecorder; 35 | #else 36 | # ifndef BSP_HISTORYRECORDER_TYPE 37 | typedef HistoryRecorder < HistoryType::MatrixData | HistoryType::AnyData | HistoryType::GroupedTimeBars | 38 | HistoryType::DistancedBars | HistoryType::MessageSize | HistoryType::MessageCount > tHistoryRecorder; 39 | # else 40 | typedef BSP_HISTORYRECORDER_TYPE tHistoryRecorder; 41 | # endif 42 | #endif 43 | 44 | #endif -------------------------------------------------------------------------------- /bsp/include/bsp/mixedBarrier.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @cond ___LICENSE___ 3 | * 4 | * Copyright (c) 2016-2018 Zefiros Software. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * @endcond 25 | */ 26 | #pragma once 27 | #ifndef __BSPLIB_MIXEDBARRIER_H__ 28 | #define __BSPLIB_MIXEDBARRIER_H__ 29 | 30 | #define BSP_SPIN_ITERATIONS 20000 31 | 32 | #include "bsp/bspAbort.h" 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | namespace BSPInternal 39 | { 40 | /** 41 | * A mixed barrier implementation. Since the lock free barrier is instable, and the condition variable barrier is 42 | * slow but stable. This barrier implements a combination of both combining the speed of the lockfree barrier, with 43 | * the stability of the condvar barrier. 44 | */ 45 | 46 | class MixedBarrier 47 | { 48 | public: 49 | 50 | /** 51 | * Constructor. 52 | * 53 | * @param count Number of threads to wait for. 54 | */ 55 | 56 | explicit MixedBarrier(uint32_t count) 57 | : mCurrentCon(&mConVar1), 58 | mPreviousCon(&mConVar2), 59 | mCount(count), 60 | mMax(count), 61 | mSpaces(count) 62 | { 63 | } 64 | 65 | /** 66 | * Sets the size of the barrier, thus the number of threads to wait for on a sync point. 67 | * 68 | * @param count Number of threads to wait on. 69 | * 70 | * @post The amount of threads the barriers waits on equals count. 71 | */ 72 | 73 | void SetSize(uint32_t count) 74 | { 75 | mCount = count; 76 | mMax = count; 77 | mSpaces = count; 78 | } 79 | 80 | /** 81 | * Waits for all the threads to reach the sync point, however the process can be aborted when `aborted` equals to 82 | * true. 83 | * 84 | * @param [in,out] aborted Check whether the process should be aborted. 85 | * 86 | * @pre if aborted == true, all threads quit computations. 87 | * 88 | * @post all threads have waited for each other to reach the barrier. 89 | */ 90 | 91 | void Wait(const std::atomic_bool &aborted) 92 | { 93 | const uint32_t myGeneration = mGeneration; 94 | 95 | if (aborted) 96 | { 97 | Abort(); 98 | } 99 | 100 | if (!--mSpaces) 101 | { 102 | mSpaces = mMax; 103 | std::lock_guard< std::mutex > condVarLoc(mCondVarMutex); 104 | ++mGeneration; 105 | Reset(); 106 | } 107 | else 108 | { 109 | size_t i = 0; 110 | 111 | while (mGeneration == myGeneration && ++i < BSP_SPIN_ITERATIONS) 112 | { 113 | if ((i & 127) == 0 && aborted) 114 | { 115 | Abort(); 116 | } 117 | } 118 | 119 | if (i >= BSP_SPIN_ITERATIONS) 120 | { 121 | std::unique_lock< std::mutex > condVarLoc(mCondVarMutex); 122 | mCurrentCon->wait(condVarLoc, [&] {return mGeneration != myGeneration || aborted;}); 123 | } 124 | } 125 | 126 | if (aborted) 127 | { 128 | mCurrentCon->notify_all(); 129 | throw BspAbort("Aborted"); 130 | } 131 | } 132 | 133 | void NotifyAbort() 134 | { 135 | mCurrentCon->notify_all(); 136 | ++mGeneration; 137 | } 138 | 139 | private: 140 | 141 | std::mutex mCondVarMutex; 142 | std::condition_variable mConVar1; 143 | std::condition_variable mConVar2; 144 | 145 | std::condition_variable *mCurrentCon; 146 | std::condition_variable *mPreviousCon; 147 | 148 | uint32_t mCount; 149 | uint32_t mMax; 150 | 151 | std::atomic_uint_fast32_t mSpaces; 152 | std::atomic_uint_fast32_t mGeneration; 153 | 154 | void Reset() 155 | { 156 | mCount = mMax; 157 | std::condition_variable *tmpCon = mCurrentCon; 158 | mCurrentCon = mPreviousCon; 159 | mPreviousCon = tmpCon; 160 | 161 | tmpCon->notify_all(); 162 | } 163 | 164 | void Abort() 165 | { 166 | mCurrentCon->notify_all(); 167 | throw BspAbort("Aborted"); 168 | } 169 | 170 | }; 171 | } 172 | 173 | #endif -------------------------------------------------------------------------------- /bsp/include/bsp/processorData.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @cond ___LICENSE___ 3 | * 4 | * Copyright (c) 2016-2018 Zefiros Software. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * @endcond 25 | */ 26 | #pragma once 27 | #ifndef __BSPLIB_PROCESSORDATA_H__ 28 | #define __BSPLIB_PROCESSORDATA_H__ 29 | 30 | #include "bsp/registerMapType.h" 31 | #include "bsp/stackAllocator.h" 32 | #include "bsp/requestVector.h" 33 | #include "bsp/barrierType.h" 34 | 35 | struct ProcessorData 36 | { 37 | ProcessorData() 38 | : sendReceivedIndex(0), 39 | registerCount(0), 40 | newTagSize(0), 41 | sendRequestsSize(0), 42 | pushRequestsSize(0), 43 | popRequestsSize(0), 44 | putBufferStack(9064), 45 | getBufferStack(9064), 46 | sendBufferStack(9064) 47 | { 48 | sendRequests.Reserve(9064); 49 | pushRequests.Reserve(9064); 50 | popRequests.Reserve(9064); 51 | 52 | } 53 | 54 | uint32_t sendReceivedIndex; 55 | uint32_t registerCount; 56 | uint32_t newTagSize; 57 | uint32_t sendRequestsSize; 58 | uint32_t pushRequestsSize; 59 | uint32_t popRequestsSize; 60 | BSPInternal::StackAllocator putBufferStack; 61 | BSPInternal::StackAllocator getBufferStack; 62 | BSPInternal::StackAllocator sendBufferStack; 63 | std::vector tmpSendBufferStacks; 64 | BSPUtil::TicTimer startTimer; 65 | BSPUtil::TicTimer ticTimer; 66 | std::vector> putRequests; 67 | std::vector> getRequests; 68 | std::vector> bufferedGetRequests; 69 | std::vector> tmpSendRequests; 70 | BSPInternal::RequestVector< BSPInternal::SendRequest > sendRequests; 71 | BSPInternal::RequestVector< BSPInternal::PushRequest > pushRequests; 72 | BSPInternal::RequestVector< BSPInternal::PopRequest > popRequests; 73 | tRegisterMap threadRegisters; 74 | 75 | struct 76 | { 77 | bool hasPutRequests = false; 78 | bool hasGetRequests = false; 79 | bool hasPushRequests = false; 80 | bool hasPopRequests = false; 81 | bool hasSendRequests = false; 82 | bool hasTagSizeUpdate = false; 83 | } syncBools; 84 | }; 85 | 86 | #endif -------------------------------------------------------------------------------- /bsp/include/bsp/registerMapType.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @cond ___LICENSE___ 3 | * 4 | * Copyright (c) 2016-2018 Zefiros Software. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * @endcond 25 | */ 26 | #pragma once 27 | #ifndef __BSPLIB_REGISTERMAPTYPE_H__ 28 | #define __BSPLIB_REGISTERMAPTYPE_H__ 29 | 30 | #include "bsp/threadRegisterVector.h" 31 | #include "bsp/threadRegisterMap.h" 32 | 33 | #ifndef BSP_REGISTERMAP_TYPE 34 | typedef BSPInternal::ThreadRegisterVector tRegisterMap; 35 | #else 36 | typedef BSP_REGISTERMAP_TYPE tRegisterMap; 37 | #endif 38 | 39 | #endif -------------------------------------------------------------------------------- /bsp/include/bsp/requestVector.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @cond ___LICENSE___ 3 | * 4 | * Copyright (c) 2016-2018 Zefiros Software. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * @endcond 25 | */ 26 | #pragma once 27 | #ifndef __BSPLIB_REQUESTVECTOR_H__ 28 | #define __BSPLIB_REQUESTVECTOR_H__ 29 | 30 | #include "bsp/requests.h" 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | namespace BSPInternal 37 | { 38 | template< typename tRequest > 39 | class RequestVector 40 | { 41 | public: 42 | 43 | RequestVector() 44 | : mRequests(10), 45 | mCursor(0), 46 | mSize(10) 47 | { 48 | } 49 | 50 | /** 51 | * Constructor. 52 | * 53 | * @param size The number of requests. 54 | */ 55 | 56 | RequestVector(size_t size) 57 | : mRequests(size), 58 | mCursor(0), 59 | mSize(size) 60 | { 61 | } 62 | 63 | tRequest &GetRequest(size_t index) 64 | { 65 | return mRequests[index]; 66 | } 67 | 68 | tRequest &InitRequest() 69 | { 70 | if (mCursor >= mSize) 71 | { 72 | Grow(); 73 | } 74 | 75 | return mRequests[mCursor++]; 76 | } 77 | 78 | tRequest &operator[](size_t index) 79 | { 80 | return mRequests[index]; 81 | } 82 | 83 | const tRequest &operator[](size_t index) const 84 | { 85 | return mRequests[index]; 86 | } 87 | 88 | size_t GetSize() const 89 | { 90 | return mCursor; 91 | } 92 | 93 | void Reserve(size_t size) 94 | { 95 | if (size > mSize - mCursor) 96 | { 97 | mRequests.resize(mCursor + size); 98 | mSize = mRequests.size(); 99 | } 100 | } 101 | 102 | void Clear() 103 | { 104 | mCursor = 0; 105 | } 106 | 107 | bool Empty() const 108 | { 109 | return mCursor == 0; 110 | } 111 | 112 | typename std::vector< tRequest >::reverse_iterator RBegin() 113 | { 114 | return mRequests.rend() - mCursor; 115 | } 116 | 117 | typename std::vector< tRequest >::reverse_iterator REnd() 118 | { 119 | return mRequests.rend(); 120 | } 121 | 122 | typename std::vector< tRequest >::iterator Begin() 123 | { 124 | return mRequests.begin(); 125 | } 126 | 127 | typename std::vector< tRequest >::iterator End() 128 | { 129 | return mRequests.begin() + mCursor; 130 | } 131 | 132 | typename std::vector< tRequest >::const_reverse_iterator CRBegin() const 133 | { 134 | return mRequests.crend() - mCursor; 135 | } 136 | 137 | typename std::vector< tRequest >::const_reverse_iterator CREnd() const 138 | { 139 | return mRequests.crend(); 140 | } 141 | 142 | typename std::vector< tRequest >::const_iterator CBegin() const 143 | { 144 | return mRequests.cbegin(); 145 | } 146 | 147 | typename std::vector< tRequest >::const_iterator CEnd() const 148 | { 149 | return mRequests.cbegin() + mCursor; 150 | } 151 | 152 | template< typename tIterator > 153 | void Append(tIterator begin, tIterator end) 154 | { 155 | Reserve(end - begin); 156 | 157 | std::copy(begin, end, End()); 158 | 159 | mCursor += end - begin; 160 | } 161 | 162 | private: 163 | 164 | std::vector< tRequest > mRequests; 165 | 166 | size_t mCursor; 167 | size_t mSize; 168 | 169 | void Grow() 170 | { 171 | mRequests.resize(static_cast(mSize * 1.6f) + 1); 172 | mSize = mRequests.size(); 173 | } 174 | }; 175 | } 176 | 177 | #endif -------------------------------------------------------------------------------- /bsp/include/bsp/requests.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @cond ___LICENSE___ 3 | * 4 | * Copyright (c) 2016-2018 Zefiros Software. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * @endcond 25 | */ 26 | #pragma once 27 | #ifndef __BSPLIB_REQUESTS_H__ 28 | #define __BSPLIB_REQUESTS_H__ 29 | 30 | #include "bsp/stackAllocator.h" 31 | 32 | #include 33 | 34 | namespace BSPInternal 35 | { 36 | struct RegisterInfo 37 | { 38 | uint32_t size; 39 | uint32_t registerCount; 40 | }; 41 | 42 | struct PutRequest 43 | { 44 | StackAllocator::StackLocation bufferLocation; 45 | //const void *destination; 46 | ptrdiff_t offset; 47 | uint32_t globalId; 48 | uint32_t size; 49 | }; 50 | 51 | struct GetRequest 52 | { 53 | const void *destination; 54 | uint32_t globalId; 55 | ptrdiff_t offset; 56 | uint32_t size; 57 | }; 58 | 59 | struct BufferedGetRequest 60 | { 61 | StackAllocator::StackLocation bufferLocation; 62 | const void *destination; 63 | uint32_t size; 64 | }; 65 | 66 | struct SendRequest 67 | { 68 | StackAllocator::StackLocation bufferLocation; 69 | uint32_t bufferSize; 70 | 71 | StackAllocator::StackLocation tagLocation; 72 | uint32_t tagSize; 73 | 74 | void From(const SendRequest &request) 75 | { 76 | bufferLocation = request.bufferLocation; 77 | bufferSize = request.bufferSize; 78 | tagLocation = request.tagLocation; 79 | tagSize = request.tagSize; 80 | } 81 | }; 82 | 83 | struct PushRequest 84 | { 85 | const void *pushRegister; 86 | RegisterInfo registerInfo; 87 | }; 88 | 89 | struct PopRequest 90 | { 91 | const void *popRegister; 92 | }; 93 | 94 | } 95 | 96 | #endif -------------------------------------------------------------------------------- /bsp/include/bsp/spinLock.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @cond ___LICENSE___ 3 | * 4 | * Copyright (c) 2016-2018 Zefiros Software. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * @endcond 25 | */ 26 | #pragma once 27 | #ifndef __BSPLIB_SPINLOCK_H__ 28 | #define __BSPLIB_SPINLOCK_H__ 29 | 30 | #include 31 | 32 | namespace BSPInternal 33 | { 34 | class SpinLock 35 | { 36 | public: 37 | 38 | SpinLock() 39 | { 40 | } 41 | 42 | void lock() 43 | { 44 | while (mLockValue.test_and_set(std::memory_order_acquire)) 45 | { 46 | } 47 | } 48 | 49 | bool try_lock() 50 | { 51 | return !mLockValue.test_and_set(std::memory_order_acquire); 52 | } 53 | 54 | void unlock() 55 | { 56 | mLockValue.clear(std::memory_order_release); 57 | } 58 | 59 | private: 60 | 61 | std::atomic_flag mLockValue; 62 | 63 | SpinLock(const SpinLock &); 64 | }; 65 | } 66 | 67 | #endif -------------------------------------------------------------------------------- /bsp/include/bsp/stackAllocator.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @cond ___LICENSE___ 3 | * 4 | * Copyright (c) 2016-2018 Zefiros Software. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * @endcond 25 | */ 26 | #pragma once 27 | #ifndef __BSPLIB_STACKALLOCATOR_H__ 28 | #define __BSPLIB_STACKALLOCATOR_H__ 29 | 30 | #include "util.h" 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | namespace BSPInternal 37 | { 38 | /** 39 | * A stack allocator implementation, that will allocate memory in contiguous memory on the stack, 40 | * optimising cache line efficiency. 41 | */ 42 | 43 | class StackAllocator 44 | { 45 | public: 46 | 47 | typedef std::ptrdiff_t StackLocation; 48 | 49 | /** 50 | * Default constructor. Starts with byte size 10. 51 | */ 52 | 53 | StackAllocator() 54 | : mStack(10, '@'), 55 | mCursor(0), 56 | mSize(10) 57 | { 58 | } 59 | 60 | /** 61 | * Constructor. 62 | * 63 | * @param size The size in bytes. 64 | */ 65 | 66 | StackAllocator(size_t size) 67 | : mStack(size, '@'), 68 | mCursor(0), 69 | mSize(size) 70 | { 71 | } 72 | 73 | /** 74 | * Check whether an object of given amount of its in stack. 75 | * 76 | * @param size The size of the object in bytes. 77 | * 78 | * @return true if it will succeed, false if it fails. 79 | */ 80 | 81 | BSP_FORCEINLINE bool FitsInStack(size_t size) const 82 | { 83 | return mCursor + size < mSize; 84 | } 85 | 86 | /** 87 | * Allocates the given amount of bytes on the stack. With content as pointer to 88 | * what we want to allocate on the stack. (due to resizing invalidation we cannot return a pointer) 89 | * 90 | * @param size The size of the content in bytes. 91 | * @param content The content to place on the stack. 92 | * 93 | * @return A StackLocation that refers to the object. 94 | */ 95 | 96 | BSP_FORCEINLINE StackLocation Alloc(size_t size, const char *content) 97 | { 98 | if (!FitsInStack(size)) 99 | { 100 | Grow(size); 101 | } 102 | 103 | const StackLocation loc = mCursor; 104 | char *buffer = mStack.data() + loc; 105 | memcpy(buffer, content, size); 106 | 107 | mCursor += size; 108 | 109 | return loc; 110 | } 111 | 112 | /** 113 | * Extracts this object on the given stack location. 114 | * 115 | * @param location The location to read the memory from. 116 | * @param size The size in bytes. 117 | * @param [in,out] dst If non-null, destination to read the object to. 118 | */ 119 | 120 | inline void Extract(StackLocation location, size_t size, char *dst) const 121 | { 122 | memcpy(dst, mStack.data() + location, size); 123 | } 124 | 125 | /** 126 | * Clears this object to its blank/initial state. 127 | */ 128 | 129 | inline void Clear() 130 | { 131 | mCursor = 0; 132 | } 133 | 134 | /** 135 | * Merges two stackallocator to one large stack allocator. 136 | * 137 | * @param [in,out] sa The stack allocator. 138 | */ 139 | 140 | inline void Merge(StackAllocator &sa) 141 | { 142 | Alloc(sa.mCursor, sa.mStack.data()); 143 | } 144 | 145 | /** 146 | * Gets the size of the stack. 147 | * 148 | * @return A StackLocation. 149 | */ 150 | 151 | inline StackLocation Size() const 152 | { 153 | return mCursor; 154 | } 155 | 156 | inline bool Empty() const 157 | { 158 | return mCursor == 0; 159 | } 160 | 161 | private: 162 | 163 | /// The stack buffer 164 | std::vector< char > mStack; 165 | /// The current size of the stack 166 | StackLocation mCursor; 167 | size_t mSize; 168 | 169 | /** 170 | * Grows the stack with a rate of phi, which is mathematically the most efficient 171 | * growing rate. [See also](https://crntaylor.wordpress.com/2011/07/15/optimal-memory-reallocation-and-the-golden-ratio/). 172 | * 173 | * @param size The size to at least be able to allocate. 174 | */ 175 | 176 | BSP_FORCEINLINE void Grow(size_t size) 177 | { 178 | mStack.resize(static_cast(mSize * 1.6f) + size, '~'); 179 | mSize = mStack.size(); 180 | } 181 | }; 182 | } 183 | 184 | #endif -------------------------------------------------------------------------------- /bsp/include/bsp/threadRegisterMap.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @cond ___LICENSE___ 3 | * 4 | * Copyright (c) 2016-2018 Zefiros Software. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * @endcond 25 | */ 26 | #pragma once 27 | #ifndef __BSPLIB_THREADREGISTERMAP_H__ 28 | #define __BSPLIB_THREADREGISTERMAP_H__ 29 | 30 | #include "bsp/requests.h" 31 | 32 | #include 33 | #include 34 | 35 | namespace BSPInternal 36 | { 37 | class ThreadRegisterMap 38 | { 39 | public: 40 | 41 | inline uint32_t LocalToGlobal(const void *reg) 42 | { 43 | return mRegisters.find(reg)->second.registerCount; 44 | } 45 | 46 | inline const void *GlobalToLocal(uint32_t globalId) 47 | { 48 | return mThreadRegisterLocations[globalId]; 49 | } 50 | 51 | inline void Insert(const void *reg, const BSPInternal::RegisterInfo ®isterInfo) 52 | { 53 | mRegisters[reg] = registerInfo; 54 | mThreadRegisterLocations.push_back(reg); 55 | } 56 | 57 | inline void Erase(const void *reg) 58 | { 59 | //mThreadRegisterLocations[LocalToGlobal( reg )] = nullptr; 60 | mRegisters.erase(reg); 61 | } 62 | 63 | private: 64 | 65 | std::map< const void *, RegisterInfo > mRegisters; 66 | std::vector< const void * > mThreadRegisterLocations; 67 | }; 68 | } 69 | 70 | #endif -------------------------------------------------------------------------------- /bsp/include/bsp/threadRegisterVector.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @cond ___LICENSE___ 3 | * 4 | * Copyright (c) 2016-2018 Zefiros Software. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * @endcond 25 | */ 26 | #pragma once 27 | #ifndef __BSPLIB_THREADREGISTERVECTOR_H__ 28 | #define __BSPLIB_THREADREGISTERVECTOR_H__ 29 | 30 | #include "bsp/requests.h" 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | namespace BSPInternal 37 | { 38 | class ThreadRegisterVector 39 | { 40 | public: 41 | 42 | ThreadRegisterVector() 43 | : mRegisterCache(nullptr), 44 | mLocationCache((uint32_t)(-1)) 45 | { 46 | 47 | } 48 | 49 | BSP_FORCEINLINE uint32_t LocalToGlobal(const void *reg) 50 | { 51 | if (reg != mRegisterCache) 52 | { 53 | auto l = std::lower_bound(mRegisters.begin(), mRegisters.end(), reg); 54 | 55 | mRegisterCache = reg; 56 | mLocationCache = mRegistersInfo[l - mRegisters.begin()].registerCount; 57 | } 58 | 59 | return mLocationCache; 60 | } 61 | 62 | BSP_FORCEINLINE const void *GlobalToLocal(uint32_t globalId) 63 | { 64 | if (mLocationCache == globalId) 65 | { 66 | return mRegisterCache; 67 | } 68 | 69 | mLocationCache = globalId; 70 | mRegisterCache = mThreadRegisterLocations[globalId]; 71 | 72 | return mRegisterCache; 73 | } 74 | 75 | inline void Insert(const void *reg, const BSPInternal::RegisterInfo ®isterInfo) 76 | { 77 | if (mRegisters.empty()) 78 | { 79 | mRegisters.push_back(reg); 80 | mRegistersInfo.emplace_back(registerInfo); 81 | mThreadRegisterLocations.push_back(reg); 82 | return; 83 | } 84 | 85 | auto l = std::lower_bound(mRegisters.begin(), mRegisters.end(), reg); 86 | 87 | if (l != mRegisters.end() && *l == reg) 88 | { 89 | mRegistersInfo[l - mRegisters.begin()] = registerInfo; 90 | mThreadRegisterLocations.push_back(reg); 91 | } 92 | else 93 | { 94 | mRegistersInfo.insert(mRegistersInfo.begin() + (l - mRegisters.begin()), registerInfo); 95 | mRegisters.insert(l, reg); 96 | mThreadRegisterLocations.push_back(reg); 97 | } 98 | } 99 | 100 | inline void Erase(const void *reg) 101 | { 102 | auto regIt = std::find(mRegisters.begin(), mRegisters.end(), reg); 103 | 104 | if (regIt != mRegisters.end()) 105 | { 106 | mRegistersInfo.erase(mRegistersInfo.begin() + (regIt - mRegisters.begin())); 107 | mRegisters.erase(regIt); 108 | } 109 | } 110 | 111 | size_t GetSize() const 112 | { 113 | return mThreadRegisterLocations.size(); 114 | } 115 | 116 | private: 117 | 118 | std::vector< const void * > mRegisters; 119 | std::vector< RegisterInfo > mRegistersInfo; 120 | 121 | std::vector< const void * > mThreadRegisterLocations; 122 | 123 | const void *mRegisterCache; 124 | uint32_t mLocationCache; 125 | }; 126 | } 127 | 128 | #endif -------------------------------------------------------------------------------- /bsp/include/bsp/util.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @cond ___LICENSE___ 3 | * 4 | * Copyright (c) 2016-2018 Zefiros Software. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * @endcond 25 | */ 26 | #pragma once 27 | #ifndef __BSPLIB_UTIL_H__ 28 | #define __BSPLIB_UTIL_H__ 29 | 30 | // From boost. Forces inlining on multiple compilers for extra perfomance. 31 | #if !defined(BSP_FORCEINLINE) 32 | # if defined(_MSC_VER) 33 | # define BSP_FORCEINLINE __forceinline 34 | # elif defined(__GNUC__) && __GNUC__ > 3 35 | // Clang also defines __GNUC__ (as 4) 36 | # define BSP_FORCEINLINE inline __attribute__ ((__always_inline__)) 37 | # else 38 | # define BSP_FORCEINLINE inline 39 | # endif 40 | #endif 41 | 42 | 43 | #if !defined(BSP_TLS) 44 | # if defined(_MSC_VER) 45 | # define BSP_TLS __declspec(thread) 46 | # elif defined(__GNUC__) && __GNUC__ > 3 47 | // Clang also defines __GNUC__ (as 4) 48 | # define BSP_TLS __thread 49 | # else 50 | # error "Define a thread local storage qualifier for your compiler/platform!" 51 | # endif 52 | #endif 53 | 54 | #include 55 | 56 | namespace BSPUtil 57 | { 58 | template< typename tLoopIterator, typename tFunc> 59 | BSP_FORCEINLINE void SplitFor(tLoopIterator begin, tLoopIterator end, tLoopIterator start, const tFunc &body) 60 | { 61 | for (tLoopIterator it = start; it < end; ++it) 62 | { 63 | body(it); 64 | } 65 | 66 | for (tLoopIterator it = begin; it < start; ++it) 67 | { 68 | body(it); 69 | } 70 | } 71 | 72 | template< bool tCondition > 73 | class StaticIfUnreached 74 | { 75 | public: 76 | 77 | template< typename tFuncIf > 78 | StaticIfUnreached(const tFuncIf &) 79 | { 80 | } 81 | 82 | template< bool tElseIfCondition, typename tFuncElseIf > 83 | StaticIfUnreached< tElseIfCondition > ElseIf(const tFuncElseIf &elseIfBody) 84 | { 85 | return StaticIfUnreached< tElseIfCondition >(elseIfBody); 86 | } 87 | 88 | template< typename tFuncElse > 89 | void Else(const tFuncElse &) 90 | { 91 | } 92 | }; 93 | 94 | template< bool tCondition > 95 | class StaticIf 96 | { 97 | public: 98 | 99 | template< typename tFuncIf > 100 | StaticIf(const tFuncIf &ifBody) 101 | { 102 | ifBody(); 103 | } 104 | 105 | template< bool tElseIfCondition, typename tFuncElseIf > 106 | StaticIfUnreached< tElseIfCondition > ElseIf(const tFuncElseIf &elseIfBody) 107 | { 108 | return StaticIfUnreached< tElseIfCondition >(elseIfBody); 109 | } 110 | 111 | template< typename tFuncElse > 112 | void Else(const tFuncElse &) 113 | { 114 | } 115 | }; 116 | 117 | template<> 118 | class StaticIf 119 | { 120 | public: 121 | 122 | template< typename tFuncIf > 123 | StaticIf(const tFuncIf &) 124 | { 125 | } 126 | 127 | template< bool tElseIfCondition, typename tFuncElseIf > 128 | StaticIf< tElseIfCondition > ElseIf(const tFuncElseIf &elseIfBody) 129 | { 130 | return StaticIf< tElseIfCondition >(elseIfBody); 131 | } 132 | 133 | template< typename tFuncElse > 134 | void Else(const tFuncElse &elseBody) 135 | { 136 | elseBody(); 137 | } 138 | }; 139 | 140 | class TicTimer 141 | { 142 | public: 143 | 144 | TicTimer() 145 | : mTicTime(std::chrono::high_resolution_clock::now()) 146 | { 147 | 148 | } 149 | 150 | void Tic() 151 | { 152 | mTicTime = std::chrono::high_resolution_clock::now(); 153 | } 154 | 155 | double Toc() 156 | { 157 | const std::chrono::time_point< std::chrono::high_resolution_clock > now = std::chrono::high_resolution_clock::now(); 158 | std::chrono::duration diff = now - mTicTime; 159 | return diff.count(); 160 | } 161 | 162 | double TocTic() 163 | { 164 | double diff = Toc(); 165 | Tic(); 166 | return diff; 167 | } 168 | 169 | private: 170 | 171 | std::chrono::time_point< std::chrono::high_resolution_clock > mTicTime; 172 | }; 173 | } 174 | 175 | #endif -------------------------------------------------------------------------------- /bsp/include/bsp/voidRecorder.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @cond ___LICENSE___ 3 | * 4 | * Copyright (c) 2016-2018 Zefiros Software. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * @endcond 25 | */ 26 | #pragma once 27 | #ifndef __BSPLIB_VOIDRECORDER_H__ 28 | #define __BSPLIB_VOIDRECORDER_H__ 29 | 30 | #include "bsp/processorData.h" 31 | 32 | class VoidRecorder 33 | { 34 | public: 35 | 36 | void ResetResize(uint32_t /*size*/) 37 | { 38 | } 39 | 40 | void PauseRecording(uint32_t /*pid*/) 41 | { 42 | } 43 | 44 | void ResumeRecording(uint32_t /*pid*/) 45 | { 46 | } 47 | 48 | void InitSyncTimer(uint32_t /*pid*/) 49 | { 50 | } 51 | 52 | void RecordPreSync(uint32_t /*pid*/) 53 | { 54 | } 55 | 56 | void RecordPostSync(uint32_t /*pid*/) 57 | { 58 | } 59 | 60 | void InitCommunication(uint32_t /*pid*/) 61 | { 62 | } 63 | 64 | void ManualInitCommunicaion(uint32_t /*pid*/) 65 | { 66 | } 67 | 68 | void FinishCommunication(uint32_t /*pid*/) 69 | { 70 | } 71 | 72 | void ManualFinishCommunicaion(uint32_t /*pid*/) 73 | { 74 | } 75 | 76 | void MarkSuperstep(uint32_t /*pid*/) 77 | { 78 | } 79 | 80 | void MarkSuperstep(uint32_t /*pid*/, uint32_t /*superstep*/) 81 | { 82 | } 83 | 84 | void RecordProcessorsData(uint32_t /*pid*/, const std::vector &/*processorsData*/) 85 | { 86 | } 87 | 88 | void PlotData() 89 | { 90 | } 91 | }; 92 | 93 | #endif -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | ignore: 3 | - "test/*" 4 | - "extern/*" -------------------------------------------------------------------------------- /docs/CNAME: -------------------------------------------------------------------------------- 1 | bsplib.eu -------------------------------------------------------------------------------- /docs/bsp.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zefiros-software/BSPLib/969d92434a3b1e2bb7c59cb06026451e8a64f771/docs/bsp.pdf -------------------------------------------------------------------------------- /docs/classic.md: -------------------------------------------------------------------------------- 1 | # The Classic BSP Interface 2 | Since BSP originally was a C library, the whole interface was designed 3 | to be used from C. We made the interface easier to work with from C++, 4 | but we also provide the classic interface implementation. 5 | 6 | ##Program Logic 7 | 8 | | Classic | Modern | 9 | | ------------------------------- | -------------------------------------------- | 10 | | [`bsp_init()`](logic/init.md) | [`BSPLib::Classic::Init()`](logic/init.md) | 11 | | [`bsp_begin()`](logic/begin.md) | [`BSPLib::Classic::Begin()`](logic/begin.md) | 12 | | [`bsp_end()`](logic/begin.md) | [`BSPLib::Classic::End()`](logic/end.md) | 13 | 14 | ##Utilities 15 | 16 | | Classic | Modern | 17 | | -------------------------------- | ------------------------------------- | 18 | | [`bsp_pid()`](util/procid.md) | [`BSPLib::ProcId()`](util/procid.md) | 19 | | [`bsp_nprocs()`](util/nprocs.md) | [`BSPLib::NProcs()`](util/nprocs.md) | 20 | | [`bsp_time()`](util/time.md) | [`BSPLib::Time()`](util/time.md) | 21 | 22 | ##Halting 23 | 24 | | Classic | Modern | 25 | | ---------------------------------- | ----------------------------------------------- | 26 | | [`bsp_abort()`](halting/abort.md) | [`BSPLib::Classic::Abort()`](halting/abort.md) | 27 | | [`bsp_vabort()`](halting/abort.md) | [`BSPLib::Classic::VAbort()`](halting/abort.md) | 28 | 29 | 30 | ##Synchronisation Point 31 | 32 | | Classic | Modern | 33 | | ---------------------------- | --------------------------------- | 34 | | [`bsp_sync()`](sync/sync.md) | [`BSPLib::Sync()`](sync/sync.md) | 35 | 36 | ##Registration & Deregistration 37 | 38 | | Classic | Modern | 39 | | ------------------------------------- | ------------------------------------- | 40 | | [`bsp_push_reg()`](regdereg/push.md) | [`BSPLib::Push()`](regdereg/push.md) | 41 | | [`bsp_pop_reg()`](regdereg/pop.md) | [`BSPLib::Pop()`](regdereg/pop.md) | 42 | 43 | 44 | ##Communication 45 | 46 | | Classic | Modern | 47 | | ------------------------- | --------------------------------- | 48 | | [`bsp_put()`](com/put.md) | [`BSPLib::Put()`](com/put.md) | 49 | | [`bsp_get()`](com/get.md) | [`BSPLib::Get()`](com/get.md) | 50 | 51 | 52 | ##Messaging 53 | 54 | | Classic | Modern | 55 | | ----------------------------------- | --------------------------------------- | 56 | | [`bsp_send()`](messaging/send.md) | [`BSPLib::Send()`](messaging/send.md) | 57 | | [`bsp_qsize()`](messaging/qsize.md) | [`BSPLib::QSize()`](messaging/qsize.md) | 58 | | [`bsp_move()`](messaging/move.md) | [`BSPLib::Move()`](messaging/move.md) | 59 | 60 | 61 | ##Messaging Utilities 62 | 63 | | Classic | Modern | 64 | | -------------------------------------------------- | ----------------------------------------------------- | 65 | | [`bsp_set_tagsize()`](messagingutil/settagsize.md) | [`BSPLib::SetTagSize()`](messagingutil/settagsize.md) | 66 | | [`bsp_get_tag()`](messagingutil/gettag.md) | [`BSPLib::GetTag()`](messagingutil/gettag.md) | -------------------------------------------------------------------------------- /docs/com/get.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | void BSPLib::Classic::Get( uint32_t pid, const void *src, ptrdiff_t offset, 5 | void *dst, size_t nbytes ) // (1) Classic 6 | void bsp_get( uint32_t pid, const void *src, ptrdiff_t offset, void *dst, 7 | size_t nbytes ) // (2) Legacy 8 | ``` 9 | This operation get the registered memory of another processor and copies the 10 | memory into its own memory. It gets a buffer of size `nbytes` from source 11 | pointer `src` that is located in the processor with identifier `pid` at 12 | offset `offset` bytes from source pointer `src` and stores it at the 13 | location of `dst`. 14 | 15 | 1. Classic BSP function, this is the interface one should prefer to 16 | use over the old BSP interface. 17 | 2. Legacy BSP function, this interface is included for backwards 18 | compatibility with other BSP libraries. 19 | 20 | !!! tip 21 | There are easier functions to work with. See for 22 | [Containers](getContainer.md), [Primitives](getPrimitive.md) 23 | and [Pointers](getPtrs.md). 24 | 25 | #Parameters 26 | 27 | * `pid` The processor identifier of the processor to communicate with. 28 | * `src` Pointer to the source of the information in the other processor. 29 | * `offset` Offset from the source `src` in bytes to start reading from. 30 | * `dst` Pointer to the destination for the information in the current processor. 31 | * `nbytes` Number of bytes to read. 32 | 33 | #Pre-Conditions 34 | * [`BSPLib::Begin()`](../logic/begin.md) has been called. 35 | * `src != nullptr`. 36 | * `dst != nullptr`. 37 | * [`BSPLib::Push()`](../regdereg/push.md) has been called on 38 | `src` with at least size `offset + nbytes` in the processor with ID `pid`. 39 | * A [`BSPLib::Sync()`](../sync/sync.md) has happened between 40 | [`BSPLig::Push()`](../regdereg/push.md) and this call. 41 | 42 | #Post-Conditions 43 | * Get request has been queued. 44 | * In the next superstep [`BSPLib::Sync()`](../sync/sync.md), the destination 45 | will have the copied value from the source. 46 | 47 | #Examples 48 | 49 | ###(1) Classic 50 | 51 | ###(2) Legacy -------------------------------------------------------------------------------- /docs/com/getPrimitive.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | template< typename tPrimitive > 5 | void BSPLib::Get( uint32_t pid, tPrimitive &src, tPrimitive &dst ) // (1) References 6 | 7 | template<> 8 | void BSPLib::Get( uint32_t pid, std::string &src, std::string &dst ) // (2) std::string 9 | 10 | template< typename tPrimitive > 11 | void BSPLib::Get( uint32_t pid, tPrimitive &var ) // (3) Reference 12 | ``` 13 | This operation get the registered primitive of another processor and copies the 14 | memory into its own memory. It gets the primitive stored in `src` that 15 | is located in the processor with ID `pid` and stores it at the location of `dst`. 16 | Internally, it calculates the size in bytes that is required for the primitive, 17 | and calls to [`BSPLib::Classic::Get()`](get.md). 18 | 19 | 1. Gets the value from `src` in the processor with ID `pid` and stores 20 | it in `dst`, using references. 21 | 2. Overload for `std::string`. 22 | 3. Get the value from `var` in the processor with ID `pid` and 23 | stores it in `var`, the same reference. 24 | 25 | !!! tip 26 | There are also other specialisations available. See 27 | [Containers](getContainer.md), [Primitives](getPrimitive.md) 28 | and [Pointers](getPtrs.md). 29 | 30 | !!! danger "Warnings" 31 | * In case of (2), the destination `std::string` must be at least as big 32 | as the source `std::string`. Make sure it is correctly resized, 33 | either by deciding on a fixed size, or communicating the size beforehand. 34 | 35 | #Parameters 36 | 37 | * `pid` The identifier of the processor to communicate with. 38 | * `src` Reference to the source of the information in the other processor. 39 | * `dst` Reference to the destination for the information in the current processor. 40 | * `var` Reference to both the source of the in the other processor, and the 41 | destination for the information in the current processor. 42 | 43 | #Pre-Conditions 44 | * [`BSPLib::Begin()`](../logic/begin.md) has been called. 45 | * [`BSPLib::Push()`](../regdereg/push.md) has been called on `src` in the processor with ID `pid`. 46 | * A [`BSPLib::Sync()`](../sync/sync.md) has happened between [`BSPLig::Push()`](../regdereg/push.md) and this call. 47 | * In case of (2), the `dst` string is at least as big as the `src` string. 48 | 49 | #Post-Conditions 50 | * Get request has been queued. 51 | * In the next superstep [`BSPLib::Sync()`](../sync/sync.md), the destination 52 | will have the copied value from the source. 53 | 54 | #Examples 55 | 56 | ### (1) References 57 | 58 | ### (2) std::string 59 | 60 | ### (3) Reference -------------------------------------------------------------------------------- /docs/com/getPtrs.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | template< typename tPrimitive > 5 | void BSPLib::GetPtrs( uint32_t pid, tPrimitive *srcBegin, size_t offset, 6 | tPrimitive *resultBegin, size_t count ) // (1) Begin-Offset-Count 7 | 8 | template< typename tPrimitive > 9 | void BSPLib::GetPtrs( uint32_t pid, tPrimitive *srcBegin, tPrimitive *srcCursor, 10 | tPrimitive *resultBegin, tPrimitive *resultEnd ) // (2) Begin-End-Cursor 11 | 12 | template< typename tPrimitive > 13 | void BSPLib::GetPtrs( uint32_t pid, tPrimitive *begin, 14 | tPrimitive *cursor, tPrimitive *end ) // (3) Same Begin-End-Cursor 15 | 16 | template< typename tPrimitive > 17 | void BSPLib::GetPtrs( uint32_t pid, tPrimitive *begin, 18 | tPrimitive *end ) // (4) Same Begin-End 19 | 20 | template< typename tPrimitive > 21 | void BSPLib::GetPtrs( uint32_t pid, tPrimitive *begin, 22 | size_t offset, size_t count ) // (5) Same Begin-Offset-Count 23 | 24 | template< typename tPrimitive > 25 | void BSPLib::GetPtrs( uint32_t pid, tPrimitive *begin, 26 | size_t count ) // (6) Same Begin-Count 27 | ``` 28 | This operation get the registered memory of another processor and copies the 29 | memory into its own memory. Gets a buffer of size `count` primitives from 30 | source pointer `srcBegin` that is located in the processor with identifier `pid` 31 | at offset `offset` primitives from source pointer `src` and stores it 32 | at the location of `dstBegin`. 33 | 34 | 1. Gets a buffer of size `count` primitives from source pointer `srcBegin` 35 | that is located in the processor with ID `pid` at offset `offset` 36 | primitives from source pointer `src` and stores it at the location of `dstBegin`. 37 | 2. Uses `resultBegin` and `resultEnd` pointers to calculate the number 38 | of primitives `count`, and uses `srcCursor` instead of `offset` 39 | to determine the offset it needs to start reading from. 40 | 3. The same as (1), but now, it uses `begin` as `srcBegin`, `cursor` as 41 | both `srcCursor` and `resultBegin`, and `end` as `resultEnd`. 42 | It stores the values in the same location as they were located in the 43 | other processor. 44 | 4. The same as (3), but now `begin` is used as both `begin` and `cursor`. 45 | It copies the entire range from `begin` to `end` from the 46 | processor with ID `pid` to the same location in the current processor. 47 | 5. The same as (3), with the behaviour: `cursor = begin + offset` and 48 | `end = begin + offset + count`. 49 | 6. The same as (5), with the behaviour: `offset = 0`. 50 | 51 | !!! tip 52 | There are also other specialisations available. See 53 | [Containers](getContainer.md), [Primitives](getPrimitive.md) 54 | and [Pointers](getPtrs.md). 55 | 56 | !!! danger "Warnings" 57 | * `std::string` is not assumed to be a primitive in this case, 58 | although it was in [`BSPLib::Get()`](getPrimitive.md). 59 | 60 | #Parameters 61 | 62 | * `pid` The ID of the processor to communicate with. 63 | * `srcBegin` Pointer to the begin of the information in the other processor. 64 | * `offset` Offset from the source `srcBegin` in number of primitives to 65 | start reading from. 66 | * `resultBegin` Pointer to the destination for the information in the 67 | current processor. 68 | * `count` Number of primitives to read. 69 | * `srcCursor` Other method to determine `offset`. The behaviour is the 70 | same as taking `offset = srcCursor - srcBegin`. 71 | * `resultEnd` Other method to determine `count`. The behaviour is the 72 | same as taking `count = resultEnd - resultBegin`. 73 | * `begin` Pointer to the begin of the information in both the processors. 74 | * `cursor` Cursor to start reading from in the other processor, and to 75 | start writing to in the current processor. 76 | * `end` End of the information block to get. 77 | 78 | #Pre-Conditions 79 | * [`BSPLib::Begin()`](../logic/begin.md) has been called. 80 | * None of the pointers `srcBegin`, `resultBegin`, `srcCursor`, `begin`, 81 | `cursor` and `end` is allowed to be `nullptr`. 82 | * [`BSPLib::Push()`](../regdereg/push.md) has been called on `srcBegin` or 83 | `begin` with at least size `offset + nbytes` in the processor with ID `pid`. 84 | * A [`BSPLib::Sync()`](../sync/sync.md) has happened between 85 | [`BSPLig::Push()`](../regdereg/push.md) and this call. 86 | 87 | #Post-Conditions 88 | * Get request has been queued. 89 | * In the next superstep [`BSPLib::Sync()`](../sync/sync.md), the destination 90 | will have the copied value from the source. 91 | 92 | #Examples 93 | 94 | ### (1) Begin-Offset-Count 95 | 96 | ### (2) Begin-End-Cursor 97 | 98 | ### (3) Same Begin-End-Cursor 99 | 100 | ### (4) Same Begin-End 101 | 102 | ### (5) Same Begin-Offset-Count 103 | 104 | ### (6) Same Begin-Count -------------------------------------------------------------------------------- /docs/com/put.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | void BSPLib::Classic::Put( uint32_t pid, const void *src, void *dst, ptrdiff_t offset, 5 | size_t nbytes ) // (1) Classic 6 | void bsp_get( uint32_t pid, const void *src, void *dst, ptrdiff_t offset, 7 | size_t nbytes ) // (2) Legacy 8 | ``` 9 | 10 | Puts a buffer of size `nbytes` from source pointer `src` in the thread 11 | with identifier `pid` at offset `offset` from destination pointer `dst`. 12 | 13 | 1. Classic BSP function, this is the interface one should prefer to 14 | use over the old BSP interface. 15 | 2. Legacy BSP function, this interface is included for backwards 16 | compatibility with other BSP libraries. 17 | 18 | !!! tip 19 | There are easier functions to work with. See for 20 | [Containers](putContainer.md), [Primitives](putPrimitive.md) 21 | and [Pointers](putPtrs.md). 22 | 23 | #Parameters 24 | 25 | * `pid` The ID of the processor to communicate with. 26 | * `src` Pointer to the source of the information in the current processor. 27 | * `offset` Offset from the destination `dst` in bytes to start writing from. 28 | * `dst` Pointer to the destination for the information in the other processor. 29 | * `nbytes` Number of bytes to write. 30 | 31 | #Pre-Conditions 32 | * [`BSPLib::Begin()`](../logic/begin.md) has been called. 33 | * `src != nullptr`. 34 | * `dst != nullptr`. 35 | * [`BSPLib::Push()`](../regdereg/push.md) has been called on `dst` 36 | with at leas size `offset + nbytes` in the processor with identifier `pid`. 37 | * A [`BSPLib::Sync()`](../sync/sync.md) has happened between 38 | [`BSPLig::Push()`](../regdereg/push.md) and this call. 39 | 40 | #Post-Conditions 41 | * Put request has been queued. 42 | * In the next superstep [`BSPLib::Sync()`](../sync/sync.md), the destination 43 | will have the copied value from the source. 44 | 45 | #Examples 46 | 47 | ###(1) Classic 48 | 49 | ###(2) Legacy -------------------------------------------------------------------------------- /docs/com/putPrimitive.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | template< typename tPrimitive > 5 | void BSPLib::Put( uint32_t pid, tPrimitive &src, tPrimitive &dst ) // (1) References 6 | 7 | template<> 8 | void BSPLib::Put( uint32_t pid, std::string &src, std::string &dst ) // (2) std::string 9 | 10 | template< typename tPrimitive > 11 | void BSPLib::Put( uint32_t pid, tPrimitive &var ) // (3) Reference 12 | ``` 13 | 14 | Puts the primitive stored in `src` that is located in the current processor 15 | and stores it at the location of `dst` that is located in the processor with 16 | identifier `pid`. Internally, it calculates the size in bytes that is required 17 | for the primitive, and calls to [`BSPLib::Classic::Put()`](put.md). 18 | 19 | 1. Puts the value from `src` and stores it in `dst` in the processor 20 | with identifier `pid`, using references. 21 | 2. Overload for `std::string`. 22 | 3. Put the value from `var` and stores it in `var`in the processor with 23 | identifier `pid`, the same reference. 24 | 25 | !!! tip 26 | There are also other specialisations available. See 27 | [Containers](putContainer.md), [Primitives](putPrimitive.md) 28 | and [Pointers](putPtrs.md). 29 | 30 | !!! danger "Warnings" 31 | * In case of (2), the destination `std::string` must be at least 32 | as big as the source `std::string`. Make sure it is correctly resized, 33 | either by deciding on a fixed size, or communicating the size beforehand. 34 | 35 | #Parameters 36 | 37 | * `pid` The identifier of the processor to communicate with. 38 | * `src` Reference to the source of the information in the current processor. 39 | * `dst` Reference to the destination for the information in the other processor. 40 | * `var` Reference to both the source of the in the current processor, and the 41 | destination for the information in the other processor. 42 | 43 | #Pre-Conditions 44 | * [`BSPLib::Begin()`](../logic/begin.md) has been called. 45 | * [`BSPLib::Push()`](../regdereg/push.md) has been called on `dst` in the 46 | processor with identifier `pid`. 47 | * A [`BSPLib::Sync()`](../sync/sync.md) has happened between 48 | [`BSPLig::Push()`](../regdereg/push.md) and this call. 49 | * In case of (2), the `dst` string is at least as big as the `src` string. 50 | 51 | #Post-Conditions 52 | * Put request has been queued. 53 | * In the next superstep [`BSPLib::Sync()`](../sync/sync.md), 54 | the destination will have the copied value from the source. 55 | 56 | #Examples 57 | 58 | ### (1) References 59 | 60 | ### (2) std::string 61 | 62 | ### (3) Reference -------------------------------------------------------------------------------- /docs/com/putPtrs.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | template< typename tPrimitive > 5 | void BSPLib::PutPtrs( uint32_t pid, tPrimitive *srcBegin, size_t count, 6 | tPrimitive *resultBegin, size_t offset ) // (1) Begin-Offset-Count 7 | 8 | template< typename tPrimitive > 9 | void BSPLib::PutPtrs( uint32_t pid, tPrimitive *srcBegin, tPrimitive *srcEnd, 10 | tPrimitive *resultBegin, tPrimitive *resultDst ) // (2) Begin-End-Cursor 11 | 12 | template< typename tPrimitive > 13 | void BSPLib::PutPtrs( uint32_t pid, tPrimitive *begin, 14 | tPrimitive *cursor, tPrimitive *end ) // (3) Same Begin-End-Cursor 15 | 16 | template< typename tPrimitive > 17 | void BSPLib::PutPtrs( uint32_t pid, tPrimitive *begin, 18 | tPrimitive *end ) // (4) Same Begin-End 19 | 20 | template< typename tPrimitive > 21 | void BSPLib::PutPtrs( uint32_t pid, tPrimitive *begin, 22 | size_t offset, size_t count ) // (5) Same Begin-Offset-Count 23 | 24 | template< typename tPrimitive > 25 | void BSPLib::PutPtrs( uint32_t pid, tPrimitive *begin, 26 | size_t count ) // (6) Same Begin-Count 27 | ``` 28 | 29 | Puts a buffer of size `count` primitives from source pointer `srcBegin` that is 30 | located in the current processor, and stores it at offset `offset` from the 31 | location of `dstBegin` in the processor with ID `pid`. 32 | 33 | 1. Puts a buffer of size `count` primitives from source pointer `srcBegin` that 34 | is located in the current processor, 35 | and stores it at offset `offset` from the location of `dstBegin` in the 36 | processor with ID `pid`. 37 | 2. Uses `srcBegin` and `srcEnd` pointers to calculate the number of primitives 38 | `count`, and uses `resultDst` instead of `offset` 39 | to determine the offset it needs to start reading from. 40 | 3. The same as (1), but now, it uses `begin` as `resultBegin`, `cursor` 41 | as both `srcBegin` and `resultDst`, and `end` as `srcEnd`. 42 | It stores the values in the same location as they were located in the 43 | other processor. 44 | 4. The same as (3), but now `begin` is used as both `begin` and `cursor`. 45 | It copies the entire range from `begin` to `end` from the 46 | processor with ID `pid` to the same location in the current processor. 47 | 5. The same as (3), with the behaviour: `cursor = begin + offset` and 48 | `end = begin + offset + count`. 49 | 6. The same as (5), with the behaviour: `offset = 0`. 50 | 51 | !!! tip 52 | There are also other specialisations available. See 53 | [Containers](putContainer.md), [Primitives](putPrimitive.md) 54 | and [Pointers](putPtrs.md). 55 | 56 | !!! danger "Warnings" 57 | * `std::string` is not assumed to be a primitive in this case, although it was in [`BSPLib::Put()`](putPrimitive.md). 58 | 59 | #Parameters 60 | 61 | * `pid` The ID of the processor to communicate with. 62 | * `srcBegin` Pointer to the begin of the information in the other processor. 63 | * `offset` Offset from the source `srcBegin` in number of primitives to start 64 | reading from. 65 | * `resultBegin` Pointer to the destination for the information in the current processor. 66 | * `count` Number of primitives to read. 67 | * `resultDst` Other method to determine `offset`. The behaviour is the same 68 | as taking `offset = resultDst - resultBegin`. 69 | * `srcEnd` Other method to determine `count`. The behaviour is the same 70 | as taking `count = srcEnd - srcBegin`. 71 | * `begin` Pointer to the begin of the information in both the processors. 72 | * `cursor` Cursor to start reading from in the current processor, and 73 | to start writing to in the other processor. 74 | * `end` End of the information block to put. 75 | 76 | #Pre-Conditions 77 | * [`BSPLib::Begin()`](../logic/begin.md) has been called. 78 | * None of the pointers `srcBegin`, `resultBegin`, `resultDst`, `srcEnd`, 79 | `begin`, `cursor` and `end` is allowed to be `nullptr`. 80 | * [`BSPLib::Push()`](../regdereg/push.md) has been called on `resultBegin` 81 | or `begin` with at least size `offset + nbytes` in the processor with ID `pid`. 82 | * A [`BSPLib::Sync()`](../sync/sync.md) has happened between 83 | [`BSPLig::Push()`](../regdereg/push.md) and this call. 84 | 85 | #Post-Conditions 86 | * Put request has been queued. 87 | * In the next superstep [`BSPLib::Sync()`](../sync/sync.md), the 88 | destination in the current processor will have the copied value 89 | from the source in the other processor. 90 | 91 | #Examples 92 | 93 | ### (1) Begin-Offset-Count 94 | 95 | ### (2) Begin-End-Cursor 96 | 97 | ### (3) Same Begin-End-Cursor 98 | 99 | ### (4) Same Begin-End 100 | 101 | ### (5) Same Begin-Offset-Count 102 | 103 | ### (6) Same Begin-Count -------------------------------------------------------------------------------- /docs/halting/abort.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | void BSPLib::Classic::Abort( const char *errorMessage, ... ) // (1) Classic 5 | void bsp_abort( const char *errorMessage, ... ) // (2) BSP 6 | void BSPLib::VAbort( const char *errorMessage, va_list args ) // (3) Modern va_list 7 | void bsp_vabort( const char *errorMessage, va_list args ) // (4) BSP va_list 8 | ``` 9 | 10 | Aborts the BSP program with the given error message. The formatting used is the same as in 11 | fprintf. If more than one processors calls [`BSPLib::Abort()`](abort.md), then 12 | all processors may print the abort message, and not just one. 13 | 14 | The thread that aborts prints the message to `stderr`. 15 | Instead of terminating the whole program, it just terminates 16 | the computation, and thus you are able to continue or restart 17 | the program. When you use [`BSPLib::Execute()`](../logic/execute.md) 18 | you can query whether the program was aborted or not. When [`BSPLib::Execute()`](../logic/execute.md) 19 | is not used, the main thread may throw an exception. 20 | 21 | If [`BSPLib::Init()`](../logic/init.md) is called after an abort, it will determine whether all threads have actually 22 | aborted. If not, it will notify the waiting threads about the abort. If even this fails, the entire program will terminate. 23 | 24 | 25 | 1. Classic BSP function, this is the interface one should prefer to use over the old BSP interface. 26 | 2. Legacy BSP function, this interface is included for backwards compatibility with other BSP libraries. 27 | 3. Classic BSP function that takes a `va_list` directly. 28 | 4. Legacy BSP function that takes a `va_list` directly. 29 | 30 | !!! note "Warnings" 31 | The termination behaviour is different in BSPLib differs from that in other BSP libraries. 32 | 33 | !!! danger "Deprication" 34 | This function has been depricated and should be avoided. 35 | 36 | #Parameters 37 | 38 | * `format` Describes the message to format. 39 | * `...` Variable arguments providing message formatting. 40 | * `args` The formatting arguments. 41 | 42 | #Post-Conditions 43 | * All threads other than main thread will exit on a BSP call, unless the BSP process is restarted. 44 | * If main thread, a BSPAbort exception will be thrown. 45 | 46 | #Examples 47 | 48 | ###(1) Classic 49 | 50 | ```cpp 51 | void main( int32_t, const char ** ) 52 | { 53 | bool success = BSPLib::Execute( [] 54 | { 55 | if ( BSPLib::Classic::ProcId() == 0 ) 56 | { 57 | // Prints "Quit non gracefully" 58 | BSPLib::Classic::Abort( "Quit non gracefully" ); 59 | 60 | // Will never be reached 61 | while( true ); 62 | } 63 | 64 | BSPLib::Classic::Sync(); 65 | 66 | }, BSPLib::Classic::NProcs() ); 67 | 68 | assert( !success ); 69 | } 70 | ``` 71 | 72 | ###(2) BSP 73 | 74 | ```cpp 75 | void main( int32_t, const char ** ) 76 | { 77 | bool success = BSPLib::Execute( [] 78 | { 79 | if ( bsp_pid() == 0 ) 80 | { 81 | // Prints "Quit non gracefully" 82 | bsp_abort( "Quit non gracefully" ); 83 | 84 | // Will never be reached 85 | while( true ); 86 | } 87 | 88 | bsp_sync(); 89 | 90 | }, bsp_nprocs() ); 91 | 92 | assert( !success ); 93 | } 94 | ``` 95 | -------------------------------------------------------------------------------- /docs/hp/hpget.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zefiros-software/BSPLib/969d92434a3b1e2bb7c59cb06026451e8a64f771/docs/hp/hpget.md -------------------------------------------------------------------------------- /docs/hp/hpmove.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zefiros-software/BSPLib/969d92434a3b1e2bb7c59cb06026451e8a64f771/docs/hp/hpmove.md -------------------------------------------------------------------------------- /docs/hp/hpput.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zefiros-software/BSPLib/969d92434a3b1e2bb7c59cb06026451e8a64f771/docs/hp/hpput.md -------------------------------------------------------------------------------- /docs/hp/hpsend.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zefiros-software/BSPLib/969d92434a3b1e2bb7c59cb06026451e8a64f771/docs/hp/hpsend.md -------------------------------------------------------------------------------- /docs/logic/begin.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | void BSPLib::Classic::Begin( uint32_t p ) // (1) Classic 5 | void bsp_begin( uint32_t p ) // (2) BSP 6 | ``` 7 | 8 | Begins the computations with the maximum given processors. The BSP model is implemented around the 9 | Single Program Multiple Data (SPMD) programming model. This means that we divide our datastructures 10 | over all threads, and try to evenly divide the work per processor. BSPLib will handle the required 11 | communication, as implemented by the user. This means that the distribution of work 12 | is the users responsibility, whilst the communication is that of the library. 13 | 14 | Usually we create a BSP program by pairing (optionally) [`BSPLib::Classic::Init()`](init.md), [`BSPLib::Classic::Begin()`](begin.md) 15 | and [`BSPLib::Classic::End()`](end.md) calls. When no [`BSPLib::Classic::Init()`](init.md) call is made, the library resumes in 16 | SPMD mode, and calls the `main()` function in all threads. Otherwise the given entry point from the 17 | [`BSPLib::Classic::Init()`](init.md) call will be used. 18 | 19 | 1. Classic BSP function, this is the interface one should prefer to use over the old BSP interface. 20 | 2. Legacy BSP function, this interface is included for backwards compatibility with other BSP libraries. 21 | 22 | !!! danger "Deprication" 23 | This function has been depricated in favour of [`BSPLib::Execute()`](execute.md). 24 | 25 | #Parameters 26 | 27 | * `p` The maximum processors to use in computation. Assigning more processors than 28 | physically available could slow down your program. 29 | 30 | #Pre-Conditions 31 | 32 | * If Init has been called: 33 | * Will execute entry in parallel. 34 | 35 | Else: 36 | 37 | * Will execute main in parallel. Also, a warning will be printed to `stderr`. 38 | 39 | * If called from the main thread: 40 | 41 | * Resets and initialises the communication queues and buffers. 42 | * Calls the entry point for all other threads. 43 | * Starts the timer for the main thread. 44 | Else: 45 | Starts the timer for the current thread. 46 | 47 | #Exceptions 48 | 49 | * `BspInternal::BspAbort`: 50 | Thrown when an abort error condition occurs, if enabled with symbol `BSP_THROW`. 51 | 52 | #Examples 53 | 54 | ###(1) Classic 55 | 56 | **SPMD Exectution** 57 | 58 | In SPMD mode, BSPLib regocnises no [`BSPLib::Classic::Init`](init.md) has been called, 59 | and thus automatically recalls the `main()` function for the other threads. 60 | 61 | ```cpp 62 | void main( int32_t, const char ** ) 63 | { 64 | // No Init call, so other threads will call 65 | // the main fuction 66 | BSPLib::Classic::Begin( BSPLib::NProcs() ); 67 | 68 | std::cout << "Hello BSP Worldwide from process " << BSPLib::Classic::ProcId() 69 | << " of " << BSPLib::NProcs() << std::endl; 70 | 71 | BSPLib::Classic::End(); 72 | } 73 | ``` 74 | 75 | Of course namespaces may be ommited, so the interface gets even simpler. 76 | 77 | ```cpp 78 | void main( int32_t, const char ** ) 79 | { 80 | using namespace BSPLib; 81 | 82 | // No Init call, so other threads will call 83 | // the main fuction 84 | Classic::Begin( NProcs() ); 85 | 86 | std::cout << "Hello BSP Worldwide from process " << ProcId() 87 | << " of " << NProcs() << std::endl; 88 | 89 | Classic::End(); 90 | } 91 | ``` 92 | 93 | **Normal Exectution** 94 | 95 | In the normal execution mode we need to initialise the BSPLibrary with a [`BSPLib::Classic::Init`](init.md) call. 96 | This ensures we assign the correct entry point to the threads, which will be called on the 97 | [`BSPLib::Classic::Begin()`](begin.md) call. 98 | 99 | ```cpp 100 | void Spmd() 101 | { 102 | BSPLib::Classic::Begin( BSPLib::NProcs() ); 103 | 104 | std::cout << "Hello BSP Worldwide from process " << BSPLib::Classic::ProcId() 105 | << " of " << BSPLib::NProcs() << std::endl; 106 | 107 | BSPLib::Classic::End(); 108 | } 109 | 110 | 111 | void main( int32_t argc, const char **argv ) 112 | { 113 | // Set the entry point for the other threads 114 | BSPLib::Classic::Init( Spmd, argc, argv ); 115 | 116 | // Main thread needs to call it also 117 | Spmd(); 118 | } 119 | ``` 120 | 121 | ###(2) BSP 122 | 123 | ```cpp 124 | void main( int32_t, const char ** ) 125 | { 126 | // No Init call, so other threads will call 127 | // the main fuction 128 | bsp_begin( bsp_nprocs() ); 129 | 130 | std::cout << "Hello BSP Worldwide from process " << bsp_pid() 131 | << " of " << bsp_nprocs() << std::endl; 132 | 133 | bsp_end(); 134 | } 135 | ``` -------------------------------------------------------------------------------- /docs/logic/end.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | void BSPLib::Classic::End() // (1) Classic 5 | void bsp_end() // (2) BSP 6 | ``` 7 | 8 | Ends the BSP computation. All threads must call this function to gracefully exit the BSP program. A BSP program is paired by [`BSPLib::Classic::Begin()`](begin.md) 9 | and [`BSPLib::Classic::End()`](end.md) calls. Wherein the [`BSPLib::Classic::End()`](end.md) should be the last call in the computation. Calling this function 10 | will ensure that the library is reset for reuse, and thuse we can restart calculations or start another SPMD program. 11 | 12 | 1. Classic BSP function, this is the interface one should prefer to use over the old BSP interface. 13 | 2. Legacy BSP function, this interface is included for backwards compatibility with other BSP libraries. 14 | 15 | !!! danger "Deprication" 16 | This function has been depricated in favour of [`BSPLib::Execute()`](execute.md). 17 | 18 | #Pre-Conditions 19 | 20 | * Begin has been called 21 | 22 | #Post-Conditions 23 | 24 | * Ended is true 25 | * All threads have synced and ended. 26 | * The main thread releases all threads. 27 | 28 | #Examples 29 | 30 | ###(1) Classic 31 | 32 | ```cpp 33 | void main( int32_t, const char ** ) 34 | { 35 | BSPLib::Classic::Begin( BSPLib::NProcs() ); 36 | 37 | std::cout << "Hello BSP Worldwide from process " << BSPLib::Classic::ProcId() 38 | << " of " << BSPLib::NProcs() << std::endl; 39 | 40 | // Stop all the threads, reset the library 41 | // and resume execution on the main thread. 42 | BSPLib::Classic::End(); 43 | } 44 | ``` 45 | 46 | ###(2) BSP 47 | 48 | ```cpp 49 | void main( int32_t, const char ** ) 50 | { 51 | BSPLib::Classic::Begin( BSPLib::NProcs() ); 52 | 53 | std::cout << "Hello BSP Worldwide from process " << BSPLib::Classic::ProcId() 54 | << " of " << BSPLib::NProcs() << std::endl; 55 | 56 | // Stop all the threads, reset the library 57 | // and resume execution on the main thread. 58 | BSPLib::Classic::End(); 59 | } 60 | ``` -------------------------------------------------------------------------------- /docs/logic/execute.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | bool Execute( std::function< void() > func, uint32_t nProc ) // (1) Simple 5 | bool Execute( std::function< void() > func, uint32_t nProc, 6 | int32_t argc, char **argv ) // (2) Arguments 7 | ``` 8 | This function executes the given function according to the BSP model, with the 9 | given amount of processors. There is no need to seperate main thread and instanced threads from the library, 10 | and also [`BSPLib::Classic::Begin()`](begin.md) and [`BSPLib::Classic::End()`](end.md) are not needed in 11 | this function body. Everything is taken care off, and if the computations are abored prematurely, 12 | the return value will be false instead of true. 13 | 14 | This function is sematically equal to: 15 | ```cpp 16 | std::function< void() > spmd = [func, nProc] 17 | { 18 | BSPLib::Classic::Begin( nProc ); 19 | 20 | func(); 21 | 22 | BSPLib::Classic::End(); 23 | }; 24 | 25 | BSPLib::Classic::Init( spmd, argc, argv ); 26 | 27 | try 28 | { 29 | spmd(); 30 | } 31 | catch ( BspInternal::BspAbort & ) 32 | { 33 | return false; 34 | } 35 | 36 | return true; 37 | ``` 38 | 39 | A BSP program normally is paired by [`BSPLib::Classic::Begin()`](begin.md) 40 | and [`BSPLib::Classic::End()`](end.md) calls. When using the normal execution mode 41 | [`BSPLib::Classic::Init()`](init.md) needs to be called beforehand, otherwise 42 | the computations will start in SPMD mode, and the behaviour will be undefined. 43 | To solve this we introduce the [`BSPLib::Execute()`](execute.md) function makes the 44 | BSP interface easier to use. 45 | 46 | 1. This is the most basic way of calling this function. 47 | 2. When we need to pass the `main()` arguments to the BSP program. 48 | 49 | #Parameters 50 | 51 | * `func` The entry function to execute over all processors. 52 | * `nProcs` The amount of processors to use in the executions. 53 | * `argc` *Currently not used, should be `argc` from `main` function.* 54 | * `argv` *Currently not used, should be `argv` from `main` function.* 55 | 56 | #Return Value 57 | True when the BSP program executed successfully, othwerise false. 58 | 59 | #Post-Conditions 60 | 61 | * The BSP program has been executed. 62 | 63 | #Examples 64 | 65 | ###(1) Simple 66 | 67 | **Normal** 68 | 69 | This is the normal usage of the function. 70 | 71 | ```cpp 72 | void main( int32_t, const char ** ) 73 | { 74 | BSPLib::Execute( [] 75 | { 76 | std::cout << "Hello BSP Worldwide from process " << BSPLib::Classic::ProcId() 77 | << " of " << BSPLib::NProcs() << std::endl; 78 | }, BSPLib::NProcs() ); 79 | } 80 | ``` 81 | 82 | **Non Gracefull Exit** 83 | 84 | If the computation could call abort, one can check for it on the return type. 85 | 86 | ```cpp 87 | void main( int32_t, const char ** ) 88 | { 89 | bool success = BSPLib::Execute( [] 90 | { 91 | std::cout << "Hello BSP Worldwide from process " << BSPLib::Classic::ProcId() 92 | << " of " << BSPLib::NProcs() << std::endl; 93 | 94 | if ( BSPLib::ProcId() == 0 ) 95 | { 96 | BSPLib::Abort( "Quit non gracefully" ); 97 | } 98 | }, BSPLib::NProcs() ); 99 | 100 | assert( !success ); 101 | } 102 | ``` 103 | 104 | ###(2) Arguments 105 | 106 | ```cpp 107 | void main( int32_t argc, const char **argv ) 108 | { 109 | BSPLib::Execute( [] 110 | { 111 | std::cout << "Hello BSP Worldwide from process " << BSPLib::Classic::ProcId() 112 | << " of " << BSPLib::NProcs() << std::endl; 113 | }, BSPLib::NProcs(), argc, argv ); 114 | } 115 | ``` -------------------------------------------------------------------------------- /docs/logic/init.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | void BSPLib::Classic::Init( std::function< void() > spmd, 5 | int32_t argc, char **argv) // (1) Classic 6 | void bsp_init( void(*spmd)(void), int32_t argc, char **argv) // (2) BSP 7 | ``` 8 | 9 | Initialises the BSP computation process. Please note that the main thread should also call the entry function. 10 | 11 | 1. Classic BSP function, this is the interface one should prefer to use over the old BSP interface. 12 | 2. Legacy BSP function, this interface is included for backwards compatibility with other BSP libraries. 13 | 14 | !!! note "Warnings" 15 | * By default, [`BSPLib::Classic::Init()`](init.md) will print a warning to `stderr` in case an abort of the previous BSP program has been detected. This message can be suppressed by the symbol `BSP_SUPPRESS_ABORT_WARNING`. 16 | * When [`BSPLib::Classic::Init()`](init.md) failed to join all threads from the previous BSP program, an error will be printed to `stderr`, and the entire program will be terminated by `std::terminate()`. This behaviour cannot be disabled, as it will most certainly cause errors in the next BSP program. 17 | 18 | !!! danger "Deprication" 19 | This function has been depricated in favour of [`BSPLib::Execute()`](execute.md). 20 | 21 | #Parameters 22 | 23 | * `spmd` The entry function to execute. 24 | * `argc` *Currently not used, should be `argc` from `main` function.* 25 | * `argv` *Currently not used, should be `argv` from `main` function.* 26 | 27 | #Pre-Conditions 28 | * If the previous BSP program was terminated using Abort or VAbort: 29 | * BSPLib will try to end the previous BSP program by notifying all threads that are stuck in a synchronisation about the previous Abort. 30 | * After 100 failed tries, the entire program will be terminated by `std::terminate()`. 31 | 32 | #Post-Conditions 33 | 34 | * Tag size is 0. 35 | * Entry point is now `entry`, thus when we call [`BSPLib::Classic::Begin()`](begin.md) all threads except for the 36 | main thread will execute this function. 37 | * For the main thread, `BSPLib::ProcId() == 0`, other threads get their identifier assigned 38 | in the [`BSPLib::Classic::Begin()`](begin.md) function. 39 | 40 | #Examples 41 | 42 | ###(1) Classic 43 | 44 | **SPMD Exectution** 45 | 46 | In SPMD mode, BSPLib regocnises no [`BSPLib::Classic::Init`](init.md) has been called, 47 | and thus automatically recalls the `main()` function for the other threads. 48 | 49 | ```cpp 50 | void main(int32_t, const char **) 51 | { 52 | BSPLib::Classic::Begin( BSPLib::NProcs() ); 53 | 54 | std::cout << "Hello BSP Worldwide from process " << BSPLib::Classic::ProcId() 55 | << " of " << BSPLib::NProcs() << std::endl; 56 | 57 | BSPLib::Classic::End(); 58 | } 59 | ``` 60 | 61 | **Normal Exectution** 62 | 63 | In the normal execution mode we need to initialise the BSPLibrary with a [`BSPLib::Classic::Init`](init.md) call. 64 | This ensures we assign the correct entry point to the threads, which will be called on the 65 | [`BSPLib::Classic::Begin()`](begin.md) call. 66 | 67 | ```cpp 68 | void Spmd() 69 | { 70 | BSPLib::Classic::Begin( BSPLib::NProcs() ); 71 | 72 | std::cout << "Hello BSP Worldwide from process " << BSPLib::Classic::ProcId() 73 | << " of " << BSPLib::NProcs() << std::endl; 74 | 75 | BSPLib::Classic::End(); 76 | } 77 | 78 | 79 | void main(int32_t argc, const char **argv) 80 | { 81 | BSPLib::Classic::Init( Spmd, argc, argv ); 82 | // Main thread needs to call it also 83 | Spmd(); 84 | } 85 | ``` 86 | 87 | **Lambda Exectution** 88 | 89 | A more advanced manner of execution is using lambda, giving our 90 | more freedom over small BSP programs. Since we now use `std::function< void() >` 91 | as entry point, we are no longer bound by function pointers. [`BSPLib::Execute()`](execute.md) 92 | is a nice abstraction over this programming method, and should be used in favour of calling the 93 | program logic functions yourself. 94 | 95 | ```cpp 96 | void main( int32_t argc, const char **argv ) 97 | { 98 | auto entry = [] 99 | { 100 | BSPLib::Classic::Begin( BSPLib::NProcs() ); 101 | 102 | std::cout << "Hello BSP Worldwide from process " << BSPLib::Classic::ProcId() 103 | << " of " << BSPLib::NProcs() << std::endl; 104 | 105 | BSPLib::Classic::End(); 106 | }; 107 | 108 | // Set the entry point for the other threads 109 | BSPLib::Classic::Init( entry, argc, argv ); 110 | 111 | // Main thread needs to call it also 112 | entry(); 113 | } 114 | ``` 115 | 116 | ###(2) BSP 117 | 118 | ```cpp 119 | void Spmd() 120 | { 121 | bsp_begin( bsp_nprocs() ); 122 | 123 | std::cout << "Hello BSP Worldwide from process " << bsp_pid() 124 | << " of " << bsp_nprocs() << std::endl; 125 | 126 | bsp_end(); 127 | } 128 | 129 | 130 | void main(int32_t argc, const char **argv) 131 | { 132 | bsp_init( Spmd, argc, argv ); 133 | // Main thread needs to call it also 134 | Spmd(); 135 | } 136 | ``` -------------------------------------------------------------------------------- /docs/messaging/move.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | void BSPLib::Classic::Move( void *payload, size_t max_copy_size_in ) // (1) Classic 5 | void bsp_move( void *payload, size_t max_copy_size_in ) // (2) Legacy 6 | 7 | template< typename tPrimitive > 8 | void BSPLib::Move( tPrimitive &payloadRef ) // (3) Reference 9 | 10 | template<> 11 | void BSPLib::Move( std::string &payloadRef ) // (4) std::string 12 | 13 | template< typename tPrimitive > 14 | void BSPLib::MovePtrs( tPrimitive *begin, uint32_t maxCopySize ) // (5) Pointers: Begin-Count 15 | 16 | template< typename tPrimitive > 17 | void BSPLib::MovePtrs( tPrimitive *begin, tPrimitive *end ) // (6) Pointers: Begin-End 18 | 19 | template< typename tIterator > 20 | void BSPLib::MoveIterator( tIterator beginIt, uint32_t maxCopySize ) // (7) Iterators: Begin-Count 21 | 22 | template< typename tIterator > 23 | void BSPLib::MoveIterator( tIterator beginIt, tIterator endIt ) // (8) Iterators: Begin-End 24 | 25 | template< typename tPrimitive, size_t tSize > 26 | void BSPLib::MoveCArray( tPrimitive( &payloadCArray )[tSize] ) // (9) C-Array 27 | 28 | template< typename tContainer > 29 | void BSPLib::MoveContainer( tContainer &payloadContainer ) // (10) Container 30 | ``` 31 | 32 | Moves the first message in the queue to the given payload destination. 33 | 34 | 1. Classic BSP function, this is the interface one should prefer to use over the old BSP interface. 35 | 2. Legacy BSP function, this interface is included for backwards compatibility with other BSP libraries. 36 | 3. Moves the first message in the queue to the given primitive. 37 | 4. Overload of (3) for `std::string`. 38 | 5. Moves the first message in the queue to `begin`, with up to `maxCopySize` primitives. 39 | 6. Has the same behaviour as (5), using that `maxCopySize = begin - end`. 40 | 7. Moves the first message in the queue to `beginIt`, with up to `maxCopySize` primitives. 41 | 8. Has the same behaviour as (5), using that `maxCopySize = beginIt - endIt`. 42 | 9. Moves the first message in the queue to the C-Array. 43 | 10. Moves the first message in the queue to the container. 44 | 45 | #Parameters 46 | 47 | * `payload` Void pointer to the begin of the payload destination. 48 | * `max_copy_size_in` Maximum size in bytes for the payload destination. No more than this will be copied (may copy less). 49 | * `payloadRef` Reference to store the payload to. 50 | * `begin` Typesafe pointer to the begin of the payload destination. 51 | * `maxCopySize` Maximum number of primitives for the payload destination. Similar to `max_copy_size_in`, but not in bytes. 52 | * `end` Typesafe pointer to the end of the payload destination. 53 | * `beginIt` Iterator describing the begin of the payload destination. 54 | * `endIt` Iterator describing the end of the payload destination. 55 | * `payloadCArray` C-Array that is the destination for the payload. 56 | * `payloadContainer` Container that is the destination for the payload. 57 | 58 | #Pre-Conditions 59 | * Begin has been called. 60 | * If the send queue is empty or the cursor is at/behind the end: 61 | * Does nothing. 62 | 63 | Else: 64 | 65 | * Moves the first message in the queue o the given payload destination. 66 | * payload != nullptr. 67 | 68 | #Post-Conditions 69 | The queue cursor for the send queue is moved to the next message. 70 | 71 | #Examples 72 | 73 | ###(1) Classic 74 | ###(2) Legacy 75 | ###(3) Reference 76 | ###(4) std::string 77 | ###(5) Pointers: Begin-Count 78 | ###(6) Pointers: Begin-End 79 | ###(7) Iterators: Begin-Count 80 | ###(8) Iterators: Begin-End 81 | ###(9) C-Array 82 | ###(10) Container -------------------------------------------------------------------------------- /docs/messaging/qsize.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | void BSPLib::Classic::QSize( size_t *packets, size_t *accumulatedSize ) // (1) Classic 5 | void bsp_qsize( size_t *packets, size_t *accumulatedSize ) // (2) Legacy 6 | 7 | void BSPLib::QSize( size_t &packetsRef ) // (3) Reference 8 | void BSPLib::QSize( size_t &packetsRef, size_t &accumulatedSizeRef ) // (4) References 9 | ``` 10 | 11 | Get both the amount of messages, and the total size of the messages in bytes. 12 | 13 | 1. Classic BSP function, this is the interface one should prefer to use over the old BSP interface. 14 | 2. Legacy BSP function, this interface is included for backwards compatibility with other BSP libraries. 15 | 3. Gets the amount of messages in the queue using a reference, as we do not allow `packets` to be `nullptr`. 16 | 4. Gets both the amount of messages in the queue and the total size of the messages in bytes, using references. 17 | 18 | #Parameters 19 | 20 | * `packets` Pointer to the location where the total number of packets is to be written. 21 | * `accumulatedSize` Pointer to the location where the total size of the messages is to be written. 22 | * `packetsRef` Reference to write the number of packets to. 23 | * `accumulatedSizeRef` Reference to write the total size of the messages to. 24 | 25 | #Pre-Conditions 26 | * [`BSPLib::Begin()`](../logic/begin.md) has been called. 27 | * packets != nullptr. 28 | 29 | #Post-Conditions 30 | * If `accumulatedSize != nullptr`: 31 | * accumulatedSize will be the accumulated size of the packets in bytes. 32 | 33 | Else: 34 | 35 | * The calculation of the accumulated size will be skipped. 36 | 37 | #Examples 38 | 39 | ###(1) Classic 40 | 41 | ###(2) Legacy 42 | 43 | ###(3) Reference 44 | 45 | ###(4) References -------------------------------------------------------------------------------- /docs/messaging/send.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | void BSPLib::Classic::Send( uint32_t pid, const void *tag, 5 | const void *payload, size_t size ) // (1) Classic 6 | void bsp_send( uint32_t pid, const void *tag, 7 | const void *payload, size_t size ) // (2) Legacy 8 | ``` 9 | 10 | Send a buffered message to the processor with ID pid using a tag to identify the message. 11 | 12 | 1. Classic BSP function, this is the interface one should prefer to use over the old BSP interface. 13 | 2. Legacy BSP function, this interface is included for backwards compatibility with other BSP libraries. 14 | 15 | !!! tip 16 | There are easier functions to work with. See for [Containers](sendContainer.md), 17 | [Primitives](sendPrimitive.md), [Iterators](sendIterator.md), [Pointers with Primitive Tags](sendPtrs.md) 18 | and [Pointers with Container Tags](sendPtrs.md). 19 | 20 | #Parameters 21 | 22 | * `pid` The ID of the processor to send to. 23 | * `tag` The tag by which the other processor can identify the message. 24 | * `payload` Pointer to the payload of the message. 25 | * `size` Size of the message in bytes. 26 | 27 | #Pre-Conditions 28 | * [`BSPLib::Begin()`](../logic/begin.md) has been called. 29 | * Tagsize is equal on all threads. 30 | 31 | #Examples 32 | 33 | ###(1) Classic 34 | 35 | ###(2) Legacy -------------------------------------------------------------------------------- /docs/messaging/sendContainer.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | template< typename tTag, typename tContainer > 5 | void BSPLib::SendContainer( uint32_t pid, tTag *tag, 6 | tContainer &container ) // (1) Container-Pointer 7 | 8 | template< typename tTag, typename tContainer > 9 | void BSPLib::SendContainer( uint32_t pid, tTag &tag, 10 | tContainer &container ) // (2) Container-Reference 11 | 12 | template< typename tTagPrimitive, typename tContainer, size_t tTagSize > 13 | void BSPLib::SendContainerWithCArray( uint32_t pid, tTagPrimitive( &tag )[tTagSize], 14 | tContainer &container ) // (3) Container-CArray 15 | 16 | template< typename tContainer > 17 | void BSPLib::SendContainer( uint32_t pid, tContainer &container ) // (4) Container 18 | 19 | template< typename tPrimitive, typename tTag, size_t tSize > 20 | void BSPLib::SendCArray( uint32_t pid, tTag *tag, 21 | tPrimitive( &payload )[tSize] ) // (5) CArray-Pointer 22 | 23 | template< typename tPrimitive, typename tTag, size_t tSize > 24 | void BSPLib::SendCArray( uint32_t pid, tTag &tag, 25 | tPrimitive( &payload )[tSize] ) // (6) CArray-Reference 26 | 27 | template< typename tPrimitive, typename tTagPrimitive, size_t tSize, size_t tTagSize > 28 | void BSPLib::SendCArrayWithCArray( uint32_t pid, tTagPrimitive( &tagContainer )[tTagSize], 29 | tPrimitive( &payload )[tSize] ) // (7) CArray-CArray 30 | 31 | template< typename tPrimitive, size_t tSize > 32 | void BSPLib::SendCArray( uint32_t pid, tPrimitive( &payload )[tSize] ) // (8) CArray 33 | ``` 34 | 35 | Send a buffered message to the processor with ID pid using a tag to identify the message. 36 | 37 | 1. Sends an entire container as message, accompanied by a tag that may either be a primitive or a contiguous container. 38 | 2. Sends an entire container as message, accompanied by a tag that starts at `tagPtr`. 39 | 3. Sends an entire container as message, accompanied by a tag that is an entire C-Array. 40 | 4. Has the same behaviour as (2), using that `tagPtr = nullptr`. 41 | 5. Sends an entire C-Array as message, accompanied by a tag that may either be a primitive or a contiguous container. 42 | 6. Sends an entire C-Array as message, accompanied by a tag that starts at `tagPtr`. 43 | 7. Sends an entire C-Array as message, accompanied by a tag that is an entire C-Array. 44 | 8. Has the same behaviour as (6), using that `tagPtr = nullptr`. 45 | 46 | !!! tip 47 | * There are also other specialisations available. See 48 | [Containers](sendContainer.md), [Primitives](sendPrimitive.md), [Iterators](sendIterator.md), 49 | [Pointes with Primitive Tags](sendPtrs.md) and [Pointers with Container Tags](sendPtrs.md). 50 | * You can safely pass both primitives and contiguous containers, like `std::vector` 51 | or `std:array` using the `tag` parameter. They will be specialised by 52 | [`BSPLib::SendPtrs()`](sendPtrs.md) that is called internally. 53 | * If you want to use a reference to a primitive as a tag, have a look at 54 | [Send Memory - Pointers - Primitives](sendPtrs.md). 55 | * If you want to use a reference to a container as a tag, have a look at 56 | [Send Memory - Pointers - Containers](sendTagContainer.md). 57 | 58 | !!! danger "Warnings" 59 | Make sure that in all cases, the tagsize is appropriately set. Using these functions does not guarantee that the tagsize 60 | is always correct. See [`BSPLib::SetTagSize()`](../messagingutil/settagsize.md). 61 | 62 | #Parameters 63 | 64 | * `pid` The ID of the processor to send to. 65 | * `tag` The tag by which the other processor can identify the message. This may be either a primitive or a contiguous container. 66 | * `begin` Iterator describing the begin of the payload. 67 | * `end` Iterator describing the end of the payload. 68 | * `count` Number of primitives in the payload. 69 | * `tagPtr` Pointer to the beginning of the tag. 70 | * `tagContainer` C-Array containing the tag. 71 | 72 | #Pre-Conditions 73 | * [`BSPLib::Begin()`](../logic/begin.md) has been called. 74 | * Tagsize is equal on all threads. 75 | 76 | #Examples 77 | 78 | ###(1) Container-Pointer 79 | ###(2) Container-Reference 80 | ###(3) Container-CArray 81 | ###(4) Container 82 | ###(5) CArray-Pointer 83 | ###(6) CArray-Reference 84 | ###(7) CArray-CArray 85 | ###(8) CArray -------------------------------------------------------------------------------- /docs/messaging/sendIterator.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | template< typename tIterator, typename tTag > 5 | void BSPLib::SendIterator( uint32_t pid, tTag &tag, tIterator begin, 6 | size_t count ) // (1) Begin-Count-Reference 7 | 8 | template< typename tIterator, typename tTag > 9 | void BSPLib::SendIterator( uint32_t pid, tTag *tagPtr, tIterator begin, 10 | size_t count ) // (2) Begin-Count-Pointer 11 | 12 | template< typename tIterator, typename tTag > 13 | void BSPLib::SendIterator( uint32_t pid, tTag &tag, tIterator begin, 14 | tIterator end ) // (3) Begin-End-Reference 15 | 16 | template< typename tIterator, typename tTag > 17 | void BSPLib::SendIterator( uint32_t pid, tTag *tagPtr, tIterator begin, 18 | tIterator end ) // (4) Begin-End-Pointer 19 | 20 | template< typename tIterator, typename tTagPrimitive, uint32_t tTagSize > 21 | void BSPLib::SendIteratorWithCArray( uint32_t pid, tTagPrimitive( &tagContainer )[tTagSize], 22 | tIterator begin, size_t count ) // (5) Begin-Count-CArray 23 | 24 | template< typename tIterator, typename tTagPrimitive, uint32_t tTagSize > 25 | void BSPLib::SendIteratorWithCArray( uint32_t pid, tTagPrimitive( &tagContainer )[tTagSize], 26 | tIterator begin, tIterator end ) // (6) Begin-End-CArray 27 | 28 | 29 | 30 | template< typename tIterator > 31 | void BSPLib::SendIterator( uint32_t pid, tIterator begin, 32 | size_t count ) // (7) Begin-Count 33 | 34 | template< typename tIterator > 35 | void BSPLib::SendIterator( uint32_t pid, tIterator begin, 36 | tIterator end ) // (8) Begin-End 37 | ``` 38 | 39 | Send a buffered message to the processor with ID pid using a tag to identify the message. 40 | 41 | 1. Sends a block of `count` primitives starting at `begin` as message, accompanied by a tag that may either be a primitive or a contiguous container. 42 | 2. Sends a block of `count` primitives starting at `begin` as message, accompanied by a tag that starts at `tagPtr`. 43 | 3. Has the same behaviour as (1), using that `count = end - begin`. 44 | 4. Has the same behaviour as (2), using that `count = end - begin`. 45 | 5. Sends a block of `count` primitives starting at `begin` as message, accompanied by a tag that is an entire C-Array. 46 | 6. Has the same behaviour as (5), using that `count = end - begin`. 47 | 7. Has the same behaviour as (2), using that `tagPtr = nullptr`, no tag is sent. 48 | 8. Has the same behaviour as (4), using that `tagPtr = nullptr`, no tag is sent. 49 | 50 | !!! tip 51 | * There are also other specialisations available. See 52 | [Containers](sendContainer.md), [Primitives](sendPrimitive.md), [Iterators](sendIterator.md), 53 | [Pointes with Primitive Tags](sendPtrs.md) and [Pointers with Container Tags](sendPtrs.md). 54 | * You can safely pass both primitives and contiguous containers, like `std::vector` 55 | or `std:array` using the `tag` parameter. They will be specialised by 56 | [`BSPLib::SendPtrs()`](sendPtrs.md) that is called internally. 57 | * If you want to use a reference to a primitive as a tag, have a look at 58 | [Send Memory - Pointers - Primitives](sendPtrs.md). 59 | * If you want to use a reference to a container as a tag, have a look at 60 | [Send Memory - Pointers - Containers](sendTagContainer.md). 61 | 62 | !!! danger "Warnings" 63 | Make sure that in all cases, the tagsize is appropriately set. Using these functions does not guarantee that the tagsize 64 | is always correct. See [`BSPLib::SetTagSize()`](../messagingutil/settagsize.md). 65 | 66 | #Parameters 67 | 68 | * `pid` The ID of the processor to send to. 69 | * `tag` The tag by which the other processor can identify the message. This may be either a primitive or a contiguous container. 70 | * `begin` Iterator describing the begin of the payload. 71 | * `end` Iterator describing the end of the payload. 72 | * `count` Number of primitives in the payload. 73 | * `tagPtr` Pointer to the beginning of the tag. 74 | * `tagContainer` C-Array containing the tag. 75 | 76 | #Pre-Conditions 77 | * [`BSPLib::Begin()`](../logic/begin.md) has been called. 78 | * Tagsize is equal on all threads. 79 | 80 | #Examples 81 | 82 | ###(1) Begin-Count-Reference 83 | ###(2) Begin-Count-Pointer 84 | ###(3) Begin-End-Reference 85 | ###(4) Begin-End-Pointer 86 | ###(5) Begin-Count-CArray 87 | ###(6) Begin-End-CArray 88 | ###(7) Begin-Count 89 | ###(8) Begin-End -------------------------------------------------------------------------------- /docs/messaging/sendPrimitive.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | template< typename tPrimitive, typename tTag > 5 | void BSPLib::Send( uint32_t pid, tTag &tag, 6 | const tPrimitive &payload ) // (1) References 7 | 8 | template< typename tTag > 9 | void BSPLib::Send( uint32_t pid, tTag &tag, 10 | const std::string &payload ) // (2) std::string-Reference 11 | 12 | template< typename tPrimitive, typename tTag > 13 | void BSPLib::Send( uint32_t pid, tTag *tagPtr, 14 | const tPrimitive &payload ) // (3) Reference-Pointer 15 | 16 | template< typename tTag > 17 | void BSPLib::Send( uint32_t pid, tTag *tagPtr, 18 | const std::string &payload ) // (4) std::string-Pointer 19 | 20 | template< typename tPrimitive > 21 | void BSPLib::Send( uint32_t pid, const tPrimitive &payload ) // (5) Reference 22 | 23 | template<> 24 | void BSPLib::Send( uint32_t pid, const std::string &payload ) // (6) std::string 25 | 26 | template< typename tPrimitive, typename tTagPrimitive, size_t tTagSize > 27 | void BSPLib::SendWithCArray( uint32_t pid, tTagPrimitive( &tagContainer )[tTagSize], 28 | const tPrimitive &payload ) // (7) Reference-CArray 29 | 30 | template< typename tTagPrimitive, size_t tTagSize > 31 | void BSPLib::SendWithCArray( uint32_t pid, tTagPrimitive( &tagContainer )[tTagSize], 32 | const std::string &payload ) // (8) std::string-CArray 33 | ``` 34 | 35 | Send a buffered message to the processor with ID pid using a tag to identify the message. 36 | 37 | 1. Sends one primitive as message, accompanied by a tag that may either be a primitive or a contiguous container. 38 | 2. Overload of (1) for `std::string`. 39 | 3. Sends one primitive as message, accompanied by a tag that starts at `tagPtr`. 40 | 4. Overload of (3) for `std::string`. 41 | 5. Sends one primitive as message, without a tag. 42 | 6. Overload of (5) for `std::string`. 43 | 7. Sends one primitive as message, accompanied by a tag that is a C-Array. 44 | 8. Overload of (7) for `std::string`. 45 | 46 | !!! tip 47 | * There are also other specialisations available. See 48 | [Containers](sendContainer.md), [Primitives](sendPrimitive.md), [Iterators](sendIterator.md), 49 | [Pointes with Primitive Tags](sendPtrs.md) and [Pointers with Container Tags](sendPtrs.md). 50 | * You can safely pass both primitives and contiguous containers, like `std::vector` 51 | or `std:array` using the `tag` parameter. They will be specialised by 52 | [`BSPLib::SendPtrs()`](sendPtrs.md) that is called internally. 53 | * If you want to use a reference to a primitive as a tag, have a look at 54 | [Send Memory - Pointers - Primitives](sendPtrs.md). 55 | * If you want to use a reference to a container as a tag, have a look at 56 | [Send Memory - Pointers - Containers](sendTagContainer.md). 57 | 58 | !!! danger "Warnings" 59 | Make sure that in all cases, the tagsize is appropriately set. Using these functions does not guarantee that the tagsize 60 | is always correct. See [`BSPLib::SetTagSize()`](../messagingutil/settagsize.md). 61 | 62 | #Parameters 63 | 64 | * `pid` The ID of the processor to send to. 65 | * `tag` The tag by which the other processor can identify the message. This may be either a primitive or a contiguous container. 66 | * `payload` Reference to the primitive that will be the payload of the message. 67 | * `tagPtr` Pointer to the beginning of the tag. 68 | * `tagContainer` C-Array containing the tag. 69 | 70 | #Pre-Conditions 71 | * [`BSPLib::Begin()`](../logic/begin.md) has been called. 72 | * Tagsize is equal on all threads. 73 | 74 | #Examples 75 | 76 | ###(1) References 77 | ###(2) std::string-Reference 78 | ###(3) Reference-Pointer 79 | ###(4) std::string-Pointer 80 | ###(5) Reference 81 | ###(6) std::string 82 | ###(7) Reference-CArray 83 | ###(8) std::string-CArray -------------------------------------------------------------------------------- /docs/messaging/sendPtrs.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | template< typename tPrimitive, typename tTagPrimitive > 5 | void BSPLib::SendPtrs( uint32_t pid, tTagPrimitive *tag, tPrimitive *begin, 6 | size_t count ) // (1) Begin-Count-Pointer 7 | 8 | template< typename tPrimitive, typename tTagPrimitive > 9 | void BSPLib::SendPtrs( uint32_t pid, tTagPrimitive *tag, tPrimitive *begin, 10 | tPrimitive *end ) // (2) Begin-End-Pointer 11 | 12 | template< typename tPrimitive, typename tTag > 13 | void BSPLib::SendPtrs( uint32_t pid, const tTag &tag, tPrimitive *begin, 14 | size_t count ) // (3) Begin-Count-Reference 15 | 16 | template< typename tPrimitive, typename tTag > 17 | void BSPLib::SendPtrs( uint32_t pid, const tTag &tag, tPrimitive *begin, 18 | tPrimitive *end ) // (4) Begin-End-Reference 19 | 20 | template< typename tPrimitive > 21 | void BSPLib::SendPtrs( uint32_t pid, const std::string &tag, tPrimitive *begin, 22 | tPrimitive *end ) // (5) Begin-End-std::string 23 | 24 | template< typename tPrimitive > 25 | void BSPLib::SendPtrs( uint32_t pid, const std::string &tag, tPrimitive *begin, 26 | size_t count ) // (6) Begin-Count-std::string 27 | 28 | template< typename tPrimitive > 29 | void BSPLib::SendPtrs( uint32_t pid, tPrimitive *begin, 30 | size_t count ) // (7) Begin-Count 31 | 32 | template< typename tPrimitive > 33 | void BSPLib::SendPtrs( uint32_t pid, tPrimitive *begin, 34 | tPrimitive *end ) // (8) Begin-End 35 | ``` 36 | 37 | Send a buffered message to the processor with ID pid using a tag to identify the message. 38 | 39 | 1. Sends a block of `count` primitives starting at `begin` as message, accompanied by a tag that may either be a primitive or a contiguous container. 40 | 2. Sends a block of `count` primitives starting at `begin` as message, accompanied by a tag that starts at `tagPtr`. 41 | 3. Has the same behaviour as (1), using that `count = end - begin`. 42 | 4. Has the same behaviour as (2), using that `count = end - begin`. 43 | 5. Sends a block of `count` primitives starting at `begin` as message, accompanied by a tag that is an entire C-Array. 44 | 6. Has the same behaviour as (5), using that `count = end - begin`. 45 | 7. Has the same behaviour as (2), using that `tagPtr = nullptr`, no tag is sent. 46 | 8. Has the same behaviour as (4), using that `tagPtr = nullptr`, no tag is sent. 47 | 48 | !!! tip 49 | * There are also other specialisations available. See 50 | [Containers](sendContainer.md), [Primitives](sendPrimitive.md), [Iterators](sendIterator.md), 51 | [Pointes with Primitive Tags](sendPtrs.md) and [Pointers with Container Tags](sendPtrs.md). 52 | * You can safely pass both primitives and contiguous containers, like `std::vector` 53 | or `std:array` using the `tag` parameter. They will be specialised by 54 | [`BSPLib::SendPtrs()`](sendPtrs.md) that is called internally. 55 | * If you want to use a reference to a primitive as a tag, have a look at 56 | [Send Memory - Pointers - Primitives](sendPtrs.md). 57 | * If you want to use a reference to a container as a tag, have a look at 58 | [Send Memory - Pointers - Containers](sendTagContainer.md). 59 | 60 | !!! danger "Warnings" 61 | Make sure that in all cases, the tagsize is appropriately set. Using these functions does not guarantee that the tagsize 62 | is always correct. See [`BSPLib::SetTagSize()`](../messagingutil/settagsize.md). 63 | 64 | #Parameters 65 | 66 | * `pid` The ID of the processor to send to. 67 | * `tag` The tag by which the other processor can identify the message. This may be either a primitive or a contiguous container. 68 | * `begin` Pointer to the begin of the payload. 69 | * `end` Pointer to the end of the payload. 70 | * `count` Number of primitives in the payload. 71 | * `tagPtr` Pointer to the beginning of the tag. 72 | * `tagCArray` C-Array containing the tag. 73 | 74 | #Pre-Conditions 75 | * [`BSPLib::Begin()`](../logic/begin.md) has been called. 76 | * Tagsize is equal on all threads. 77 | 78 | #Examples 79 | 80 | ###(1) Begin-Count-Reference 81 | ###(2) Begin-End-Pointer 82 | ###(3) Begin-Count-Pointer 83 | ###(4) Begin-End-Reference 84 | ###(5) Begin-Count-std::string 85 | ###(6) Begin-End-std::string 86 | ###(7) Begin-Count 87 | ###(8) Begin-End -------------------------------------------------------------------------------- /docs/messaging/sendTagContainer.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | template< typename tPrimitive, typename tTagPrimitive > 5 | void BSPLib::SendPtrs( uint32_t pid, std::vector< tTagPrimitive > &tagVector, tPrimitive *begin, 6 | size_t count ) // (1) Begin-Count-Vector 7 | 8 | template< typename tPrimitive, typename tTagPrimitive > 9 | void BSPLib::SendPtrs( uint32_t pid, std::vector< tTagPrimitive > &tagVector, tPrimitive *begin, 10 | tPrimitive *end ) // (2) Begin-End-Vector 11 | 12 | template< typename tPrimitive, typename tTagPrimitive, uint32_t tTagSize > 13 | void BSPLib::SendPtrs( uint32_t pid, std::array< tTagPrimitive, tTagSize > &tagArray, 14 | tPrimitive *begin, size_t count ) // (3) Begin-Count-StdArray 15 | 16 | template< typename tPrimitive, typename tTagPrimitive, uint32_t tTagSize > 17 | void BSPLib::SendPtrs( uint32_t pid, std::array< tTagPrimitive, tTagSize > &tagArray, 18 | tPrimitive *begin, tPrimitive *end ) // (4) Begin-End-StdArray 19 | 20 | template< typename tPrimitive, typename tTagPrimitive, uint32_t tTagSize > 21 | void BSPLib::SendPtrsWithCArray( uint32_t pid, tTagPrimitive( &tagCArray )[tTagSize], 22 | tPrimitive *begin, size_t count ) // (5) Begin-Count-CArray 23 | 24 | template< typename tPrimitive, typename tTagPrimitive, uint32_t tTagSize > 25 | void BSPLib::SendPtrsWithCArray( uint32_t pid, tTagPrimitive( &tagCArray )[tTagSize], 26 | tPrimitive *begin, tPrimitive *end ) // (6) Begin-End-CArray 27 | ``` 28 | 29 | Send a buffered message to the processor with ID pid using a tag to identify the message. 30 | 31 | 1. Sends a block of `count` primitives starting at `begin` as message, accompanied by a tag that consists of an entire `std::vector`. 32 | 2. Has the same behaviour as (1), using that `count = end - begin`. 33 | 3. Sends a block of `count` primitives starting at `begin` as message, accompanied by a tag that consists of an entire `std::array`. 34 | 4. Has the same behaviour as (3), using that `count = end - begin`. 35 | 5. Sends a block of `count` primitives starting at `begin` as message, accompanied by a tag that consists of an entire C-Array. 36 | 6. Has the same behaviour as (5), using that `count = end - begin`. 37 | 38 | !!! tip 39 | * There are also other specialisations available. See 40 | [Containers](sendContainer.md), [Primitives](sendPrimitive.md), [Iterators](sendIterator.md), 41 | [Pointes with Primitive Tags](sendPtrs.md) and [Pointers with Container Tags](sendPtrs.md). 42 | * You can safely pass both primitives and contiguous containers, like `std::vector` 43 | or `std:array` using the `tag` parameter. They will be specialised by 44 | [`BSPLib::SendPtrs()`](sendPtrs.md) that is called internally. 45 | * If you want to use a reference to a primitive as a tag, have a look at 46 | [Send Memory - Pointers - Primitives](sendPtrs.md). 47 | * If you want to use a reference to a container as a tag, have a look at 48 | [Send Memory - Pointers - Containers](sendTagContainer.md). 49 | 50 | !!! danger "Warnings" 51 | Make sure that in all cases, the tagsize is appropriately set. Using these functions does not guarantee that the tagsize 52 | is always correct. See [`BSPLib::SetTagSize()`](../messagingutil/settagsize.md). 53 | 54 | #Parameters 55 | 56 | * `pid` The ID of the processor to send to. 57 | * `begin` Iterator describing the begin of the payload. 58 | * `end` Iterator describing the end of the payload. 59 | * `count` Number of primitives in the payload. 60 | * `tagVector` `std::vector` containing the entire tag. 61 | * `tagArray` `std::array` containing the entire tag. 62 | * `tagCArray` C-Array containing the entire tag. 63 | 64 | #Pre-Conditions 65 | * [`BSPLib::Begin()`](../logic/begin.md) has been called. 66 | * Tagsize is equal on all threads. 67 | 68 | #Examples 69 | 70 | ###(1) Begin-Count-Vector 71 | ###(2) Begin-End-Vector 72 | ###(3) Begin-Count-StdArray 73 | ###(4) Begin-End-StdArray 74 | ###(5) Begin-Count-CArray 75 | ###(6) Begin-End-CArray -------------------------------------------------------------------------------- /docs/messagingutil/gettag.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | void BSPLib::Classic::GetTag( size_t *status, void *tag ) // (1) Classic 5 | void bsp_get_tag( size_t *status, void *tag ) // (2) Legacy 6 | 7 | template< typename tPrimitive > 8 | void BSPLib::GetTag( size_t &statusRef, tPrimitive &tagRef ) // (3) Reference 9 | 10 | template<> 11 | void BSPLib::GetTag( size_t &statusRef, std::string &tagRef ) // (4) std::string 12 | 13 | template< typename tPrimitive > 14 | void BSPLib::GetTagPtr( size_t &statusRef, tPrimitive *tagPtr ) // (5) Pointer 15 | 16 | template< typename tIterator > 17 | void BSPLib::GetTagIterator( size_t &statusRef, tIterator tagBegin ) // (6) Iterator 18 | 19 | template< typename tContainer > 20 | void BSPLib::GetTagContainer( size_t &statusRef, tContainer &tagContainer ) // (7) Container 21 | 22 | template< typename tPrimitive, size_t tSize > 23 | void BSPLib::GetTagCArray( size_t &statusRef, tPrimitive( &tagCArray )[tSize] ) // (8) C-Array 24 | ``` 25 | 26 | Gets the tag for the next message in the send queue. 27 | 28 | 1. Classic BSP function. 29 | 2. Legacy BSP function 30 | 3. Uses a reference for `status`, as it is not allowed to be `nullptr`. 31 | Uses a reference to store the tag. 32 | 4. Specialisation of (3) for `std::string`. 33 | 5. Uses a reference for `status`. More typesafe version for the tag pointer. 34 | 6. Uses a reference for `status`. Uses an iterator to describe te beginning of the tag. 35 | 7. Uses a reference for `status`. Uses a container to store the tag. 36 | 8. Uses a reference for `status`. Uses a C-Array to store the tag. 37 | 38 | #Parameters 39 | 40 | * `status` Void pointer to store the status to. 41 | * `tag` Void pointer to store the tag to. 42 | * `statusRef` Reference to store the status to. 43 | * `tagRef` Reference to store the tag to. 44 | * `tagPtr` Typesafe pointer to store the tag to. 45 | * `tagBegin` Iterator describing the begin of the tag. 46 | * `tagContainer` Container to store the tag to. 47 | * `tagCArray` C-Array to store the tag to. 48 | 49 | #Pre-Conditions 50 | * [`BSPLib::Begin()`](../logic/begin.md) has been called. 51 | * If the send queue is empty or the cursor is at/behind the end of the queue: 52 | * Returns a status equal to `-1`. 53 | 54 | Else: 55 | 56 | * Returns the size of the buffer of the request as status. 57 | * Writes the tag to the desired destination. 58 | 59 | #Post-Conditions 60 | The queue is in the same state as before. 61 | 62 | #Examples 63 | 64 | ### (1) Classic 65 | 66 | ### (2) Legacy 67 | 68 | ### (3) Reference 69 | 70 | ### (4) std::string 71 | 72 | ### (5) Pointer 73 | 74 | ### (6) Iterator 75 | 76 | ### (7) Container 77 | 78 | ### (8) C-Array -------------------------------------------------------------------------------- /docs/messagingutil/settagsize.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | void BSPLib::Classic::SetTagSize( size_t *size ) // (1) Classic 5 | void bsp_set_tagsize( size_t *size ) // (2) Legacy 6 | 7 | template< typename tPrimitive > 8 | void BSPLib::SetTagsize() // (3) Primitive 9 | 10 | template< typename tPrimitive > 11 | void SetTagsize( uint32_t count ) // (4) Count 12 | ``` 13 | 14 | Sets a tagsize for the next superstep. 15 | 16 | 1. Classic BSP function. 17 | 2. Legacy BSP function 18 | 3. Sets the tagsize to the size of a primitive, `sizeof(tPrimitive)` 19 | will be the new tagsize. 20 | 4. Sets the tagsize to the size of count primitives, `count * sizeof(tPrimitive)`. 21 | 22 | #Parameters 23 | 24 | * `size` Pointer to the desired size. 25 | * `count` Number of primitives to set the tagsize to. 26 | 27 | #Pre-Conditions 28 | * [`BSPLib::Begin()`](../logic/begin.md) has been called. 29 | * `size != nullptr`. 30 | 31 | #Post-Conditions 32 | The tagsize will be updated during the next [synchronization](../sync/sync.md) 33 | 34 | #Examples 35 | 36 | ### (1) Classic 37 | 38 | ### (2) Legacy 39 | 40 | ### (3) Primitive 41 | 42 | ### (4) Count -------------------------------------------------------------------------------- /docs/regdereg/pop.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | void BSPLib::Pop( const void *ident ) // (1) Modern 5 | void BSPLib::Pop() // (2) Padding 6 | 7 | template< typename tPrimitive > 8 | void BSPLib::Pop( tPrimitive &identRef ) // (3) Reference 9 | 10 | template<> 11 | void BSPLib::Pop( std::string &stringRef ) // (4) std::string 12 | 13 | template< typename tPrimitive > 14 | void BSPLib::PopPtrs( tPrimitive *begin ) // (5) Primitive pointer 15 | 16 | template < typename tIterator> 17 | void BSPLib::PopIterator( tIterator beginIt ) // (6) Iterator 18 | 19 | template< typename tPrimitive, size_t tSize > 20 | void BSPLib::PopCArray( tPrimitive( &cArray )[tSize] ) // (7) C-Array 21 | 22 | template< typename tContainer > 23 | void BSPLib::PopContainer( tContainer &container ) // (8) Container 24 | 25 | void BSPLib::Classic::Pop( const void *ident ) // (9) Classic 26 | void bsp_popreg( const void *ident ) // (10) BSP 27 | ``` 28 | 29 | Pops a register and makes it unavailable in the next superstep. 30 | BSPLib can have communication with any 31 | contiguous data type. To ensure this requirement, the library needs to know what 32 | addresses are available for communication. To recognise addresses of other 33 | processors, the order of [registration](push.md) and [deregistration](pop.md) 34 | needs to be the same in each processor. When one processor does not need to register 35 | an address, a `nullptr`can be pushed, or the specialised function (2) can be used. 36 | Each push should be accompanied by a pop, or is assumed to be popped at the end of 37 | the BSP program. 38 | 39 | 1. Modern interface of the classic BSP function. 40 | 2. Removes padding added by [`BSPLib::Push()`](push.md) (without parameters). 41 | 3. Pops the register belonging to a primitive. 42 | 4. Template specialisation for `std::string`. 43 | 5. Pops the address of `begin`. 44 | 6. Pops the address of `beginIt`. 45 | 7. Pops the addresses of the C-Array. 46 | 8. Pops the addresses of the container. 47 | 9. Classic BSP function, this is the interface one should prefer to use over the old BSP interface. 48 | 10. Legacy BSP function, this interface is included for backwards compatibility with other BSP libraries. 49 | 50 | !!! danger "Warnings" 51 | * In case of (4), the `std::string` must not have been resized. 52 | * In case of (6) and (8), make sure the iterators describe cotiguous memory, 53 | and have not been invalidated (due to resizes). 54 | * When `BSPLib::Push()` is called after `BSPLib::Pop()`, the register that has 55 | been popped will not be replaced by the new register, as the naming might 56 | suggest. 57 | 58 | !!! note "Notes" 59 | In the current implementation, the pointer to the top of the registration stack 60 | is never lowered. In the programs we tested until now, this has not been a 61 | problem. We might change this behaviour in the future. In case we do, no changes 62 | will be needed in existing BSP programs. The stack is always cleared when a new 63 | BSP program is initialised. 64 | 65 | #Parameters 66 | 67 | * `ident` The address to deregister. 68 | * `identRef` Reference to the variable to deregister. 69 | * `stringRef` Reference to the string to deregiser. 70 | * `begin` Begin of the address space to deregister. 71 | * `beginIt` Iterator describing the begin of the address space to deregister. 72 | * `cArray` C-Array of which we deregister all addresses. 73 | * `container` Container of which we deregister all addresses. 74 | 75 | #Pre-Conditions 76 | * [`BSPLib::Classic::Begin()`](../logic/begin.md) has been called. 77 | 78 | #Post-Conditions 79 | * Pop request has been queued. 80 | * In the next superstep, this register will be unavailable for [`BSPLib::Put()`](../com/put.md)/[`BSPLib::Get()`](../com/get.md). 81 | 82 | #Examples 83 | 84 | ### (1) Modern 85 | 86 | ### (2) Padding 87 | 88 | ### (3) Reference 89 | 90 | ### (4) std::string 91 | 92 | ### (5) Primitive pointer 93 | 94 | ### (6) Iterator 95 | 96 | ### (7) C-Array 97 | 98 | ### (8) Container 99 | 100 | ### (9) Classic 101 | 102 | ### (10) BSP -------------------------------------------------------------------------------- /docs/regdereg/push.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | void BSPLib::Push( const void *ident, size_t byteSize ) // (1) Modern 5 | void BSPLib::Push() // (2) Padding 6 | 7 | template< typename tPrimitive > 8 | void BSPLib::Push( tPrimitive &identRef ) // (3) Reference 9 | 10 | template<> 11 | void BSPLib::Push( std::string &stringRef ) // (4) std::string 12 | 13 | template< typename tPrimitive > 14 | void BSPLib::PushPtrs( tPrimitive *begin, size_t count ) // (5) Primitive pointer 15 | 16 | template< typename tPrimitive > 17 | void BSPLib::PushPtrs( tPrimitive *begin, tPrimitive *end ) // (6) Primitive pointers 18 | 19 | template < typename tIterator> 20 | void BSPLib::PushIterator( tIterator beginIt, size_t count ) // (7) Iterator 21 | 22 | template < typename tIterator> 23 | void BSPLib::PushIterator( tIterator beginIt, tIterator endIt ) // (8) Iterators 24 | 25 | template< typename tPrimitive, size_t tSize > 26 | void BSPLib::PushCArray( tPrimitive( &cArray )[tSize] ) // (9) C-Array 27 | 28 | template< typename tContainer > 29 | void BSPLib::PushContainer( tContainer &container ) // (10) Container 30 | 31 | 32 | void BSPLib::Classic::Push( const void *ident, size_t byteSize ) // (11) Classic 33 | void bsp_pushreg( const void *ident, size_t byteSize ) // (12) BSP 34 | ``` 35 | 36 | Pushes a register, with the given size. BSPLib can have communication with any 37 | contiguous data type. To ensure this requirement, the library needs to know what 38 | addresses are available for communication. To recognise addresses of other 39 | processors, the order of [registration](push.md) and [deregistration](pop.md) 40 | needs to be the same in each processor. When one processor does not need to register 41 | an address, a `nullptr`can be pushed, or the specialised function (2) can be used. 42 | Each push should be accompanied by a pop, or is assumed to be popped at the end of 43 | the BSP program. 44 | 45 | 1. Modern interface of the classic BSP function. 46 | 2. Adds padding if the current processor does not need to push. 47 | 3. Pushes a primitive as register. Computes the bytesize internally. 48 | 4. Template specialisation for `std::string`. 49 | 5. Pushes the address of `begin`, with bytesize `count * sizeof(tPrimitive)`. 50 | 6. Pushes all addresses from `begin` to `end`. Computes the bytesize internally. 51 | 7. Pushes the address of the `beginIt` iterator up to `count` adresses more. 52 | 8. Pushes all addresses from `beginIt` to `endIt`. Computes the bytesize internally. 53 | 9. Pushes all addresses of the C-Array, with bytesize `tSize * sizeof(tPrimitive)`. 54 | 10. Pushes all addresses of the container, with bytesize `container.size() * sizeof(tContainer::value_type)`. 55 | 11. Classic BSP function. 56 | 12. Legacy BSP function. 57 | 58 | !!! danger "Warnings" 59 | * In case of (4), the std::string must not be resized. If a resize is absolutely 60 | necessary, it should be done before pushing the register, or after popping the 61 | register. Also, make sure the processors agree on the size beforehand. 62 | * In case of (7), (8) and (10), make sure the iterators describe contiguous memory, 63 | and are not invalidated (due to resizes). 64 | * When `BSPLib::Push()` is called after `BSPLib::Pop()`, the register that has 65 | been popped will not be replaced by the new register, as the naming might 66 | suggest. 67 | 68 | !!! note "Notes" 69 | In the current implementation, the pointer to the top of the registration stack 70 | is never lowered. In the programs we tested until now, this has not been a 71 | problem. We might change this behaviour in the future. In case we do, no changes 72 | will be needed in existing BSP programs. The stack is always cleared when a new 73 | BSP program is initialised. 74 | 75 | 76 | #Parameters 77 | 78 | * `ident` The address to register. 79 | * `byteSize` The size in bytes of the address space. 80 | * `identRef` Reference to the variable to register. 81 | * `stringRef` Reference to the string to regiser. 82 | * `begin` Begin of the address space to register. 83 | * `count` Number of addresses to register in the current space. 84 | * `end` End of the address space to register. 85 | * `beginIt` Iterator describing the begin of the address space to register. 86 | * `endIt` Iterator describing the end of the address space to register. 87 | * `cArray` C-Array of which we register all addresses. 88 | * `container` Container of which we register all addresses. 89 | 90 | #Pre-Conditions 91 | * [`BSPLib::Classic::Begin()`](../logic/begin.md) has been called. 92 | 93 | #Post-Conditions 94 | * Push request has been queued. 95 | * In the next superstep, this register will be available for [`BSPLib::Put()`](../com/put.md)/[`BSPLib::Get()`](../com/get.md). 96 | 97 | #Examples 98 | 99 | ###(1) Modern 100 | 101 | ###(2) Padding 102 | 103 | ###(3) Reference 104 | 105 | ###(4) std::string 106 | 107 | ###(5) Primitive pointer 108 | 109 | ###(6) Primitive pointers 110 | 111 | ###(7) Iterator 112 | 113 | ###(8) Iterators 114 | 115 | ###(9) C-Array 116 | 117 | ###(10) Container 118 | 119 | ###(11) Classic 120 | 121 | ###(12) BSP -------------------------------------------------------------------------------- /docs/sync/sync.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | void BSPLib::Sync() // (1) Modern 5 | void BSPLib::Classic::Sync() // (2) Classic 6 | void bsp_sync() // (3) BSP 7 | ``` 8 | 9 | Synchronises all threads and communications. This marks the end of a computation super step, 10 | and each processor can handle its own computations between the super steps. At the end (and not earlier) 11 | of the super step in the synchronisation point, the communication is handled. All threads have queued 12 | their desired communications before this point, and the queues will now be handled here. The 13 | synchronisation point also ensures all threads are synchronised, and functions as a barrier. 14 | 15 | #Pre-Conditions 16 | * [`BSPLib::Classic::Begin()`](../logic/begin.md) has been called. 17 | 18 | #Post-Conditions 19 | * All threads have completed this superstep. 20 | * Tagsize has been synchronized and is available in the next superstep. 21 | * Get requests have been processed, updated data is available in the next superstep. 22 | * Pop requests have been processed, registers will be unavailable in the next superstep. 23 | * Put requests have been processed, updated data is available in the next superstep. 24 | * Buffers for the put requests have been cleared. 25 | * Push requests have been processed, registers will be available in the next superstep. 26 | 27 | 1. This is interface one should choose to use, and is semantically the same as the other interfaces. 28 | 2. Classic BSP function, this is the interface one should prefer to use over the old BSP interface. 29 | 3. Legacy BSP function, this interface is included for backwards compatibility with other BSP libraries. 30 | 31 | #Examples 32 | 33 | ###(1) Modern 34 | 35 | ```cpp 36 | void main( int32_t, const char ** ) 37 | { 38 | const uint32_t nProcs = BSPLib::NProcs(); 39 | // Waits for all threads to print the first line, 40 | // before printing the second line. 41 | BSPLib::Execute( [] 42 | { 43 | std::cout << "Thread " << BSPLib::ProcId() 44 | << " waiting on barrier 1" << std::endl; 45 | 46 | // Wait for all threads to print 47 | BSPLib::Sync(); 48 | 49 | std::cout << "Thread " << BSPLib::ProcId() 50 | << " waiting on barrier 2" << std::endl; 51 | 52 | BSPLib::Sync(); 53 | }, nProcs ); 54 | } 55 | ``` 56 | 57 | ###(2) Classic 58 | 59 | ```cpp 60 | void main( int32_t, const char ** ) 61 | { 62 | const uint32_t nProcs = BSPLib::NProcs(); 63 | // Waits for all threads to print the first line, 64 | // before printing the second line. 65 | BSPLib::Execute( [] 66 | { 67 | std::cout << "Thread " << BSPLib::Classic::ProcId() 68 | << " waiting on barrier 1" << std::endl; 69 | 70 | // Wait for all threads to print 71 | BSPLib::Classic::Sync(); 72 | 73 | std::cout << "Thread " << BSPLib::Classic::ProcId() 74 | << " waiting on barrier 2" << std::endl; 75 | 76 | BSPLib::Classic::Sync(); 77 | }, nProcs ); 78 | } 79 | ``` 80 | 81 | ###(3) BSP 82 | 83 | ```cpp 84 | void main( int32_t, const char ** ) 85 | { 86 | const uint32_t nProcs = bsp_nprocs(); 87 | // Waits for all threads to print the first line, 88 | // before printing the second line. 89 | BSPLib::Execute( [] 90 | { 91 | std::cout << "Thread " << bsp_pid() 92 | << " waiting on barrier 1" << std::endl; 93 | 94 | // Wait for all threads to print 95 | bsp_sync(); 96 | 97 | std::cout << "Thread " << bsp_pid() 98 | << " waiting on barrier 2" << std::endl; 99 | bsp_sync(); 100 | }, nProcs ); 101 | } 102 | ``` -------------------------------------------------------------------------------- /docs/util/nprocs.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | uint32_t BSPLib::NProcs() // (1) Modern 5 | uint32_t BSPLib::Classic::NProcs() // (2) Classic 6 | uint32_t bsp_nprocs() // (3) BSP 7 | ``` 8 | 9 | Gets the the amount of processors used by the BSP library. When the BSP library is not 10 | initialised this returns the amount of processors available in hardware. After initalisation 11 | it returns the maximum amount of processors available as initialised. 12 | 13 | 1. This is interface one should choose to use, and is semantically the same as the other interfaces. 14 | 2. Classic BSP function, this is the interface one should prefer to use over the old BSP interface. 15 | 3. Legacy BSP function, this interface is included for backwards compatibility with other BSP libraries. 16 | 17 | #Return Value 18 | 19 | The amount of processors available. 20 | 21 | #Pre-Conditions 22 | 23 | * If Begin has been called: 24 | * Returns the number of started threads. 25 | 26 | Else: 27 | 28 | * Returns the number of physical threads available. 29 | 30 | #Examples 31 | 32 | ###(1) Modern 33 | 34 | ```cpp 35 | void main( int32_t, const char ** ) 36 | { 37 | // The total amount of physical processors available 38 | const uint32_t nProcs = BSPLib::NProcs(); 39 | BSPLib::Execute( [] 40 | { 41 | std::cout << "The amount of processors we started with equals " << BSPLib::NProcs() << std::endl; 42 | }, nProcs ); 43 | 44 | // prints: "The amount of processors we started with equals 3", 3 times 45 | BSPLib::Execute( [] 46 | { 47 | std::cout << "The amount of processors we started with equals " << BSPLib::NProcs() << std::endl; 48 | }, 3 ); 49 | } 50 | ``` 51 | 52 | ###(2) Classic 53 | 54 | ```cpp 55 | void main( int32_t, const char ** ) 56 | { 57 | // The total amount of physical processors available 58 | const uint32_t nProcs = BSPLib::Classic::NProcs(); 59 | BSPLib::Execute( [] 60 | { 61 | std::cout << "The amount of processors we started with equals " << BSPLib::Classic::NProcs() << std::endl; 62 | }, nProcs ); 63 | 64 | // prints: "The amount of processors we started with equals 3", 3 times 65 | BSPLib::Execute( [] 66 | { 67 | std::cout << "The amount of processors we started with equals " << BSPLib::Classic::NProcs() << std::endl; 68 | }, 3 ); 69 | } 70 | ``` 71 | 72 | ###(3) BSP 73 | 74 | ```cpp 75 | void main( int32_t, const char ** ) 76 | { 77 | // The total amount of physical processors available 78 | const uint32_t nProcs = bsp_nprocs(); 79 | BSPLib::Execute( [] 80 | { 81 | std::cout << "The amount of processors we started with equals " << bsp_nprocs() << std::endl; 82 | }, nProcs ); 83 | 84 | // prints: "The amount of processors we started with equals 3", 3 times 85 | BSPLib::Execute( [] 86 | { 87 | std::cout << "The amount of processors we started with equals " << bsp_nprocs() << std::endl; 88 | }, 3 ); 89 | } 90 | ``` -------------------------------------------------------------------------------- /docs/util/procid.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | uint32_t BSPLib::ProcId() // (1) Modern 5 | uint32_t BSPLib::Classic::ProcId() // (2) Classic 6 | uint32_t bsp_pid() // (3) BSP 7 | ``` 8 | 9 | When [`BSPLib::Classic::Begin()`](../logic/begin.md) has been called, all processors other than the main thread 10 | will get a unique identifier assigned in the range [`[1, [BSPLib::NProcs() - 1]`](nprocs.md). The main 11 | thread holds identifier `0`. 12 | 13 | 1. This is interface one should choose to use, and is semantically the same as the other interfaces. 14 | 2. Classic BSP function, this is the interface one should prefer to use over the old BSP interface. 15 | 3. Legacy BSP function, this interface is included for backwards compatibility with other BSP libraries. 16 | 17 | #Return Value 18 | 19 | The current processor identifier. 20 | 21 | #Pre-Conditions 22 | 23 | * [`BSPLib::Classic::Begin()`](../logic/begin.md) has been called, otherwise 24 | this will return `0xdeadbeef`. 25 | 26 | 27 | #Examples 28 | 29 | ###(1) Modern 30 | 31 | ```cpp 32 | void main( int32_t, const char ** ) 33 | { 34 | // The total amount of physical processors available 35 | const uint32_t nProcs = BSPLib::NProcs(); 36 | 37 | // prints: "The current processor identifier is `x`", with x between 0 and `nProcs` - 1. 38 | BSPLib::Execute( [] 39 | { 40 | std::cout << "The current processor identifier is " << BSPLib::ProcId() << std::endl; 41 | }, nProcs ); 42 | 43 | // prints: "The current processor identifier is 0" 44 | BSPLib::Execute( [] 45 | { 46 | std::cout << "The current processor identifier is " << BSPLib::ProcId() << std::endl; 47 | }, 1 ); 48 | } 49 | ``` 50 | 51 | ###(2) Classic 52 | 53 | ```cpp 54 | void main( int32_t, const char ** ) 55 | { 56 | // The total amount of physical processors available 57 | const uint32_t nProcs = BSPLib::NProcs(); 58 | 59 | // prints: "The current processor identifier is `x`", with x between 0 and `nProcs` - 1. 60 | BSPLib::Execute( [] 61 | { 62 | std::cout << "The current processor identifier is " << BSPLib::Classic::ProcId() << std::endl; 63 | }, nProcs ); 64 | 65 | // prints: "The current processor identifier is 0" 66 | BSPLib::Execute( [] 67 | { 68 | std::cout << "The current processor identifier is " << BSPLib::Classic::ProcId() << std::endl; 69 | }, 1 ); 70 | } 71 | ``` 72 | 73 | ###(3) BSP 74 | 75 | ```cpp 76 | void main( int32_t, const char ** ) 77 | { 78 | // The total amount of physical processors available 79 | const uint32_t nProcs = BSPLib::NProcs(); 80 | 81 | // prints: "The current processor identifier is `x`", with x between 0 and `nProcs` - 1. 82 | BSPLib::Execute( [] 83 | { 84 | std::cout << "The current processor identifier is " << bsp_pid() << std::endl; 85 | }, nProcs ); 86 | 87 | // prints: "The current processor identifier is 0" 88 | BSPLib::Execute( [] 89 | { 90 | std::cout << "The current processor identifier is " << bsp_pid() << std::endl; 91 | }, 1 ); 92 | } 93 | ``` -------------------------------------------------------------------------------- /docs/util/time.md: -------------------------------------------------------------------------------- 1 | #Interfaces 2 | 3 | ```cpp 4 | double BSPLib::Time() // (1) Modern 5 | double BSPLib::Classic::Time() // (2) Classic 6 | double bsp_time() // (3) BSP 7 | ``` 8 | Gets the time in seconds since for this thread since starting calculations by 9 | calling [`BSPLib::Classic::Begin()`](../logic/begin.md). This function internally 10 | uses a high precion time, however a good resolution is not guaranteed and may vary 11 | between platforms and compilers. The timings are thread specific, and 12 | may vary, due to startup times. 13 | 14 | 1. This is interface one should choose to use, and is semantically the same as the other interfaces. 15 | 2. Classic BSP function, this is the interface one should prefer to use over the old BSP interface. 16 | 3. Legacy BSP function, this interface is included for backwards compatibility with other BSP libraries. 17 | 18 | #Return Value 19 | 20 | The the time in seconds for this processor since the beginning of computation. 21 | 22 | #Examples 23 | 24 | ###(1) Modern 25 | 26 | ```cpp 27 | void main( int32_t, const char ** ) 28 | { 29 | const uint32_t nProcs = BSPLib::NProcs(); 30 | 31 | // prints: "The processes waited for `x` seconds", where `x` is greater 32 | // than 5 for each thread. 33 | BSPLib::Execute( [] 34 | { 35 | std::this_thread::sleep_for( std::chrono::milliseconds( 5000 ) ); 36 | std::cout << "The processes waited for " << BSPLib::Time() 37 | << " seconds" << std::endl; 38 | }, nProcs ); 39 | } 40 | ``` 41 | 42 | ###(2) Classic 43 | 44 | ```cpp 45 | void main( int32_t, const char ** ) 46 | { 47 | const uint32_t nProcs = BSPLib::NProcs(); 48 | 49 | // prints: "The processes waited for `x` seconds", where `x` is greater 50 | // than 5 for each thread. 51 | BSPLib::Execute( [] 52 | { 53 | std::this_thread::sleep_for( std::chrono::milliseconds( 5000 ) ); 54 | std::cout << "The processes waited for " << BSPLib::Classic::Time() 55 | << " seconds" << std::endl; 56 | }, nProcs ); 57 | } 58 | ``` 59 | 60 | ###(3) BSP 61 | 62 | ```cpp 63 | void main( int32_t, const char ** ) 64 | { 65 | 66 | const uint32_t nProcs = BSPLib::NProcs(); 67 | 68 | // prints: "The processes waited for `x` seconds", where `x` is greater 69 | // than 5 for each thread. 70 | BSPLib::Execute( [] 71 | { 72 | std::this_thread::sleep_for( std::chrono::milliseconds( 5000 ) ); 73 | std::cout << "The processes waited for " << bsp_sleep() 74 | << " seconds" << std::endl; 75 | }, nProcs ); 76 | } 77 | ``` -------------------------------------------------------------------------------- /edupack/Makefile: -------------------------------------------------------------------------------- 1 | CC= bspcc 2 | CFLAGS= -O3 -flibrary-level 2 -bspfifo 10000 -fcombine-puts -fcombine-puts-buffer 256K,128M,4K 3 | LFLAGS= -lm 4 | OBJIP= bspinprod.o bspedupack.o 5 | OBJBEN= bspbench.o bspedupack.o 6 | OBJLU= bsplu_test.o bsplu.o bspedupack.o 7 | OBJFFT= bspfft_test.o bspfft.o bspedupack.o 8 | OBJMV= bspmv_test.o bspmv.o bspedupack.o 9 | 10 | all: ip bench lu fft matvec 11 | 12 | ip: $(OBJIP) 13 | $(CC) $(CFLAGS) -o ip $(OBJIP) $(LFLAGS) 14 | 15 | bench: $(OBJBEN) 16 | $(CC) $(CFLAGS) -o bench $(OBJBEN) $(LFLAGS) 17 | 18 | lu: $(OBJLU) 19 | $(CC) $(CFLAGS) -o lu $(OBJLU) $(LFLAGS) 20 | 21 | fft: $(OBJFFT) 22 | $(CC) $(CFLAGS) -o fft $(OBJFFT) $(LFLAGS) 23 | 24 | matvec: $(OBJMV) 25 | $(CC) $(CFLAGS) -o matvec $(OBJMV) $(LFLAGS) 26 | 27 | bspinprod.o: bspinprod.c bspedupack.h 28 | $(CC) $(CFLAGS) -c bspinprod.c 29 | 30 | bspbench.o: bspbench.c bspedupack.h 31 | $(CC) $(CFLAGS) -c bspbench.c 32 | 33 | bsplu_test.o: bsplu_test.c bspedupack.h 34 | $(CC) $(CFLAGS) -c bsplu_test.c 35 | 36 | bsplu.o: bsplu.c bspedupack.h 37 | $(CC) $(CFLAGS) -c bsplu.c 38 | 39 | bspfft_test.o: bspfft_test.c bspedupack.h 40 | $(CC) $(CFLAGS) -c bspfft_test.c 41 | 42 | bspfft.o: bspfft.c bspedupack.h 43 | $(CC) $(CFLAGS) -c bspfft.c 44 | 45 | bspmv_test.o: bspmv_test.c bspedupack.h 46 | $(CC) $(CFLAGS) -c bspmv_test.c 47 | 48 | bspmv.o: bspmv.c bspedupack.h 49 | $(CC) $(CFLAGS) -c bspmv.c 50 | 51 | bspedupack.o: bspedupack.c bspedupack.h 52 | $(CC) $(CFLAGS) -c bspedupack.c 53 | 54 | clean: 55 | rm -f *.o ip bench lu fft matvec 56 | -------------------------------------------------------------------------------- /edupack/bspBenchModern.cpp: -------------------------------------------------------------------------------- 1 | #include "bench.h" 2 | 3 | #include "plot/plotting.h" 4 | 5 | template< typename tFunc > 6 | void BenchCommunication( const tFunc &measureCommunication, uint32_t P, Plot &plot ) 7 | { 8 | std::vector< double > t( MAXH + 1 ); 9 | double r, g, l, g0, l0; 10 | 11 | BSPLib::Execute( [ &t, &r, &g0, &l0, &g, &l, &measureCommunication ] 12 | { 13 | uint32_t p = BSPLib::NProcs(); 14 | uint32_t s = BSPLib::ProcId(); 15 | 16 | std::vector< double > Time( p ); 17 | std::vector< double > dest( 2 * MAXH + p ); 18 | BSPLib::PushContainer( Time ); 19 | BSPLib::PushContainer( dest ); 20 | 21 | BSPLib::Sync(); 22 | 23 | DetermineR( r, Time, s ); 24 | 25 | DetermineGL( r, t, dest, Time, p, s, measureCommunication ); 26 | 27 | if ( s == 0 ) 28 | { 29 | ReportResults( g0, l0, p, r, g, l, t ); 30 | } 31 | 32 | BSPLib::PopContainer( dest ); 33 | BSPLib::PopContainer( Time ); 34 | }, P ); 35 | 36 | LinePlot line( PVec( 0, MAXH, MAXH, [g, l, r]( double h ) 37 | { 38 | return ( g * h + l ) / r * 1000000; 39 | } ) ); 40 | 41 | plot.AddPlot( LinePlot( vec( vec( t.data(), t.size(), false ) / r * 1000000 ) ) ); 42 | plot.AddPlot( line ); 43 | } 44 | 45 | namespace BenchType 46 | { 47 | enum BenchType 48 | { 49 | BenchPut = 0x1, 50 | BenchGet = 0x2, 51 | BenchSend = 0x4 52 | }; 53 | } 54 | 55 | void BSPBenchModern( uint32_t P, BenchType::BenchType benchType ) 56 | { 57 | Plot plot; 58 | 59 | if ( benchType & BenchType::BenchPut ) 60 | { 61 | BenchCommunication( MeasurePut, P, plot ); 62 | } 63 | 64 | if ( benchType & BenchType::BenchGet ) 65 | { 66 | BenchCommunication( MeasureGet, P, plot ); 67 | } 68 | 69 | if ( benchType & BenchType::BenchSend ) 70 | { 71 | BenchCommunication( MeasureSend, P, plot ); 72 | } 73 | 74 | plot.SetTightLayout().Show(); 75 | } 76 | 77 | int main( int /*argc*/, char ** /*argv*/ ) 78 | { 79 | #ifdef _WIN32 80 | _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); 81 | _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE ); 82 | _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDERR ); 83 | //_crtBreakAlloc = 0; 84 | #endif 85 | printf( "How many processors do you want to use?\n" ); 86 | fflush( stdout ); 87 | 88 | uint32_t P; 89 | 90 | //scanf_s( "%d", &P ); 91 | P = 4; 92 | 93 | if ( P > bsp_nprocs() ) 94 | { 95 | printf( "Sorry, not enough processors available.\n" ); 96 | exit( 1 ); 97 | } 98 | 99 | BSPBenchModern( P, BenchType::BenchPut ); 100 | } -------------------------------------------------------------------------------- /edupack/bspedupack.cpp: -------------------------------------------------------------------------------- 1 | #include "bspedupack.h" 2 | 3 | /* These functions can be used to allocate and deallocate vectors and matrices. 4 | If not enough memory available, one processor halts them all. 5 | */ 6 | 7 | double *vecallocd( int n ) 8 | { 9 | /* This function allocates a vector of doubles of length n */ 10 | double *pd; 11 | 12 | if ( n == 0 ) 13 | { 14 | pd = NULL; 15 | } 16 | else 17 | { 18 | pd = ( double * )malloc( n * SZDBL ); 19 | 20 | if ( pd == NULL ) 21 | { 22 | bsp_abort( "vecallocd: not enough memory" ); 23 | } 24 | } 25 | 26 | return pd; 27 | 28 | } /* end vecallocd */ 29 | 30 | int *vecalloci( int n ) 31 | { 32 | /* This function allocates a vector of integers of length n */ 33 | int *pi; 34 | 35 | if ( n == 0 ) 36 | { 37 | pi = NULL; 38 | } 39 | else 40 | { 41 | pi = ( int * )malloc( n * SZINT ); 42 | 43 | if ( pi == NULL ) 44 | { 45 | bsp_abort( "vecalloci: not enough memory" ); 46 | } 47 | } 48 | 49 | return pi; 50 | 51 | } /* end vecalloci */ 52 | 53 | double **matallocd( int m, int n ) 54 | { 55 | /* This function allocates an m x n matrix of doubles */ 56 | int i; 57 | double *pd, **ppd; 58 | 59 | if ( m == 0 ) 60 | { 61 | ppd = NULL; 62 | } 63 | else 64 | { 65 | ppd = ( double ** )malloc( m * sizeof( double * ) ); 66 | 67 | if ( ppd == NULL ) 68 | { 69 | bsp_abort( "matallocd: not enough memory" ); 70 | } 71 | 72 | if ( n == 0 ) 73 | { 74 | for ( i = 0; i < m; i++ ) 75 | { 76 | ppd[i] = NULL; 77 | } 78 | } 79 | else 80 | { 81 | pd = ( double * )malloc( m * n * SZDBL ); 82 | 83 | if ( pd == NULL ) 84 | { 85 | bsp_abort( "matallocd: not enough memory" ); 86 | } 87 | 88 | ppd[0] = pd; 89 | 90 | for ( i = 1; i < m; i++ ) 91 | { 92 | ppd[i] = ppd[i - 1] + n; 93 | } 94 | } 95 | } 96 | 97 | return ppd; 98 | 99 | } /* end matallocd */ 100 | 101 | void vecfreed( double *pd ) 102 | { 103 | /* This function frees a vector of doubles */ 104 | 105 | if ( pd != NULL ) 106 | { 107 | free( pd ); 108 | } 109 | 110 | } /* end vecfreed */ 111 | 112 | void vecfreei( int *pi ) 113 | { 114 | /* This function frees a vector of integers */ 115 | 116 | if ( pi != NULL ) 117 | { 118 | free( pi ); 119 | } 120 | 121 | } /* end vecfreei */ 122 | 123 | void matfreed( double **ppd ) 124 | { 125 | /* This function frees a matrix of doubles */ 126 | 127 | if ( ppd != NULL ) 128 | { 129 | if ( ppd[0] != NULL ) 130 | { 131 | free( ppd[0] ); 132 | } 133 | 134 | free( ppd ); 135 | } 136 | 137 | } /* end matfreed */ 138 | -------------------------------------------------------------------------------- /edupack/bspedupack.h: -------------------------------------------------------------------------------- 1 | /* 2 | ########################################################################### 3 | ## BSPedupack Version 1.0 ## 4 | ## Copyright (C) 2004 Rob H. Bisseling ## 5 | ## ## 6 | ## BSPedupack is released under the GNU GENERAL PUBLIC LICENSE ## 7 | ## Version 2, June 1991 (given in the file LICENSE) ## 8 | ## ## 9 | ########################################################################### 10 | */ 11 | 12 | #pragma once 13 | #ifndef __BSPEDUPACK_H__ 14 | #define __BSPEDUPACK_H__ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #include "bsp/bsp.h" 21 | 22 | #define SZDBL (sizeof(double)) 23 | #define SZINT (sizeof(int)) 24 | //#define TRUE (1) 25 | //#define FALSE (0) 26 | //#define MAX(a,b) ((a)>(b) ? (a) : (b)) 27 | //#define MIN(a,b) ((a)<(b) ? (a) : (b)) 28 | 29 | double *vecallocd( int n ); 30 | int *vecalloci( int n ); 31 | double **matallocd( int m, int n ); 32 | void vecfreed( double *pd ); 33 | void vecfreei( int *pi ); 34 | void matfreed( double **ppd ); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /edupack/bspfft_test.cpp: -------------------------------------------------------------------------------- 1 | #include "bspedupack.h" 2 | 3 | /* This is a test program which uses bspfft to perform 4 | a Fast Fourier Transform and its inverse. 5 | 6 | The input vector is defined by x[j]=j+i, for 0 <= j < n. 7 | Here i= sqrt(-1). 8 | 9 | The output vector should equal the input vector, 10 | up to roundoff errors. Output is by triples (j, Re x[j], Im x[j]). 11 | Warning: don't rely on this test alone to check correctness. 12 | (After all, deleting the main loop will give similar results ;) 13 | 14 | */ 15 | 16 | #define NITERS 5 /* Perform NITERS forward and backward transforms. 17 | A large NITERS helps to obtain accurate timings. */ 18 | #define NPRINT 10 /* Print NPRINT values per processor */ 19 | #define MEGA 1000000.0 20 | 21 | uint32_t P; 22 | 23 | void bspfft_test() 24 | { 25 | void bspfft( double * x, int n, int p, int s, int sign, double * w0, 26 | double * w, double * tw, int * rho_np, int * rho_p ); 27 | void bspfft_init( int n, int p, int s, double * w0, 28 | double * w, double * tw, int * rho_np, int * rho_p ); 29 | int k1_init( int n, int p ); 30 | 31 | int p, s, n, q, np, k1, j, jglob, it, *rho_np, *rho_p; 32 | double time0, time1, time2, ffttime, nflops, 33 | max_error, error_re, error_im, error, 34 | *Error, *x, *w0, *w, *tw; 35 | 36 | bsp_begin( P ); 37 | p = bsp_nprocs(); 38 | s = bsp_pid(); 39 | 40 | bsp_push_reg( &n, SZINT ); 41 | Error = vecallocd( p ); 42 | bsp_push_reg( Error, p * SZDBL ); 43 | bsp_sync(); 44 | 45 | if ( s == 0 ) 46 | { 47 | printf( "Please enter length n: \n" ); 48 | 49 | #ifdef _WIN32 50 | scanf_s( "%d", &n ); 51 | #else 52 | scanf( "%d", &n ); 53 | #endif 54 | 55 | if ( n < 2 * p ) 56 | { 57 | bsp_abort( "Error in input: n < 2p" ); 58 | } 59 | 60 | for ( q = 1; q < p; q++ ) 61 | { 62 | bsp_put( q, &n, &n, 0, SZINT ); 63 | } 64 | } 65 | 66 | bsp_sync(); 67 | 68 | if ( s == 0 ) 69 | { 70 | printf( "FFT of vector of length %d using %d processors\n", n, p ); 71 | printf( "performing %d forward and %d backward transforms\n", 72 | NITERS, NITERS ); 73 | } 74 | 75 | /* Allocate, register, and initialize vectors */ 76 | np = n / p; 77 | x = vecallocd( 2 * np ); 78 | bsp_push_reg( x, 2 * np * SZDBL ); 79 | k1 = k1_init( n, p ); 80 | w0 = vecallocd( k1 ); 81 | w = vecallocd( np ); 82 | tw = vecallocd( 2 * np + p ); 83 | rho_np = vecalloci( np ); 84 | rho_p = vecalloci( p ); 85 | 86 | for ( j = 0; j < np; j++ ) 87 | { 88 | jglob = j * p + s; 89 | x[2 * j] = ( double )jglob; 90 | x[2 * j + 1] = 1.0; 91 | } 92 | 93 | bsp_sync(); 94 | time0 = bsp_time(); 95 | 96 | /* Initialize the weight and bit reversal tables */ 97 | for ( it = 0; it < NITERS; it++ ) 98 | { 99 | bspfft_init( n, p, s, w0, w, tw, rho_np, rho_p ); 100 | } 101 | 102 | bsp_sync(); 103 | time1 = bsp_time(); 104 | 105 | /* Perform the FFTs */ 106 | for ( it = 0; it < NITERS; it++ ) 107 | { 108 | bspfft( x, n, p, s, 1, w0, w, tw, rho_np, rho_p ); 109 | bspfft( x, n, p, s, -1, w0, w, tw, rho_np, rho_p ); 110 | } 111 | 112 | bsp_sync(); 113 | time2 = bsp_time(); 114 | 115 | /* Compute the accuracy */ 116 | max_error = 0.0; 117 | 118 | for ( j = 0; j < np; j++ ) 119 | { 120 | jglob = j * p + s; 121 | error_re = fabs( x[2 * j] - ( double )jglob ); 122 | error_im = fabs( x[2 * j + 1] - 1.0 ); 123 | error = sqrt( error_re * error_re + error_im * error_im ); 124 | 125 | if ( error > max_error ) 126 | { 127 | max_error = error; 128 | } 129 | } 130 | 131 | bsp_put( 0, &max_error, Error, s * SZDBL, SZDBL ); 132 | bsp_sync(); 133 | 134 | if ( s == 0 ) 135 | { 136 | max_error = 0.0; 137 | 138 | for ( q = 0; q < p; q++ ) 139 | { 140 | if ( Error[q] > max_error ) 141 | { 142 | max_error = Error[q]; 143 | } 144 | } 145 | } 146 | 147 | for ( j = 0; j < NPRINT && j < np; j++ ) 148 | { 149 | jglob = j * p + s; 150 | printf( "proc=%d j=%d Re= %f Im= %f \n", s, jglob, x[2 * j], x[2 * j + 1] ); 151 | } 152 | 153 | fflush( stdout ); 154 | bsp_sync(); 155 | 156 | if ( s == 0 ) 157 | { 158 | printf( "Time per initialization = %lf sec \n", 159 | ( time1 - time0 ) / NITERS ); 160 | ffttime = ( time2 - time1 ) / ( 2.0 * NITERS ); 161 | printf( "Time per FFT = %lf sec \n", ffttime ); 162 | nflops = 5 * n * log( ( double )n ) / log( 2.0 ) + 2 * n; 163 | printf( "Computing rate in FFT = %lf Mflop/s \n", 164 | nflops / ( MEGA * ffttime ) ); 165 | printf( "Absolute error= %e \n", max_error ); 166 | printf( "Relative error= %e \n\n", max_error / n ); 167 | } 168 | 169 | 170 | bsp_pop_reg( x ); 171 | bsp_pop_reg( Error ); 172 | bsp_pop_reg( &n ); 173 | bsp_sync(); 174 | 175 | vecfreei( rho_p ); 176 | vecfreei( rho_np ); 177 | vecfreed( tw ); 178 | vecfreed( w ); 179 | vecfreed( w0 ); 180 | vecfreed( x ); 181 | vecfreed( Error ); 182 | bsp_end(); 183 | 184 | } /* end bspfft_test */ 185 | 186 | int main( int argc, char **argv ) 187 | { 188 | bsp_init( bspfft_test, argc, argv ); 189 | 190 | printf( "How many processors do you want to use?\n" ); 191 | fflush( stdout ); 192 | 193 | #ifdef _WIN32 194 | scanf_s( "%d", &P ); 195 | #else 196 | scanf( "%d", &P ); 197 | #endif 198 | 199 | if ( P > bsp_nprocs() ) 200 | { 201 | printf( "Sorry, not enough processors available.\n" ); 202 | fflush( stdout ); 203 | exit( 1 ); 204 | } 205 | 206 | bspfft_test(); 207 | 208 | exit( 0 ); 209 | 210 | } /* end main */ 211 | -------------------------------------------------------------------------------- /edupack/bspinprod.cpp: -------------------------------------------------------------------------------- 1 | #include "bspedupack.h" 2 | 3 | /* This program computes the sum of the first n squares, for n>=0, 4 | sum = 1*1 + 2*2 + ... + n*n 5 | by computing the inner product of x=(1,2,...,n)^T and itself. 6 | The output should equal n*(n+1)*(2n+1)/6. 7 | The distribution of x is cyclic. 8 | */ 9 | 10 | uint32_t P; /* number of processors requested */ 11 | 12 | int nloc( int p, int s, int n ) 13 | { 14 | /* Compute number of local components of processor s for vector 15 | of length n distributed cyclically over p processors. */ 16 | 17 | return ( n + p - s - 1 ) / p ; 18 | 19 | } /* end nloc */ 20 | 21 | double bspip( int p, int s, int n, double *x, double *y ) 22 | { 23 | /* Compute inner product of vectors x and y of length n>=0 */ 24 | 25 | int nloc( int p, int s, int n ); 26 | double inprod, *Inprod, alpha; 27 | int i, t; 28 | 29 | Inprod = vecallocd( p ); 30 | bsp_push_reg( Inprod, p * SZDBL ); 31 | bsp_sync(); 32 | 33 | inprod = 0.0; 34 | 35 | for ( i = 0; i < nloc( p, s, n ); i++ ) 36 | { 37 | inprod += x[i] * y[i]; 38 | } 39 | 40 | for ( t = 0; t < p; t++ ) 41 | { 42 | bsp_put( t, &inprod, Inprod, s * SZDBL, SZDBL ); 43 | } 44 | 45 | bsp_sync(); 46 | 47 | alpha = 0.0; 48 | 49 | for ( t = 0; t < p; t++ ) 50 | { 51 | alpha += Inprod[t]; 52 | } 53 | 54 | bsp_pop_reg( Inprod ); 55 | vecfreed( Inprod ); 56 | 57 | return alpha; 58 | 59 | } /* end bspip */ 60 | 61 | void bspinprod() 62 | { 63 | 64 | double bspip( int p, int s, int n, double * x, double * y ); 65 | int nloc( int p, int s, int n ); 66 | double *x, alpha, time0, time1; 67 | int p, s, n, nl, i, iglob; 68 | 69 | bsp_begin( P ); 70 | p = bsp_nprocs(); /* p = number of processors obtained */ 71 | s = bsp_pid(); /* s = processor number */ 72 | 73 | if ( s == 0 ) 74 | { 75 | printf( "Please enter n:\n" ); 76 | fflush( stdout ); 77 | 78 | #ifdef _WIN32 79 | scanf_s( "%d", &n ); 80 | #else 81 | scanf( "%d", &n ); 82 | #endif 83 | 84 | if ( n < 0 ) 85 | { 86 | bsp_abort( "Error in input: n is negative" ); 87 | } 88 | } 89 | 90 | bsp_push_reg( &n, SZINT ); 91 | bsp_sync(); 92 | 93 | bsp_get( 0, &n, 0, &n, SZINT ); 94 | bsp_sync(); 95 | bsp_pop_reg( &n ); 96 | 97 | nl = nloc( p, s, n ); 98 | x = vecallocd( nl ); 99 | 100 | for ( i = 0; i < nl; i++ ) 101 | { 102 | iglob = i * p + s; 103 | x[i] = iglob + 1; 104 | } 105 | 106 | bsp_sync(); 107 | time0 = bsp_time(); 108 | 109 | alpha = bspip( p, s, n, x, x ); 110 | bsp_sync(); 111 | time1 = bsp_time(); 112 | 113 | printf( "Processor %d: sum of squares up to %d*%d is %.lf\n", 114 | s, n, n, alpha ); 115 | fflush( stdout ); 116 | 117 | if ( s == 0 ) 118 | { 119 | printf( "This took only %.6lf seconds.\n", time1 - time0 ); 120 | fflush( stdout ); 121 | } 122 | 123 | vecfreed( x ); 124 | bsp_end(); 125 | 126 | } /* end bspinprod */ 127 | 128 | int main( int argc, char **argv ) 129 | { 130 | 131 | bsp_init( bspinprod, argc, argv ); 132 | 133 | /* sequential part */ 134 | printf( "How many processors do you want to use?\n" ); 135 | fflush( stdout ); 136 | 137 | #ifdef _WIN32 138 | scanf_s( "%d", &P ); 139 | #else 140 | scanf( "%d", &P ); 141 | #endif 142 | 143 | if ( P > bsp_nprocs() ) 144 | { 145 | printf( "Sorry, not enough processors available.\n" ); 146 | fflush( stdout ); 147 | exit( 1 ); 148 | } 149 | 150 | /* SPMD part */ 151 | bspinprod(); 152 | 153 | /* sequential part */ 154 | exit( 0 ); 155 | 156 | } /* end main */ 157 | -------------------------------------------------------------------------------- /edupack/bsplu_test.cpp: -------------------------------------------------------------------------------- 1 | #include "bspedupack.h" 2 | 3 | /* This is a test program which uses bsplu to decompose an n by n 4 | matrix A into triangular factors L and U, with partial row pivoting. 5 | The decomposition is A(pi(i),j)=(LU)(i,j), for 0 <= i,j < n, 6 | where pi is a permutation. 7 | 8 | The input matrix A is a row-rotated version of a matrix B: 9 | the matrix B is defined by: B(i,j)= 0.5*i+1 if i<=j 10 | 0.5*j+0.5 i>j, 11 | the matrix A is defined by: A(i,j)= B((i-1) mod n, j). 12 | 13 | This should give as output: 14 | the matrix L given by: L(i,j)= 0 if ij. 17 | the matrix U given by: U(i,j)= 1 if i<=j, 18 | = 0 i>j. 19 | the permutation pi given by: pi(i)= (i+1) mod n. 20 | 21 | Output of L and U is in triples (i,j,L\U(i,j)): 22 | (i,j,0.5) for i>j 23 | (i,j,1) for i<=j 24 | Output of pi is in pairs (i,pi(i)) 25 | (i,(i+1) mod n) for all i. 26 | 27 | The matrix A is constructed such that the pivot choice is unique. 28 | In stage k of the LU decomposition, row k is swapped with row r=k+1. 29 | For the M by N cyclic distribution this forces a row swap 30 | between processor rows. 31 | */ 32 | 33 | uint32_t M, N; 34 | 35 | void bsplu_test() 36 | { 37 | int nloc( int p, int s, int n ); 38 | void bsplu( int M, int N, int s, int t, int n, int *pi, double **a ); 39 | int p, pid, q, s, t, n, nlr, nlc, i, j, iglob, jglob, *pi; 40 | double **a, time0, time1; 41 | 42 | bsp_begin( M * N ); 43 | BSPProf::PauseRecording(); 44 | p = bsp_nprocs(); /* p=M*N */ 45 | pid = bsp_pid(); 46 | 47 | bsp_push_reg( &M, SZINT ); 48 | bsp_push_reg( &N, SZINT ); 49 | bsp_push_reg( &n, SZINT ); 50 | bsp_sync(); 51 | 52 | if ( pid == 0 ) 53 | { 54 | printf( "Please enter matrix size n:\n" ); 55 | 56 | #ifdef _WIN32 57 | scanf_s( "%d", &n ); 58 | #else 59 | scanf( "%d", &n ); 60 | #endif 61 | 62 | for ( q = 0; q < p; q++ ) 63 | { 64 | bsp_put( q, &M, &M, 0, SZINT ); 65 | bsp_put( q, &N, &N, 0, SZINT ); 66 | bsp_put( q, &n, &n, 0, SZINT ); 67 | } 68 | } 69 | 70 | bsp_sync(); 71 | bsp_pop_reg( &n ); /* not needed anymore */ 72 | bsp_pop_reg( &N ); 73 | bsp_pop_reg( &M ); 74 | 75 | /* Compute 2D processor numbering from 1D numbering */ 76 | s = pid % M; /* 0 <= s < M */ 77 | t = pid / M; /* 0 <= t < N */ 78 | 79 | /* Allocate and initialize matrix */ 80 | nlr = nloc( M, s, n ); /* number of local rows */ 81 | nlc = nloc( N, t, n ); /* number of local columns */ 82 | a = matallocd( nlr, nlc ); 83 | pi = vecalloci( nlr ); 84 | 85 | if ( s == 0 && t == 0 ) 86 | { 87 | printf( "LU decomposition of %d by %d matrix\n", n, n ); 88 | printf( "using the %d by %d cyclic distribution\n", M, N ); 89 | } 90 | 91 | for ( i = 0; i < nlr; i++ ) 92 | { 93 | iglob = i * M + s; /* Global row index in A */ 94 | iglob = ( iglob - 1 + n ) % n; /* Global row index in B */ 95 | 96 | for ( j = 0; j < nlc; j++ ) 97 | { 98 | jglob = j * N + t; /* Global column index in A and B */ 99 | a[i][j] = ( iglob <= jglob ? 0.5 * iglob + 1 : 0.5 * ( jglob + 1 ) ); 100 | } 101 | } 102 | 103 | if ( s == 0 && t == 0 ) 104 | { 105 | printf( "Start of LU decomposition\n" ); 106 | } 107 | 108 | bsp_sync(); 109 | time0 = bsp_time(); 110 | 111 | bsplu( M, N, s, t, n, pi, a ); 112 | bsp_sync(); 113 | time1 = bsp_time(); 114 | 115 | if ( s == 0 && t == 0 ) 116 | { 117 | printf( "End of LU decomposition\n" ); 118 | printf( "This took only %.6lf seconds.\n", time1 - time0 ); 119 | printf( "\nThe output permutation is:\n" ); 120 | fflush( stdout ); 121 | } 122 | 123 | if ( t == 0 ) 124 | { 125 | for ( i = 0; i < nlr; i++ ) 126 | { 127 | iglob = i * M + s; 128 | printf( "i=%d, pi=%d, proc=(%d,%d)\n", iglob, pi[i], s, t ); 129 | } 130 | 131 | fflush( stdout ); 132 | } 133 | 134 | bsp_sync(); 135 | 136 | if ( s == 0 && t == 0 ) 137 | { 138 | printf( "\nThe output matrix is:\n" ); 139 | fflush( stdout ); 140 | } 141 | 142 | for ( i = 0; i < nlr; i++ ) 143 | { 144 | iglob = i * M + s; 145 | 146 | for ( j = 0; j < nlc; j++ ) 147 | { 148 | jglob = j * N + t; 149 | printf( "i=%d, j=%d, a=%f, proc=(%d,%d)\n", 150 | iglob, jglob, a[i][j], s, t ); 151 | } 152 | } 153 | 154 | vecfreei( pi ); 155 | matfreed( a ); 156 | 157 | bsp_end(); 158 | } 159 | 160 | int main( int argc, char **argv ) 161 | { 162 | 163 | bsp_init( bsplu_test, argc, argv ); 164 | 165 | printf( "Please enter number of processor rows M:\n" ); 166 | 167 | #ifdef _WIN32 168 | scanf_s( "%d", &M ); 169 | #else 170 | scanf( "%d", &M ); 171 | #endif 172 | 173 | printf( "Please enter number of processor columns N:\n" ); 174 | 175 | #ifdef _WIN32 176 | scanf_s( "%d", &N ); 177 | #else 178 | scanf( "%d", &N ); 179 | #endif 180 | 181 | if ( M * N > bsp_nprocs() ) 182 | { 183 | printf( "Sorry, not enough processors available.\n" ); 184 | fflush( stdout ); 185 | exit( 1 ); 186 | } 187 | 188 | bsplu_test(); 189 | exit( 0 ); 190 | 191 | } /* end main */ 192 | 193 | -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: Zefiros-BSPLib 2 | site_url: http://www.bsplib.eu 3 | repo_url: https://github.com/Zefiros-Software/BSPLib 4 | site_description: BSPLib a fast and easy to use parallel computation libary. 5 | theme: united 6 | copyright: Copyright © 2017 Zefiros Software 7 | google_analytics: ['UA-29999374-2', 'www.bsplib.eu'] 8 | theme: 9 | name: null 10 | custom_dir: 'docs/style' 11 | pages: 12 | - BSP: 13 | - 'index.md' 14 | 15 | - Classic: 'classic.md' 16 | 17 | - Program: 18 | - Logic: 19 | - 'Execute BSP Kernel': 'logic/execute.md' 20 | - 'Init BSP Kernel': 'logic/init.md' 21 | - 'Begin BSP Kernel': 'logic/begin.md' 22 | - 'End BSP Kernel': 'logic/end.md' 23 | 24 | - Halting: 25 | - 'Abort Program': 'halting/abort.md' 26 | 27 | - Util: 28 | - 'Processor Count': 'util/nprocs.md' 29 | - 'Processor Identifier': 'util/procid.md' 30 | - 'Wall Time': 'util/time.md' 31 | 32 | - (De)registration: 33 | - 'Push Register': 'regdereg/push.md' 34 | - 'Pop Register': 'regdereg/pop.md' 35 | 36 | - Communication: 37 | - 'Get Register': 38 | - 'Normal': 'com/get.md' 39 | - 'Primitives' : 'com/getPrimitive.md' 40 | - 'Pointers' : 'com/getPtrs.md' 41 | - 'Containers' : 'com/getContainer.md' 42 | 43 | - 'Put Register': 44 | - 'Normal': 'com/put.md' 45 | - 'Primitives' : 'com/putPrimitive.md' 46 | - 'Pointers' : 'com/putPtrs.md' 47 | - 'Containers' : 'com/putContainer.md' 48 | 49 | - Sync Point: 50 | - 'Synchronising': 'sync/sync.md' 51 | 52 | - Messaging: 53 | 54 | - Send Memory: 55 | - 'Normal': 'messaging/send.md' 56 | - 'Primitives' : 'messaging/sendPrimitive.md' 57 | - 'Iterators' : 'messaging/sendIterator.md' 58 | - 'Containers' : 'messaging/sendContainer.md' 59 | - 'Pointers - Primitives' : 'messaging/sendPtrs.md' 60 | - 'Pointers - Containers' : 'messaging/sendTagContainer.md' 61 | - 'Move Memory': 'messaging/move.md' 62 | - 'Get Queue Size': 'messaging/qsize.md' 63 | 64 | - Utilities: 65 | - 'Get Tag': 'messagingutil/gettag.md' 66 | - 'Set Tag Size': 'messagingutil/settagsize.md' 67 | 68 | #- High Performance: 69 | # - 'Get Register': 'hp/hpget.md' 70 | # - 'Put Register': 'hp/hpput.md' 71 | # - 'Send Memory': 'hp/hpsend.md' 72 | # - 'Move Memory': 'hp/hpmove.md' 73 | 74 | 75 | extra_css: 76 | - 'style/docs.css' 77 | 78 | extra_javascript: 79 | - 'style/mathjax-loader.js' 80 | 81 | markdown_extensions: 82 | - toc: 83 | permalink: True 84 | separator: "_" 85 | - admonition 86 | - sane_lists 87 | - pymdownx.arithmatex 88 | - pymdownx.magiclink 89 | - markdown_checklist.extension -------------------------------------------------------------------------------- /test/.package.yml: -------------------------------------------------------------------------------- 1 | modules: 2 | - name: Zefiros-Software/Defaults 3 | version: '@head' 4 | libraries: 5 | - name: Zefiros-Software/BSPLib 6 | repository: ../ 7 | -------------------------------------------------------------------------------- /test/bsp.licenseheader: -------------------------------------------------------------------------------- 1 | extensions: .h .cpp .cc .hpp 2 | /** 3 | * @cond ___LICENSE___ 4 | * 5 | * Copyright (c) %CurrentYear% Zefiros Software. 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * @endcond 26 | * 27 | */ 28 | -------------------------------------------------------------------------------- /test/helper.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @cond ___LICENSE___ 3 | * 4 | * Copyright (c) 2016-2018 Zefiros Software. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * @endcond 25 | */ 26 | #pragma once 27 | #ifndef __HELPER_H__ 28 | #define __HELPER_H__ 29 | 30 | #define BSP_SUPPRESS_ABORT_WARNING 31 | 32 | #include "bsp/bsp.h" 33 | 34 | #include "gtest/gtest.h" 35 | 36 | #define CONCATEXT( a, b ) a##b 37 | #define CONCAT( a, b ) CONCATEXT( a, b ) 38 | #define P( prefix ) CONCAT( PREFIX, prefix ) 39 | 40 | 41 | 42 | #define BspTest( suite, nProc, func ) \ 43 | TEST( P( suite ), func ## _ ## nProc ) \ 44 | { \ 45 | BSPLib::Execute( func, nProc ); \ 46 | } 47 | 48 | #define BspTest1( suite, nProc, func, a ) \ 49 | TEST( P( suite ), func ## _ ## nProc ## _ ## a ) \ 50 | { \ 51 | BSPLib::Execute( func< a >, nProc ); \ 52 | } 53 | 54 | #define BspTest2( suite, nProc, func, a, b ) \ 55 | TEST( P( suite ), func ## _ ## nProc ## _ ## a ## _ ## b ) \ 56 | { \ 57 | BSPLib::Execute( func< a, b >, nProc ); \ 58 | } 59 | 60 | #define BspTest3( suite, nProc, func, a, b, c ) \ 61 | TEST( P( suite ), func ## _ ## nProc ## _ ## a ## _ ## b ## _ ## c ) \ 62 | { \ 63 | BSPLib::Execute( func< a, b, c >, nProc ); \ 64 | } 65 | 66 | #define BspTest4( suite, nProc, func, a, b, c, d ) \ 67 | TEST( P( suite ), func ## _ ## nProc ## _ ## a ## _ ## b ## _ ## c ## _ ## d ) \ 68 | { \ 69 | BSPLib::Execute( func< a, b, c, d >, nProc ); \ 70 | } 71 | 72 | #define BspTest5( suite, nProc, func, a, b, c, d, e ) \ 73 | TEST( P( suite ), func ## _ ## nProc ## _ ## a ## _ ## b ## _ ## c ## _ ## d ## _ ## e ) \ 74 | { \ 75 | BSPLib::Execute( func< a, b, c, d, e >, nProc ); \ 76 | } 77 | 78 | #endif -------------------------------------------------------------------------------- /test/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @cond ___LICENSE___ 3 | * 4 | * Copyright (c) 2016-2018 Zefiros Software. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * @endcond 25 | */ 26 | #define BSP_THROW 27 | #define BSP_SUPPRESS_ABORT_WARNING 28 | #include "bsp/bsp.h" 29 | 30 | #include "gtest/gtest.h" 31 | 32 | #include "testClassic.h" 33 | #include "testPrimitive.h" 34 | 35 | int32_t main(int32_t argc, char **argv) 36 | { 37 | testing::InitGoogleTest(&argc, argv); 38 | 39 | int32_t result = RUN_ALL_TESTS(); 40 | 41 | return result; 42 | } -------------------------------------------------------------------------------- /test/zpm.lua: -------------------------------------------------------------------------------- 1 | -- [[ 2 | -- @cond ___LICENSE___ 3 | -- 4 | -- Copyright (c) 2016-2018 Zefiros Software. 5 | -- 6 | -- Permission is hereby granted, free of charge, to any person obtaining a copy 7 | -- of this software and associated documentation files (the "Software"), to deal 8 | -- in the Software without restriction, including without limitation the rights 9 | -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | -- copies of the Software, and to permit persons to whom the Software is 11 | -- furnished to do so, subject to the following conditions: 12 | -- 13 | -- The above copyright notice and this permission notice shall be included in 14 | -- all copies or substantial portions of the Software. 15 | -- 16 | -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | -- THE SOFTWARE. 23 | -- 24 | -- @endcond 25 | -- ]] 26 | 27 | workspace "BSPLib-ZPM" 28 | 29 | zefiros.setTestZPMDefaults( "bsp", { 30 | mayLink = false 31 | } ) 32 | 33 | project "bsp-zpm-test" 34 | 35 | zpm.uses "Zefiros-Software/BSPLib" -------------------------------------------------------------------------------- /zpm.lock: -------------------------------------------------------------------------------- 1 | { 2 | "definition": "./", 3 | "optionals": [], 4 | "private": { 5 | "assets": [ { 6 | "definition": "https://github.com/Zefiros-Software/Zefiros-Mkdocs-Style.git", 7 | "hash": "4d543a49f499199210d5beff785e008c71ce4f36", 8 | "name": "Zefiros-Software/Zefiros-Mkdocs-Style", 9 | "repository": "https://github.com/Zefiros-Software/Zefiros-Mkdocs-Style.git", 10 | "tag": "1.0.2", 11 | "version": "1.0.2", 12 | "versionRequirement": "^1.0.0" 13 | } ], 14 | "modules": [ { 15 | "definition": "https://github.com/Zefiros-Software/ZefirosDefaults.git", 16 | "hash": "9ec8e43e7ca1d9eab61e4514a8741234c2b8232f", 17 | "name": "Zefiros-Software/Defaults", 18 | "public": { 19 | "libraries": [ { 20 | "definition": "https://github.com/Zefiros-Software/GoogleTest.git", 21 | "hash": "9557d29b7a5f3476ce024ae54410c997b9088f4a", 22 | "name": "Zefiros-Software/GoogleTest", 23 | "repository": "https://github.com/google/googletest.git", 24 | "tag": "HEAD", 25 | "versionRequirement": "@head || ^1.0.0" 26 | }, { 27 | "definition": "https://github.com/Zefiros-Software/GoogleBenchmark.git", 28 | "hash": "56f52ee228783547f544d9ac4a533574b9010e3f", 29 | "name": "Zefiros-Software/GoogleBenchmark", 30 | "repository": "https://github.com/google/benchmark.git", 31 | "tag": "HEAD", 32 | "versionRequirement": "@head" 33 | } ] 34 | }, 35 | "repository": "https://github.com/Zefiros-Software/ZefirosDefaults.git", 36 | "tag": "HEAD", 37 | "versionRequirement": "@head" 38 | }, { 39 | "definition": "https://github.com/Zefiros-Software/Miniconda.git", 40 | "hash": "a72fd309fcdbd684a4f1bd9d4fd9e835562beea6", 41 | "name": "Zefiros-Software/Miniconda", 42 | "repository": "https://github.com/Zefiros-Software/Miniconda.git", 43 | "tag": "HEAD", 44 | "versionRequirement": "@head" 45 | } ] 46 | }, 47 | "public": { 48 | "libraries": [ { 49 | "definition": "https://github.com/Zefiros-Software/PlotLib.git", 50 | "hash": "d22076c5d5fccfab61f4b18099a8a504e14110dc", 51 | "name": "Zefiros-Software/PlotLib", 52 | "optionals": { 53 | "libraries": [ { 54 | "name": "Zefiros-Software/Armadillo", 55 | "versionRequirement": "^7.800.0" 56 | } ] 57 | }, 58 | "private": { 59 | "modules": [ { 60 | "definition": "https://github.com/Zefiros-Software/Miniconda.git", 61 | "hash": "a72fd309fcdbd684a4f1bd9d4fd9e835562beea6", 62 | "name": "Zefiros-Software/Miniconda", 63 | "repository": "https://github.com/Zefiros-Software/Miniconda.git", 64 | "tag": "HEAD", 65 | "versionRequirement": "@head" 66 | } ] 67 | }, 68 | "repository": "https://github.com/Zefiros-Software/PlotLib.git", 69 | "tag": "2.0.2", 70 | "version": "2.0.2", 71 | "versionRequirement": "^2.0.0" 72 | }, { 73 | "definition": "https://github.com/Zefiros-Software/ArmadilloBuild.git", 74 | "hash": "e80d8a1642ff06371db57d964cd02be9752fcee3", 75 | "name": "Zefiros-Software/Armadillo", 76 | "optionals": { 77 | "libraries": [ { 78 | "name": "Zefiros-Software/MKL", 79 | "versionRequirement": "@head" 80 | } ] 81 | }, 82 | "repository": "https://github.com/conradsnicta/armadillo-code.git", 83 | "tag": "8.300.x", 84 | "versionRequirement": "^8.300.0" 85 | } ] 86 | }, 87 | "repository": "./" 88 | } -------------------------------------------------------------------------------- /zpm.lua: -------------------------------------------------------------------------------- 1 | 2 | -- [[ 3 | -- @cond ___LICENSE___ 4 | -- 5 | -- Copyright (c) 2016-2018 Zefiros Software. 6 | -- 7 | -- Permission is hereby granted, free of charge, to any person obtaining a copy 8 | -- of this software and associated documentation files (the "Software"), to deal 9 | -- in the Software without restriction, including without limitation the rights 10 | -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | -- copies of the Software, and to permit persons to whom the Software is 12 | -- furnished to do so, subject to the following conditions: 13 | -- 14 | -- The above copyright notice and this permission notice shall be included in 15 | -- all copies or substantial portions of the Software. 16 | -- 17 | -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | -- THE SOFTWARE. 24 | -- 25 | -- @endcond 26 | -- ]] 27 | 28 | workspace "BSPLib" 29 | 30 | cppdialect "C++11" 31 | 32 | zefiros.setDefaults( "bsp", { 33 | mayLink = false 34 | } ) 35 | 36 | 37 | workspace "BSPEdupack" 38 | 39 | configurations { "Debug", "Release" } 40 | platforms { "x86_64", "x86" } 41 | 42 | cppdialect "C++11" 43 | 44 | startproject "bench-modern" 45 | location "edupack" 46 | objdir "bin/obj/" 47 | 48 | defines "M_PI=3.14159265358979323846" 49 | 50 | vectorextensions "SSE2" 51 | warnings "Extra" 52 | 53 | filter "platforms:x86" 54 | targetdir "bin/x86/" 55 | debugdir "bin/x86/" 56 | architecture "x86" 57 | 58 | filter "platforms:x86_64" 59 | targetdir "bin/x86_64/" 60 | debugdir "bin/x86_64/" 61 | architecture "x86_64" 62 | 63 | filter "*Debug" 64 | targetsuffix "d" 65 | symbols "On" 66 | defines "DEBUG" 67 | optimize "Off" 68 | 69 | filter "*Release" 70 | flags "LinkTimeOptimization" 71 | optimize "Speed" 72 | 73 | filter {} 74 | 75 | project "bench" 76 | kind "ConsoleApp" 77 | 78 | includedirs "bsp/include" 79 | 80 | files { 81 | "edupack/bspedupack.h", 82 | "edupack/config.h", 83 | "edupack/bspedupack.cpp", 84 | "edupack/bspbench.cpp", 85 | } 86 | 87 | project "bench-modern" 88 | kind "ConsoleApp" 89 | 90 | zpm.uses "Zefiros-Software/PlotLib" 91 | 92 | includedirs "bsp/include" 93 | 94 | files { 95 | "edupack/bspedupack.h", 96 | "edupack/config.h", 97 | "edupack/bspedupack.cpp", 98 | "edupack/bspBenchModern.cpp", 99 | "edupack/bench.h" 100 | } 101 | 102 | project "fft" 103 | kind "ConsoleApp" 104 | 105 | includedirs "bsp/include" 106 | 107 | files { 108 | "edupack/bspedupack.h", 109 | "edupack/bspedupack.cpp", 110 | "edupack/bspfft.cpp", 111 | "edupack/bspfft_test.cpp", 112 | } 113 | 114 | project "fft-modern" 115 | kind "ConsoleApp" 116 | 117 | defines "BSP_USE_PROFILER" 118 | zpm.uses "Zefiros-Software/PlotLib" 119 | 120 | includedirs "bsp/include" 121 | 122 | files { 123 | "edupack/bspedupack.h", 124 | "edupack/bspedupack.cpp", 125 | "edupack/modernFft.h", 126 | "edupack/modernFftTest.cpp", 127 | } 128 | 129 | project "lu" 130 | kind "ConsoleApp" 131 | 132 | defines "BSP_USE_PROFILER" 133 | 134 | includedirs "bsp/include" 135 | zpm.uses "Zefiros-Software/PlotLib" 136 | 137 | files { 138 | "edupack/bspedupack.h", 139 | "edupack/bspedupack.cpp", 140 | "edupack/bsplu.cpp", 141 | "edupack/bsplu_test.cpp", 142 | } 143 | 144 | project "ip" 145 | kind "ConsoleApp" 146 | 147 | includedirs "bsp/include" 148 | 149 | files { 150 | "edupack/bspedupack.h", 151 | "edupack/bspedupack.cpp", 152 | "edupack/bspinprod.cpp", 153 | } 154 | 155 | project "matvec" 156 | kind "ConsoleApp" 157 | 158 | includedirs "bsp/include" 159 | 160 | files { 161 | "edupack/bspedupack.h", 162 | "edupack/bspedupack.cpp", 163 | "edupack/bspmv.cpp", 164 | "edupack/bspmv_test.cpp", 165 | } --------------------------------------------------------------------------------