Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added parallel mode to utilise power of all CPUs #67

Merged
merged 21 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.4.4 (2021-03-10)

+ Added concurrent mode to utilize power of all CPUs

# 0.4.3 (2015-11-25)

+ Added support for Data URI #14.
Expand Down
16 changes: 6 additions & 10 deletions Leanify.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(ProjectDir)lib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DisableLanguageExtensions>false</DisableLanguageExtensions>
<LanguageStandard>stdcpp14</LanguageStandard>
<LanguageStandard>stdcpp17</LanguageStandard>
<PrecompiledHeaderFile />
</ClCompile>
<Link>
Expand All @@ -147,7 +147,7 @@
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(ProjectDir)lib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DisableLanguageExtensions>false</DisableLanguageExtensions>
<LanguageStandard>stdcpp14</LanguageStandard>
<LanguageStandard>stdcpp17</LanguageStandard>
<PrecompiledHeaderFile />
</ClCompile>
<Link>
Expand All @@ -171,7 +171,6 @@
<CompileAsManaged>false</CompileAsManaged>
<CompileAsWinRT>false</CompileAsWinRT>
<StringPooling>true</StringPooling>
<ExceptionHandling>false</ExceptionHandling>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<FloatingPointModel>Fast</FloatingPointModel>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
Expand All @@ -182,7 +181,7 @@
<DebugInformationFormat>None</DebugInformationFormat>
<OmitFramePointers>true</OmitFramePointers>
<DisableLanguageExtensions>false</DisableLanguageExtensions>
<LanguageStandard>stdcpp14</LanguageStandard>
<LanguageStandard>stdcpp17</LanguageStandard>
<PrecompiledHeaderFile />
</ClCompile>
<Link>
Expand All @@ -209,7 +208,6 @@
<CompileAsManaged>false</CompileAsManaged>
<CompileAsWinRT>false</CompileAsWinRT>
<StringPooling>true</StringPooling>
<ExceptionHandling>false</ExceptionHandling>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<FloatingPointModel>Fast</FloatingPointModel>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
Expand All @@ -218,7 +216,7 @@
<EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
<AdditionalIncludeDirectories>$(ProjectDir)lib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
<LanguageStandard>stdcpp14</LanguageStandard>
<LanguageStandard>stdcpp17</LanguageStandard>
<DebugInformationFormat>None</DebugInformationFormat>
<OmitFramePointers>true</OmitFramePointers>
<DisableLanguageExtensions>false</DisableLanguageExtensions>
Expand Down Expand Up @@ -248,7 +246,6 @@
<CompileAsManaged>false</CompileAsManaged>
<CompileAsWinRT>false</CompileAsWinRT>
<StringPooling>true</StringPooling>
<ExceptionHandling>false</ExceptionHandling>
<EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet>
<FloatingPointModel>Fast</FloatingPointModel>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
Expand All @@ -259,7 +256,7 @@
<DebugInformationFormat>None</DebugInformationFormat>
<OmitFramePointers>true</OmitFramePointers>
<DisableLanguageExtensions>false</DisableLanguageExtensions>
<LanguageStandard>stdcpp14</LanguageStandard>
<LanguageStandard>stdcpp17</LanguageStandard>
<PrecompiledHeaderFile />
</ClCompile>
<Link>
Expand All @@ -286,7 +283,6 @@
<CompileAsManaged>false</CompileAsManaged>
<CompileAsWinRT>false</CompileAsWinRT>
<StringPooling>true</StringPooling>
<ExceptionHandling>false</ExceptionHandling>
<EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet>
<FloatingPointModel>Fast</FloatingPointModel>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
Expand All @@ -295,7 +291,7 @@
<EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
<AdditionalIncludeDirectories>$(ProjectDir)lib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
<LanguageStandard>stdcpp14</LanguageStandard>
<LanguageStandard>stdcpp17</LanguageStandard>
<DebugInformationFormat>None</DebugInformationFormat>
<OmitFramePointers>true</OmitFramePointers>
<DisableLanguageExtensions>false</DisableLanguageExtensions>
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ PUGIXML_OBJ := lib/pugixml/pugixml.o
ZOPFLI_OBJ := lib/zopfli/hash.o lib/zopfli/squeeze.o lib/zopfli/gzip_container.o lib/zopfli/katajainen.o lib/zopfli/zopfli_lib.o lib/zopfli/cache.o lib/zopfli/zlib_container.o lib/zopfli/util.o lib/zopfli/tree.o lib/zopfli/deflate.o lib/zopfli/blocksplitter.o lib/zopfli/lz77.o
ZOPFLIPNG_OBJ := lib/zopflipng/lodepng/lodepng.o lib/zopflipng/lodepng/lodepng_util.o lib/zopflipng/zopflipng_lib.o

CFLAGS += -Wall -Wextra -Wno-unused-parameter -Werror -O3 -msse2 -mfpmath=sse -fno-exceptions -flto
CFLAGS += -Wall -Wextra -Wno-unused-parameter -Werror -O3 -msse2 -mfpmath=sse -flto
CPPFLAGS += -I./lib
CXXFLAGS += $(CFLAGS) -std=c++14 -fno-rtti
LDFLAGS += -flto
CXXFLAGS += $(CFLAGS) -std=c++17 -fno-rtti
LDFLAGS += -flto -lpthread

ifeq ($(OS), Windows_NT)
SYSTEM := Windows
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ Usage: leanify [options] paths
-f, --fastmode Fast mode, no recompression.
-q, --quiet No output to stdout.
-v, --verbose Verbose output.
-p, --parallel Distribute all tasks to all CPUs.
--keep-exif Do not remove Exif.
```

Expand Down
2 changes: 1 addition & 1 deletion build_gcc.bat
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@Echo off
Pushd %~dp0
SetLocal EnableDelayedExpansion
Set Args=-std=c++14 -O3 -msse2 -mfpmath=sse -fno-exceptions -fno-rtti -flto -I./lib -s -o "Leanify" Leanify.res
Set Args=-std=c++17 -O3 -msse2 -mfpmath=sse -fno-exceptions -fno-rtti -flto -I./lib -s -o "Leanify" Leanify.res
For /r "%~dp0" %%i In (*.cpp *.c *.cc) Do (Set t=%%i && Set Args=!Args!!t:%~dp0=!)
For %%i In (fileio_linux.cpp lib\mozjpeg\jstdhuff.c) Do Set Args=!Args:%%i =!
windres --output-format=coff Leanify.rc Leanify.res
Expand Down
78 changes: 78 additions & 0 deletions lib/taskflow/core/algorithm/critical.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#pragma once

#include "../task.hpp"

/**
@file critical.hpp
@brief critical include file
*/

namespace tf {

// ----------------------------------------------------------------------------
// CriticalSection
// ----------------------------------------------------------------------------

/**
@class CriticalSection

@brief class to create a critical region of limited workers to run tasks

tf::CriticalSection is a warpper over tf::Semaphore and is specialized for
limiting the maximum concurrency over a set of tasks.
A critical section starts with an initial count representing that limit.
When a task is added to the critical section,
the task acquires and releases the semaphore internal to the critical section.
This design avoids explicit call of tf::Task::acquire and tf::Task::release.
The following example creates a critical section of one worker and adds
the five tasks to the critical section.

@code{.cpp}
tf::Executor executor(8); // create an executor of 8 workers
tf::Taskflow taskflow;

// create a critical section of 1 worker
tf::CriticalSection critical_section(1);

tf::Task A = taskflow.emplace([](){ std::cout << "A" << std::endl; });
tf::Task B = taskflow.emplace([](){ std::cout << "B" << std::endl; });
tf::Task C = taskflow.emplace([](){ std::cout << "C" << std::endl; });
tf::Task D = taskflow.emplace([](){ std::cout << "D" << std::endl; });
tf::Task E = taskflow.emplace([](){ std::cout << "E" << std::endl; });

critical_section.add(A, B, C, D, E);

executor.run(taskflow).wait();
@endcode

*/
class CriticalSection : public Semaphore {

public:

/**
@brief constructs a critical region of a limited number of workers
*/
explicit CriticalSection(int max_workers = 1);

/**
@brief adds a task into the critical region
*/
template <typename... Tasks>
void add(Tasks...tasks);
};

inline CriticalSection::CriticalSection(int max_workers) :
Semaphore {max_workers} {
}

template <typename... Tasks>
void CriticalSection::add(Tasks... tasks) {
(tasks.acquire(*this), ...);
(tasks.release(*this), ...);
}


} // end of namespace tf. ---------------------------------------------------


Loading