diff options
author | Stanislav Kirillov <staskirillov@gmail.com> | 2022-02-10 16:46:07 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:07 +0300 |
commit | 92fe2b1e7bc79f7b95adef61714fc003f6ea4a1c (patch) | |
tree | 817034f4ca57c9f841bb047ec94630c2e78a2b1d /library/cpp | |
parent | 53c76da6d9f6cc5a17f6029df396f0e3bc1ff47d (diff) | |
download | ydb-92fe2b1e7bc79f7b95adef61714fc003f6ea4a1c.tar.gz |
Restoring authorship annotation for Stanislav Kirillov <staskirillov@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'library/cpp')
-rw-r--r-- | library/cpp/containers/2d_array/2d_array.h | 32 | ||||
-rw-r--r-- | library/cpp/containers/2d_array/ya.make | 2 | ||||
-rw-r--r-- | library/cpp/dbg_output/dumpers.h | 8 | ||||
-rw-r--r-- | library/cpp/getopt/small/modchooser.cpp | 18 | ||||
-rw-r--r-- | library/cpp/getopt/small/modchooser.h | 10 | ||||
-rw-r--r-- | library/cpp/lwtrace/mon/analytics/util.h | 2 | ||||
-rw-r--r-- | library/cpp/threading/local_executor/README.md | 86 | ||||
-rw-r--r-- | library/cpp/threading/local_executor/local_executor.cpp | 26 | ||||
-rw-r--r-- | library/cpp/threading/local_executor/local_executor.h | 28 | ||||
-rw-r--r-- | library/cpp/threading/local_executor/ya.make | 14 | ||||
-rw-r--r-- | library/cpp/threading/poor_man_openmp/thread_helper.h | 78 | ||||
-rw-r--r-- | library/cpp/unicode/normalization/ya.make | 14 | ||||
-rw-r--r-- | library/cpp/yson/node/node.h | 2 |
13 files changed, 160 insertions, 160 deletions
diff --git a/library/cpp/containers/2d_array/2d_array.h b/library/cpp/containers/2d_array/2d_array.h index 9e24650637..5ecd0fb84e 100644 --- a/library/cpp/containers/2d_array/2d_array.h +++ b/library/cpp/containers/2d_array/2d_array.h @@ -7,12 +7,12 @@ template <class T> struct TBoundCheck { T* Data; - size_t Size; - TBoundCheck(T* d, size_t s) { + size_t Size; + TBoundCheck(T* d, size_t s) { Data = d; Size = s; } - T& operator[](size_t i) const { + T& operator[](size_t i) const { Y_ASSERT(i >= 0 && i < Size); return Data[i]; } @@ -25,15 +25,15 @@ private: typedef T* PT; T* Data; T** PData; - size_t XSize; - size_t YSize; + size_t XSize; + size_t YSize; private: void Copy(const TArray2D& a) { XSize = a.XSize; YSize = a.YSize; Create(); - for (size_t i = 0; i < XSize * YSize; i++) + for (size_t i = 0; i < XSize * YSize; i++) Data[i] = a.Data[i]; } void Destroy() { @@ -43,12 +43,12 @@ private: void Create() { Data = new T[XSize * YSize]; PData = new PT[YSize]; - for (size_t i = 0; i < YSize; i++) + for (size_t i = 0; i < YSize; i++) PData[i] = Data + i * XSize; } public: - TArray2D(size_t xsize = 1, size_t ysize = 1) { + TArray2D(size_t xsize = 1, size_t ysize = 1) { XSize = xsize; YSize = ysize; Create(); @@ -64,7 +64,7 @@ public: ~TArray2D() { Destroy(); } - void SetSizes(size_t xsize, size_t ysize) { + void SetSizes(size_t xsize, size_t ysize) { if (XSize == xsize && YSize == ysize) return; Destroy(); @@ -76,27 +76,27 @@ public: SetSizes(1, 1); } #ifdef _DEBUG - TBoundCheck<T> operator[](size_t i) const { + TBoundCheck<T> operator[](size_t i) const { Y_ASSERT(i < YSize); return TBoundCheck<T>(PData[i], XSize); } #else - T* operator[](size_t i) const { + T* operator[](size_t i) const { Y_ASSERT(i < YSize); return PData[i]; } #endif - size_t GetXSize() const { + size_t GetXSize() const { return XSize; } - size_t GetYSize() const { + size_t GetYSize() const { return YSize; } void FillZero() { memset(Data, 0, sizeof(T) * XSize * YSize); } void FillEvery(const T& a) { - for (size_t i = 0; i < XSize * YSize; i++) + for (size_t i = 0; i < XSize * YSize; i++) Data[i] = a; } void Swap(TArray2D& a) { @@ -111,8 +111,8 @@ template <class T> inline bool operator==(const TArray2D<T>& a, const TArray2D<T>& b) { if (a.GetXSize() != b.GetXSize() || a.GetYSize() != b.GetYSize()) return false; - for (size_t y = 0; y < a.GetYSize(); ++y) { - for (size_t x = 0; x < a.GetXSize(); ++x) + for (size_t y = 0; y < a.GetYSize(); ++y) { + for (size_t x = 0; x < a.GetXSize(); ++x) if (a[y][x] != b[y][x]) return false; } diff --git a/library/cpp/containers/2d_array/ya.make b/library/cpp/containers/2d_array/ya.make index 71d56b902f..fe5e2f649b 100644 --- a/library/cpp/containers/2d_array/ya.make +++ b/library/cpp/containers/2d_array/ya.make @@ -1,7 +1,7 @@ LIBRARY() OWNER(kirillovs) - + SRCS( 2d_array.cpp ) diff --git a/library/cpp/dbg_output/dumpers.h b/library/cpp/dbg_output/dumpers.h index 4868e97da0..d5725108a2 100644 --- a/library/cpp/dbg_output/dumpers.h +++ b/library/cpp/dbg_output/dumpers.h @@ -98,10 +98,10 @@ template <class T, class A> struct TDumper<std::vector<T, A>>: public TSeqDumper { }; -template <class T> -struct TDumper<TArrayRef<T>>: public TSeqDumper { -}; - +template <class T> +struct TDumper<TArrayRef<T>>: public TSeqDumper { +}; + template <class T, size_t N> struct TDumper<std::array<T, N>>: public TSeqDumper { }; diff --git a/library/cpp/getopt/small/modchooser.cpp b/library/cpp/getopt/small/modchooser.cpp index 2fa5cfd070..ce8fc043a3 100644 --- a/library/cpp/getopt/small/modchooser.cpp +++ b/library/cpp/getopt/small/modchooser.cpp @@ -73,7 +73,7 @@ TModChooser::TModChooser() : ModesHelpOption("-?") // Default help option in last_getopt , VersionHandler(nullptr) , ShowSeparated(true) - , SvnRevisionOptionDisabled(false) + , SvnRevisionOptionDisabled(false) , PrintShortCommandInUsage(false) { } @@ -152,10 +152,10 @@ void TModChooser::SetPrintShortCommandInUsage(bool printShortCommandInUsage = fa PrintShortCommandInUsage = printShortCommandInUsage; } -void TModChooser::DisableSvnRevisionOption() { - SvnRevisionOptionDisabled = true; -} - +void TModChooser::DisableSvnRevisionOption() { + SvnRevisionOptionDisabled = true; +} + void TModChooser::AddCompletions(TString progName, const TString& name, bool hidden, bool noCompletion) { if (CompletionsGenerator == nullptr) { CompletionsGenerator = NLastGetopt::MakeCompletionMod(this, std::move(progName), name); @@ -188,7 +188,7 @@ int TModChooser::Run(const int argc, const char** argv) const { VersionHandler(); return 0; } - if (!SvnRevisionOptionDisabled && modeName == "--svnrevision") { + if (!SvnRevisionOptionDisabled && modeName == "--svnrevision") { NLastGetopt::PrintVersionAndExit(nullptr); } @@ -314,9 +314,9 @@ void TModChooser::PrintHelp(const TString& progName) const { Cerr << "To get help for specific mode type '" << progName << " MODE " << ModesHelpOption << "'" << Endl; if (VersionHandler) Cerr << "To print program version type '" << progName << " --version'" << Endl; - if (!SvnRevisionOptionDisabled) { - Cerr << "To print svn revision type --svnrevision" << Endl; - } + if (!SvnRevisionOptionDisabled) { + Cerr << "To print svn revision type --svnrevision" << Endl; + } return; } diff --git a/library/cpp/getopt/small/modchooser.h b/library/cpp/getopt/small/modchooser.h index 0a8de6d50b..54ccbb2e28 100644 --- a/library/cpp/getopt/small/modchooser.h +++ b/library/cpp/getopt/small/modchooser.h @@ -80,8 +80,8 @@ public: //! Set short command representation in Usage block void SetPrintShortCommandInUsage(bool printShortCommandInUsage); - void DisableSvnRevisionOption(); - + void DisableSvnRevisionOption(); + void AddCompletions(TString progName, const TString& name = "completion", bool hidden = false, bool noCompletion = false); /*! Run appropriate mode. @@ -155,9 +155,9 @@ private: //! When set to true, show descriptions unsorted and display separators bool ShowSeparated; - //! When set to true, disables --svnrevision option, useful for opensource (git hosted) projects - bool SvnRevisionOptionDisabled; - + //! When set to true, disables --svnrevision option, useful for opensource (git hosted) projects + bool SvnRevisionOptionDisabled; + //! When true - will print only 'mode name' in 'Usage' block bool PrintShortCommandInUsage; diff --git a/library/cpp/lwtrace/mon/analytics/util.h b/library/cpp/lwtrace/mon/analytics/util.h index e07d06cc43..4dda44f864 100644 --- a/library/cpp/lwtrace/mon/analytics/util.h +++ b/library/cpp/lwtrace/mon/analytics/util.h @@ -8,7 +8,7 @@ namespace NAnalytics { // Get rid of NaNs and INFs -inline double Finitize(double x, double notFiniteValue = 0.0) +inline double Finitize(double x, double notFiniteValue = 0.0) { return isfinite(x)? x: notFiniteValue; } diff --git a/library/cpp/threading/local_executor/README.md b/library/cpp/threading/local_executor/README.md index aaad2e2986..0fdd6f6173 100644 --- a/library/cpp/threading/local_executor/README.md +++ b/library/cpp/threading/local_executor/README.md @@ -1,23 +1,23 @@ -# Library for parallel task execution in thread pool - -This library allows easy parallelization of existing code and cycles. -It provides `NPar::TLocalExecutor` class and `NPar::LocalExecutor()` singleton accessor. +# Library for parallel task execution in thread pool + +This library allows easy parallelization of existing code and cycles. +It provides `NPar::TLocalExecutor` class and `NPar::LocalExecutor()` singleton accessor. At start, `TLocalExecutor` has no threads in thread pool and all async tasks will be queued for later execution when extra threads appear. -All tasks should be `NPar::ILocallyExecutable` child class or function equal to `std::function<void(int)>` - -## TLocalExecutor methods - -`TLocalExecutor::Run(int threadcount)` - add threads to thread pool (**WARNING!** `Run(threadcount)` will *add* `threadcount` threads to pool) - -`void TLocalExecutor::Exec(TLocallyExecutableFunction exec, int id, int flags)` - run one task and pass id as task function input, flags - bitmask composition of: - -- `TLocalExecutor::HIGH_PRIORITY = 0` - put task in high priority queue -- `TLocalExecutor::MED_PRIORITY = 1` - put task in medium priority queue -- `TLocalExecutor::LOW_PRIORITY = 2` - put task in low priority queue -- `TLocalExecutor::WAIT_COMPLETE = 4` - wait for task completion - +All tasks should be `NPar::ILocallyExecutable` child class or function equal to `std::function<void(int)>` + +## TLocalExecutor methods + +`TLocalExecutor::Run(int threadcount)` - add threads to thread pool (**WARNING!** `Run(threadcount)` will *add* `threadcount` threads to pool) + +`void TLocalExecutor::Exec(TLocallyExecutableFunction exec, int id, int flags)` - run one task and pass id as task function input, flags - bitmask composition of: + +- `TLocalExecutor::HIGH_PRIORITY = 0` - put task in high priority queue +- `TLocalExecutor::MED_PRIORITY = 1` - put task in medium priority queue +- `TLocalExecutor::LOW_PRIORITY = 2` - put task in low priority queue +- `TLocalExecutor::WAIT_COMPLETE = 4` - wait for task completion + `void TLocalExecutor::ExecRange(TLocallyExecutableFunction exec, TExecRangeParams blockParams, int flags);` - run range of tasks `[TExecRangeParams::FirstId, TExecRangeParams::LastId).` - + `flags` is the same as for `TLocalExecutor::Exec`. `TExecRangeParams` is a structure that describes the range. @@ -33,32 +33,32 @@ It is also possible to partition range of tasks in consequtive blocks and execut the range of tasks into consequtive blocks of approximately given size, or of size calculated by partitioning the range into approximately equal size blocks of given count. -## Examples - -### Simple task async exec with medium priority - -```cpp -using namespace NPar; - -LocalExecutor().Run(4); -TEvent event; -LocalExecutor().Exec([](int) { - SomeFunc(); - event.Signal(); -}, 0, TLocalExecutor::MED_PRIORITY); - -SomeOtherCode(); -event.WaitI(); -``` - -### Execute task range and wait completion - -```cpp -using namespace NPar; - -LocalExecutor().Run(4); +## Examples + +### Simple task async exec with medium priority + +```cpp +using namespace NPar; + +LocalExecutor().Run(4); +TEvent event; +LocalExecutor().Exec([](int) { + SomeFunc(); + event.Signal(); +}, 0, TLocalExecutor::MED_PRIORITY); + +SomeOtherCode(); +event.WaitI(); +``` + +### Execute task range and wait completion + +```cpp +using namespace NPar; + +LocalExecutor().Run(4); LocalExecutor().ExecRange([](int id) { - SomeFunc(id); + SomeFunc(id); }, TExecRangeParams(0, 10), TLocalExecutor::WAIT_COMPLETE | TLocalExecutor::MED_PRIORITY); ``` diff --git a/library/cpp/threading/local_executor/local_executor.cpp b/library/cpp/threading/local_executor/local_executor.cpp index 1d3fbb4bf4..d19b48d0b1 100644 --- a/library/cpp/threading/local_executor/local_executor.cpp +++ b/library/cpp/threading/local_executor/local_executor.cpp @@ -13,12 +13,12 @@ #include <utility> #ifdef _win_ -static void RegularYield() { +static void RegularYield() { } #else // unix actually has cooperative multitasking! :) // without this function program runs slower and system lags for some magic reason -static void RegularYield() { +static void RegularYield() { SchedYield(); } #endif @@ -28,12 +28,12 @@ namespace { NPar::TLocallyExecutableFunction Exec; TFunctionWrapper(NPar::TLocallyExecutableFunction exec) : Exec(std::move(exec)) - { - } - void LocalExec(int id) override { - Exec(id); - } - }; + { + } + void LocalExec(int id) override { + Exec(id); + } + }; class TFunctionWrapperWithPromise: public NPar::ILocallyExecutable { private: @@ -73,7 +73,7 @@ namespace { struct TSingleJob { TIntrusivePtr<NPar::ILocallyExecutable> Exec; int Id{0}; - + TSingleJob() = default; TSingleJob(TIntrusivePtr<NPar::ILocallyExecutable> exec, int id) : Exec(std::move(exec)) @@ -95,7 +95,7 @@ namespace { break; } AtomicAdd(WorkerCount, -1); - } + } public: TLocalRangeExecutor(TIntrusivePtr<ILocallyExecutable> exec, int firstId, int lastId) @@ -104,7 +104,7 @@ namespace { , WorkerCount(0) , LastId(lastId) { - } + } bool DoSingleOp() { const int id = AtomicAdd(Counter, 1) - 1; if (id >= LastId) @@ -112,14 +112,14 @@ namespace { Exec->LocalExec(id); RegularYield(); return true; - } + } void WaitComplete() { while (AtomicGet(WorkerCount) > 0) RegularYield(); } int GetRangeSize() const { return Max<int>(LastId - Counter, 0); - } + } }; } diff --git a/library/cpp/threading/local_executor/local_executor.h b/library/cpp/threading/local_executor/local_executor.h index c1c824f67c..e12536bd46 100644 --- a/library/cpp/threading/local_executor/local_executor.h +++ b/library/cpp/threading/local_executor/local_executor.h @@ -11,15 +11,15 @@ #include <functional> -namespace NPar { - struct ILocallyExecutable : virtual public TThrRefBase { +namespace NPar { + struct ILocallyExecutable : virtual public TThrRefBase { // Must be implemented by the end user to define job that will be processed by one of // executor threads. // // @param id Job parameter, typically an index pointing somewhere in array, or just // some dummy value, e.g. `0`. - virtual void LocalExec(int id) = 0; - }; + virtual void LocalExec(int id) = 0; + }; // Alternative and simpler way of describing a job for executor. Function argument has the // same meaning as `id` in `ILocallyExecutable::LocalExec`. @@ -27,17 +27,17 @@ namespace NPar { using TLocallyExecutableFunction = std::function<void(int)>; class ILocalExecutor: public TNonCopyable { - public: + public: ILocalExecutor() = default; virtual ~ILocalExecutor() = default; enum EFlags : int { - HIGH_PRIORITY = 0, - MED_PRIORITY = 1, - LOW_PRIORITY = 2, - PRIORITY_MASK = 3, - WAIT_COMPLETE = 4 - }; + HIGH_PRIORITY = 0, + MED_PRIORITY = 1, + LOW_PRIORITY = 2, + PRIORITY_MASK = 3, + WAIT_COMPLETE = 4 + }; // Add task for further execution. // @@ -156,7 +156,7 @@ namespace NPar { } ExecRange(BlockedLoopBody(params, body), 0, params.GetBlockCount(), flags); } - + template <typename TBody> inline void ExecRangeBlockedWithThrow(TBody&& body, int firstId, int lastId, int batchSizeOrZeroForAutoBatchSize, int flags) { if (firstId >= lastId) { @@ -270,8 +270,8 @@ namespace NPar { }; static inline TLocalExecutor& LocalExecutor() { - return *Singleton<TLocalExecutor>(); - } + return *Singleton<TLocalExecutor>(); + } template <typename TBody> inline void ParallelFor(ILocalExecutor& executor, ui32 from, ui32 to, TBody&& body) { diff --git a/library/cpp/threading/local_executor/ya.make b/library/cpp/threading/local_executor/ya.make index df210f92bb..e340556678 100644 --- a/library/cpp/threading/local_executor/ya.make +++ b/library/cpp/threading/local_executor/ya.make @@ -1,8 +1,8 @@ OWNER( - g:matrixnet + g:matrixnet gulin - kirillovs - espetrov + kirillovs + espetrov ) LIBRARY() @@ -12,9 +12,9 @@ SRCS( tbb_local_executor.cpp ) -PEERDIR( - contrib/libs/tbb +PEERDIR( + contrib/libs/tbb library/cpp/threading/future -) - +) + END() diff --git a/library/cpp/threading/poor_man_openmp/thread_helper.h b/library/cpp/threading/poor_man_openmp/thread_helper.h index 0ecee0590b..d51cda8daa 100644 --- a/library/cpp/threading/poor_man_openmp/thread_helper.h +++ b/library/cpp/threading/poor_man_openmp/thread_helper.h @@ -1,45 +1,45 @@ -#pragma once - +#pragma once + #include <util/thread/pool.h> -#include <util/generic/utility.h> +#include <util/generic/utility.h> #include <util/generic/yexception.h> -#include <util/system/info.h> -#include <util/system/atomic.h> -#include <util/system/condvar.h> -#include <util/system/mutex.h> +#include <util/system/info.h> +#include <util/system/atomic.h> +#include <util/system/condvar.h> +#include <util/system/mutex.h> #include <util/stream/output.h> - + #include <functional> #include <cstdlib> - + class TMtpQueueHelper { -public: +public: TMtpQueueHelper() { - SetThreadCount(NSystemInfo::CachedNumberOfCpus()); - } + SetThreadCount(NSystemInfo::CachedNumberOfCpus()); + } IThreadPool* Get() { - return q.Get(); - } - size_t GetThreadCount() { - return ThreadCount; - } - void SetThreadCount(size_t threads) { - ThreadCount = threads; + return q.Get(); + } + size_t GetThreadCount() { + return ThreadCount; + } + void SetThreadCount(size_t threads) { + ThreadCount = threads; q = CreateThreadPool(ThreadCount); - } + } static TMtpQueueHelper& Instance(); -private: - size_t ThreadCount; +private: + size_t ThreadCount; TAutoPtr<IThreadPool> q; -}; - +}; + namespace NYmp { - inline void SetThreadCount(size_t threads) { + inline void SetThreadCount(size_t threads) { TMtpQueueHelper::Instance().SetThreadCount(threads); - } - + } + inline size_t GetThreadCount() { return TMtpQueueHelper::Instance().GetThreadCount(); } @@ -50,9 +50,9 @@ namespace NYmp { size_t threadCount = TMtpQueueHelper::Instance().GetThreadCount(); IThreadPool* queue = TMtpQueueHelper::Instance().Get(); - TCondVar cv; - TMutex mutex; - TAtomic counter = threadCount; + TCondVar cv; + TMutex mutex; + TAtomic counter = threadCount; std::exception_ptr err; for (size_t i = 0; i < threadCount; ++i) { @@ -68,12 +68,12 @@ namespace NYmp { } currentChunkStart += chunkSize * threadCount; - } + } } catch (...) { with_lock (mutex) { err = std::current_exception(); } - } + } with_lock (mutex) { if (AtomicDecrement(counter) == 0) { @@ -81,25 +81,25 @@ namespace NYmp { cv.Signal(); } } - }); - } + }); + } with_lock (mutex) { while (AtomicGet(counter) > 0) { cv.WaitI(mutex); } - } + } if (err) { std::rethrow_exception(err); } - } - + } + template <typename T> inline void ParallelForStaticAutoChunk(T begin, T end, std::function<void(T)> func) { const size_t taskSize = end - begin; const size_t threadCount = TMtpQueueHelper::Instance().GetThreadCount(); - ParallelForStaticChunk(begin, end, (taskSize + threadCount - 1) / threadCount, func); - } + ParallelForStaticChunk(begin, end, (taskSize + threadCount - 1) / threadCount, func); + } } diff --git a/library/cpp/unicode/normalization/ya.make b/library/cpp/unicode/normalization/ya.make index 95bc93f297..beb604c636 100644 --- a/library/cpp/unicode/normalization/ya.make +++ b/library/cpp/unicode/normalization/ya.make @@ -11,14 +11,14 @@ SRCS( normalization.cpp ) -IF(NOT CATBOOST_OPENSOURCE) - SRCS( - custom_encoder.cpp - ) - PEERDIR( +IF(NOT CATBOOST_OPENSOURCE) + SRCS( + custom_encoder.cpp + ) + PEERDIR( library/cpp/charset - ) + ) GENERATE_ENUM_SERIALIZATION(normalization.h) -ENDIF() +ENDIF() END() diff --git a/library/cpp/yson/node/node.h b/library/cpp/yson/node/node.h index 5f90f95df0..f90818bd4c 100644 --- a/library/cpp/yson/node/node.h +++ b/library/cpp/yson/node/node.h @@ -360,7 +360,7 @@ inline TString TNode::ConvertTo<TString>() const { case NYT::TNode::Undefined: ythrow TTypeError() << "ConvertTo<TString>() called for type " << GetType(); } - Y_UNREACHABLE(); + Y_UNREACHABLE(); } template<> |