diff options
author | Stanislav Kirillov <staskirillov@gmail.com> | 2022-02-10 16:46:08 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:08 +0300 |
commit | cb68f224c46a8ee52ac3fdd2a32534b8bb8dc134 (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /library | |
parent | 92fe2b1e7bc79f7b95adef61714fc003f6ea4a1c (diff) | |
download | ydb-cb68f224c46a8ee52ac3fdd2a32534b8bb8dc134.tar.gz |
Restoring authorship annotation for Stanislav Kirillov <staskirillov@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'library')
-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 | ||||
-rw-r--r-- | library/python/runtime_py3/__res.pyx | 2 |
14 files changed, 161 insertions, 161 deletions
diff --git a/library/cpp/containers/2d_array/2d_array.h b/library/cpp/containers/2d_array/2d_array.h index 5ecd0fb84e..9e24650637 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 fe5e2f649b..71d56b902f 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 d5725108a2..4868e97da0 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 ce8fc043a3..2fa5cfd070 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 54ccbb2e28..0a8de6d50b 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 4dda44f864..e07d06cc43 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 0fdd6f6173..aaad2e2986 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 d19b48d0b1..1d3fbb4bf4 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 e12536bd46..c1c824f67c 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 e340556678..df210f92bb 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 d51cda8daa..0ecee0590b 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 beb604c636..95bc93f297 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 f90818bd4c..5f90f95df0 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<> diff --git a/library/python/runtime_py3/__res.pyx b/library/python/runtime_py3/__res.pyx index 37fab6f71a..97190d9f29 100644 --- a/library/python/runtime_py3/__res.pyx +++ b/library/python/runtime_py3/__res.pyx @@ -2,7 +2,7 @@ from _codecs import utf_8_decode, utf_8_encode from libcpp cimport bool -from util.generic.string cimport TString, TStringBuf +from util.generic.string cimport TString, TStringBuf cdef extern from "library/cpp/resource/resource.h" namespace "NResource": |