commit b688da651b74f6c7f9811d9a4dfae3958a77719b Author: Alexis Pereda Date: Mon May 10 18:14:13 2021 +0200 thesis version diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9cbce3f --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +build/ +debug/ +release/ +clang/ +notes +__pycache__/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..8fb4804 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,205 @@ +cmake_minimum_required(VERSION 3.0) +get_filename_component(project_name ${CMAKE_CURRENT_SOURCE_DIR} NAME) +project(${project_name}) + +set(EXTENSION "cpp") + +set(CMAKE_C_STANDARD 99) +set(CMAKE_CXX_STANDARD 14) + +set(GEN_BINARY OFF) +set(GEN_LIBRARY OFF) +set(LIB_TYPE STATIC) # NONE, STATIC, SHARED, MODULE +set(LIBS_TYPE STATIC) + +set(FLAGS_ANY "-Wall -Wextra -Wfatal-errors -Winline -fopenmp") +set(FLAGS_DEBUG "-DDEBUG -Og -pg -fsanitize=thread") +set(FLAGS_RELEASE "-DNDEBUG -O2") + +set(SRCDIRS src) +set(LIBSDIRS lib) +set(TESTSDIRS celero tests plot) +set(EXAMPLESDIRS examples) +set(MANDIRS ) + +set(INCLUDE_DIRS inc lib) +set(LIBRARIES "-lpthread") + +set(celero_FLAGS "-fopenmp") +set(celero_INCLUDE_DIRS "celero") +set(celero_LIBRARIES "-lpthread -fopenmp") + +set(USER_LIBRARIES "") + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAGS_ANY}") +set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAGS_ANY} ${FLAGS_DEBUG}") +set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${FLAGS_ANY} ${FLAGS_RELEASE}") + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS_ANY}") +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAGS_ANY} ${FLAGS_DEBUG}") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${FLAGS_ANY} ${FLAGS_RELEASE}") + +if(USE_SANITIZER STREQUAL "Address") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") +elseif(USE_SANITIZER STREQUAL "Leak") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=leak") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=leak") +elseif(USE_SANITIZER STREQUAL "Thread") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread") +elseif(USE_SANITIZER STREQUAL "Undefined") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined") +endif() + +## Libraries +if(NOT ${LIB_TYPE} MATCHES "^NONE$") + # Project library + if(GEN_LIBRARY) + set(lib_src "") + foreach(srcdir ${SRCDIRS}) + set(srcpath ${CMAKE_CURRENT_SOURCE_DIR}/${srcdir}) + file(GLOB_RECURSE tmpsrc ${srcpath}/*.${EXTENSION}) + list(APPEND lib_src ${tmpsrc}) + endforeach() + + set(lib ${PROJECT_NAME}) + if(lib_src) + message(STATUS "+ Library: ${lib}") + add_library(${lib} ${LIB_TYPE} ${lib_src}) + target_include_directories(${lib} PUBLIC ${INCLUDE_DIRS}) + target_link_libraries(${lib} ${LIBRARIES}) + list(APPEND USER_LIBRARIES ${lib}) + else() + message(WARNING "! Library ${lib}: no sources") + endif() + endif() +endif() + +## Other libraries +if(NOT ${LIBS_TYPE} MATCHES "^NONE$") + foreach(libsdir ${LIBSDIRS}) + set(libspath ${CMAKE_CURRENT_SOURCE_DIR}/${libsdir}) + file(GLOB libs RELATIVE ${libspath} ${libspath}/*) + if(libs) + foreach(child ${libs}) + set(lib "") + if(IS_DIRECTORY ${libspath}/${child}) + set(lib ${child}) + file(GLOB_RECURSE lib_src ${libspath}/${child}/*.${EXTENSION}) + else() + message(WARNING "! Ignoring file: ${libsdir}/${child}") + endif() + if(lib) + if(lib_src) + message(STATUS "+ Library: ${lib}") + add_library(${lib} ${LIBS_TYPE} ${lib_src}) + target_include_directories(${lib} PUBLIC ${INCLUDE_DIRS}) + target_link_libraries(${lib} ${LIBRARIES}) + list(APPEND USER_LIBRARIES ${lib}) + else() + message(WARNING "! Library ${lib}: no sources") + endif() + endif() + endforeach() + endif() + endforeach() +endif() + +## Binary +if(GEN_BINARY) + set(src "") + foreach(srcdir ${SRCDIRS}) + set(srcpath ${CMAKE_CURRENT_SOURCE_DIR}/${srcdir}) + file(GLOB_RECURSE tmpsrc ${srcpath}/*.${EXTENSION}) + list(APPEND src ${tmpsrc}) + endforeach() + set(bin ${PROJECT_NAME}) + if(src) + if(GEN_LIBRARY) + set(bin ${bin}.bin) + endif() + message(STATUS "+ Binary: ${bin}") + add_executable(${bin} ${src}) + target_include_directories(${bin} PUBLIC ${LIBSDIRS} ${INCLUDE_DIRS}) + target_link_libraries(${bin} ${LIBRARIES} ${USER_LIBRARIES}) + else() + message(WARNING "! Binary ${bin}: no sources") + endif() +endif() + +## Tests +foreach(testsdir ${TESTSDIRS}) + set(testspath ${CMAKE_CURRENT_SOURCE_DIR}/${testsdir}) + file(GLOB_RECURSE tests_src ${testspath}/*.${EXTENSION}) + if(tests_src) + set(tests ${testsdir}_${PROJECT_NAME}) + message(STATUS "+ Tests: ${tests}") + add_executable(${tests} ${tests_src}) + target_compile_options(${tests} PUBLIC ${${testsdir}_FLAGS}) + target_include_directories(${tests} PUBLIC ${SRCDIRS} ${LIBSDIRS} ${INCLUDE_DIRS} ${${testsdir}_INCLUDE_DIRS}) + target_link_libraries(${tests} ${LIBRARIES} ${USER_LIBRARIES} ${${testsdir}_LIBRARIES}) + endif() +endforeach() + +## Examples +foreach(examplesdir ${EXAMPLESDIRS}) + set(examplespath ${CMAKE_CURRENT_SOURCE_DIR}/${examplesdir}) + file(GLOB examples RELATIVE ${examplespath} ${examplespath}/*) + if(examples) + foreach(child ${examples}) + set(example_bin_filename "") + set(example "") + if(IS_DIRECTORY ${examplespath}/${child}) + set(example_bin_filename ${child}) + set(example ${examplesdir}_${example_bin_filename}) + file(GLOB_RECURSE example_src ${examplespath}/${child}/*.${EXTENSION}) + else() + get_filename_component(extension ${child} EXT) + if(${extension} MATCHES "^.${EXTENSION}$") + get_filename_component(example_name ${child} NAME_WE) + set(example_bin_filename ${example_name}) + set(example ${examplesdir}_${example_bin_filename}) + set(example_src ${examplespath}/${child}) + endif() + endif() + if(example) + if(example_src) + message(STATUS "+ Example: ${examplesdir}/${example}") + add_executable(${example} ${example_src}) + target_include_directories(${example} PUBLIC ${SRCDIRS} ${LIBSDIRS} ${INCLUDE_DIRS}) + target_link_libraries(${example} ${LIBRARIES} ${USER_LIBRARIES}) + set_target_properties(${example} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${examplesdir}) + set_target_properties(${example} PROPERTIES OUTPUT_NAME ${example_bin_filename}) + else() + message(WARNING "! Example ${example}: no sources") + endif() + endif() + endforeach() + endif() +endforeach() + +## Man pages +foreach(mandir ${MANDIRS}) + set(MANPATH ${CMAKE_CURRENT_SOURCE_DIR}/${mandir}) + set(MAN_OUTPATH ${CMAKE_BINARY_DIR}/deb/usr/share/man) + file(GLOB_RECURSE man_src RELATIVE ${MANPATH} ${MANPATH}/*) + if(man_src) + set(man_outfiles "") + foreach(man_file IN LISTS man_src) + set(man_outfile ${MAN_OUTPATH}/${man_file}.gz) + get_filename_component(man_outdir ${man_outfile} DIRECTORY) + list(APPEND man_outfiles ${man_outfile}) + message(STATUS "+ manpage: ${man_file}") + add_custom_command(OUTPUT ${man_outfile} + COMMAND ${CMAKE_COMMAND} -E make_directory ${man_outdir} + COMMAND ${CMAKE_COMMAND} -E copy ${MANPATH}/${man_file} ${MAN_OUTPATH}/${man_file} + COMMAND gzip -f ${MAN_OUTPATH}/${man_file} + DEPENDS ${MANPATH}/${man_file}) + endforeach() + add_custom_target(man ALL DEPENDS ${man_outfiles}) + endif() +endforeach() diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ffdc907 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + pfor + Copyright (C) 2021 phd / dev + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) 2021 phd / dev + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8fe6dbc --- /dev/null +++ b/README.md @@ -0,0 +1,145 @@ +# About + +This is an active library, using C++ template metaprogramming, to do assisted parallelisation using algorithmic skeletons. +This work has been done for my Ph.D. thesis. + +## Brief + +It implements [algorithmic skeletons](https://en.wikipedia.org/wiki/Algorithmic_skeleton) to provide an abstraction +for developers to write parallel software. +It exposes: +- bones: atomic algorithmic structure to use to build skeletons; +- links: function signatures with placeholders to define data transfers between tasks; +- execution policies: a solution to select how tasks will be distributed. + +After describing an algorithm, one can generate a functionoid that implements it and run it. +Using the links system in combination with the execution policy and overall structure knowledge, +the library provide a way to guarantee repeatability from one execution to another and even +for different number of allotted cores. +This is particularly useful for stochastic programs because of the use of pseudo-random numbers. + +Main features: +- parallel implementation is hidden and separated from domain code; +- execution is controlled by the chosen execution policy; +- repeatability is automatically enabled. + +## Related projects + +- [ROSA](https://phd.pereda.fr/dev/rosa), an algorithmic skeletons collection for [OR](https://en.wikipedia.org/wiki/Operations_research) algorithms; +- [TMP](https://phd.pereda.fr/dev/tmp), template metaprogramming library used to implement this library. + +See [ROSA](https://phd.pereda.fr/dev/rosa) for more complete and meaningful examples of algorithmic skeletons and +for the performances presented in the thesis. + +## Example + +The code below defines `Gen`, a integral sequence generator, starting from the value given +when constructed. +```cpp +struct Gen { + int value; + int operator()() { return value++; } +}; +``` + +The next code defines `transform`, a function that modifies its input depending on some +pseudo-random number generated using the given generator. +```cpp +int transform(int v, std::mt19937& rng) { + std::uniform_int_distribution d(-3, 3); + return v + d(rng); +} +``` + +The library exposes a raw interface to build skeletons from its structure and links definitions. +An example using the type `Gen`, the function `transform` and the standard function `std::min` is shown below. +```cpp +using Structure = +S, + Fn> +>; + +using Links = +L(), + int(), + int(R<0>, RNG) + >, + int(int, int) +>; + +using Skeleton = BuildSkeletonT; + +int main() { + auto algo = implement(); + algo.skeleton.n = 10; + algo.skeleton.task.task<0>() = Gen{5}; + + algo.executor.repeatability.upTo(8); + algo.executor.cores = 8; + + auto r = algo(); + std::printf("%d\n", r); +} +``` + +The same can be achieved using the EDSL provided by the library as below: +```cpp +int main() { + auto gen = alsk::edsl::makeOperand(); + auto transform = alsk::edsl::makeOperand, alsk::arg::RNG), FN(::transform)>(); + auto selectMin = alsk::edsl::makeOperand>>(); + + constexpr auto body = (10*alsk::edsl::link()>(gen, transform)) ->* selectMin; + auto algo = alsk::edsl::implement(body); + algo.skeleton.task.task<0>() = Gen{5}; + + algo.executor.repeatability.upTo(8); + algo.executor.cores = 8; + + auto r = algo(); + std::printf("%d\n", r); +} +``` + +Usually, the first interface is used to produce templates instead of types directly. + +As the examples above show, the library can handle contextual arguments like random number generators to ensure +the repeatability of the execution (in this case, up to 8 cores as specified). + +Additionally, the library optimises the number of PRNG to guarantee repeatability. +Without optimisation, the number of PRNG is linear because it must be equal to the number of tasks using a PRNG to run (red). +When the possible numbers of cores are from 1 to 64, it can be reduced (blue). +When the possible numbers of cores are powers of 2 up to 64, it becomes cyclic with a low maximum (orange). + +
+ +## Related publications + +- "Repeatability with Random Numbers Using Algorithmic Skeletons", ESM 2020 (https://hal.archives-ouvertes.fr/hal-02980472); +- "Modeling Algorithmic Skeletons for Automatic Parallelization Using Template Metaprogramming", HPCS 2019 (IEEE) [10.1109/HPCS48598.2019.9188128](https://doi.org/10.1109/HPCS48598.2019.9188128); +- "Processing Algorithmic Skeletons at Compile-Time", ROADEF 2020 (https://hal.archives-ouvertes.fr/hal-02573660); +- "Algorithmic Skeletons Using Template Metaprogramming", ICAST 2019; +- "Parallel Algorithmic Skeletons for Metaheuristics", ROADEF 2019 (https://hal.archives-ouvertes.fr/hal-02059533). + +## Organisation + +Main directories: +- `src/alsk`: the library sources; +- `examples`: some examples using the library. + +## Usage + +To produce the `Makefile` and build the project: +```bash +mkdir build +cd build +cmake -DCMAKE_BUILD_TYPE=Release .. +make +``` + +To run examples: +```bash +./build/examples/${example_name} +``` diff --git a/celero/bone/common.cpp b/celero/bone/common.cpp new file mode 100644 index 0000000..09445a0 --- /dev/null +++ b/celero/bone/common.cpp @@ -0,0 +1,32 @@ +#include + +#include "common.h" + +namespace bench { + +Data Task::operator()(int min, int max) const { + Data v(size); + std::generate_n(std::begin(v), size, [&, i=0]() mutable { return (++i)%(max-min+1) + min; }); + return v; +}; + +Data taskD(Data const& data) { + Data out(data.size()+2); + std::copy(std::begin(data), std::end(data), std::begin(out)+2); + out[0] = std::accumulate(std::begin(data), std::end(data), Data::value_type{}); + out[1] = out[0]&1? out[0]*out[0] : out[0]; + return out; +} + +Data const& select(Data const& a, Data const& b) { + Data::value_type sumA = std::accumulate(std::begin(a), std::end(a), Data::value_type{}); + Data::value_type sumB = std::accumulate(std::begin(b), std::end(b), Data::value_type{}); + + return sumA < sumB? a : b; +} + +Data::value_type project(Data const& a, Data::value_type const& init) { + return std::accumulate(std::begin(a), std::end(a), init); +} + +} diff --git a/celero/bone/common.h b/celero/bone/common.h new file mode 100644 index 0000000..bbe236f --- /dev/null +++ b/celero/bone/common.h @@ -0,0 +1,57 @@ +#ifndef ALSK_CELERO_BONE_COMMON_H +#define ALSK_CELERO_BONE_COMMON_H + +#include +#include +#include + +#include + +#include + +namespace bench { + +using Data = std::vector; +using Value = Data::value_type; + +struct Task { + std::size_t size; + Data operator()(int min, int max) const; + + // TODO inline version: improve benchmarking for skeleton? + // Data operator()(int min, int max) const { + // Data v(size); + // std::generate_n(std::begin(v), size, [&, i=0]() mutable { return (++i)%(max-min+1) + min; }); + // return v; + // }; +}; +constexpr auto eTask = alsk::edsl::makeOperand(); +constexpr auto eTaskStdFun = alsk::edsl::makeOperand>(); + +template +void taskV() { + std::vector v(count); + std::generate_n(std::begin(v), count, [i=0]() mutable { return i++; }); + for(std::size_t i = 0; i < count; ++i) + celero::DoNotOptimizeAway(std::accumulate(begin(v), end(v), i)); +} +template +constexpr auto eTaskV = alsk::edsl::makeOperand)>(); +template +constexpr auto eTaskVStdFun = alsk::edsl::makeOperand>(); + +Data taskD(Data const&); +constexpr auto eTaskD = alsk::edsl::makeOperand(); +constexpr auto eTaskDStdFun = alsk::edsl::makeOperand>(); + +Data const& select(Data const&, Data const&); +constexpr auto eSelect = alsk::edsl::makeOperand(); +constexpr auto eSelectStdFun = alsk::edsl::makeOperand>(); + +Value project(Data const&, Value const&); +constexpr auto eProject = alsk::edsl::makeOperand(); +constexpr auto eProjectStdFun = alsk::edsl::makeOperand>(); + +} + +#endif diff --git a/celero/bone/farm.cpp b/celero/bone/farm.cpp new file mode 100644 index 0000000..7547c01 --- /dev/null +++ b/celero/bone/farm.cpp @@ -0,0 +1,34 @@ +#include +#include + +#include "common.h" + +using namespace bench; + +constexpr unsigned samples = 30, iterations = 10, cores = 4; + +constexpr unsigned n = 64; +constexpr std::size_t vecSize = 1'000; + +constexpr auto eFarm = n*eTaskV; + +BASELINE(Farm, Handwritten, samples, iterations) { + for(unsigned i = 0; i < n; ++i) taskV(); +} + +BENCHMARK(Farm, Skeleton, samples, iterations) { + auto farm = alsk::edsl::implement(eFarm); + farm(); +} + +BASELINE(FarmPar, Handwritter, samples, iterations) { +#pragma omp parallel for num_threads(cores) + for(unsigned i = 0; i < n; ++i) taskV(); +} + +BENCHMARK(FarmPar, Parallel, samples, iterations) { + auto farm = alsk::edsl::implement(eFarm); + farm.executor.cores = cores; + + farm(); +} diff --git a/celero/bone/farmsel.cpp b/celero/bone/farmsel.cpp new file mode 100644 index 0000000..91111a9 --- /dev/null +++ b/celero/bone/farmsel.cpp @@ -0,0 +1,111 @@ +#include +#include + +#include "common.h" + +using namespace bench; +using namespace alsk::edsl; +using namespace alsk::arg; + +constexpr unsigned samples = 10, iterations = 100, cores = 4; + +constexpr std::size_t vecSize = 10'000; +constexpr unsigned n = 128; +constexpr int minValue = -250, maxValue = +250; + +decltype(auto) hwFarmSel(int min, int max) { + Task task{vecSize}; + Data best{}; + + if(n) + best = task(min, max); + for(std::size_t i = 1; i < n; ++i) { + Data current = task(min, max); + best = select(current, best); + } + + return best; +} + +decltype(auto) hwFarmSelSk(int min, int max) { + Task task{vecSize}; + Data best{}; + + std::vector bests(n); + + for(std::size_t i = 0; i < n; ++i) + bests[i] = task(min, max); + + best = std::move(bests[0]); + for(std::size_t i = 1; i < n; ++i) + best = select(std::move(bests[i-1]), std::move(best)); + + return best; +} + +decltype(auto) hwFarmSelPar(int min, int max) { + Task task{vecSize}; + Data best{}; + + std::vector bests(n); + +#pragma omp parallel for num_threads(cores) + for(std::size_t i = 0; i < n; ++i) + bests[i] = task(min, max); + + best = std::move(bests[0]); + for(std::size_t i = 1; i < n; ++i) + best = select(std::move(bests[i-1]), std::move(best)); + + return best; +} + +constexpr auto eFarmSel = link(int, int)>(n * link, P<1>)>(eTask)) ->* eSelect; +constexpr auto eFarmSelStdFun = link(int, int)>(n * link, P<1>)>(eTaskStdFun)) ->* eSelectStdFun; + +BASELINE(FarmSel, Handwritten, samples, iterations) { + celero::DoNotOptimizeAway( + hwFarmSel(minValue, maxValue) + ); +} + +BENCHMARK(FarmSel, HandwrittenSk, samples, iterations) { + celero::DoNotOptimizeAway( + hwFarmSelSk(minValue, maxValue) + ); +} + +BENCHMARK(FarmSel, Skeleton, samples, iterations) { + auto farmSel = alsk::edsl::implement(eFarmSel); + farmSel.skeleton.task.size = vecSize; + + celero::DoNotOptimizeAway( + farmSel(minValue, maxValue) + ); +} + +BENCHMARK(FarmSel, SkeletonStdFunction, samples, iterations) { + auto farmSel = alsk::edsl::implement(eFarmSelStdFun); + farmSel.skeleton.task = Task{vecSize}; + farmSel.skeleton.select = bench::select; + + celero::DoNotOptimizeAway( + farmSel(minValue, maxValue) + ); +} + +BASELINE(FarmSelPar, Handwritten, samples, iterations) { + celero::DoNotOptimizeAway( + hwFarmSelPar(minValue, maxValue) + ); +} + +BENCHMARK(FarmSelPar, Skeleton, samples, iterations) { + auto farmSel = alsk::edsl::implement(eFarmSel); + farmSel.executor.cores = cores; + farmSel.skeleton.task.size = vecSize; + + celero::DoNotOptimizeAway( + farmSel(minValue, maxValue) + ); +} diff --git a/celero/bone/itersel.cpp b/celero/bone/itersel.cpp new file mode 100644 index 0000000..147fc19 --- /dev/null +++ b/celero/bone/itersel.cpp @@ -0,0 +1,50 @@ +#include +#include + +#include "common.h" + +using namespace bench; +using namespace alsk::edsl; +using namespace alsk::arg; + +constexpr unsigned samples = 50, iterations = 100; +constexpr unsigned n = 8192; // if too small => bad results +constexpr auto initVector = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; + +decltype(auto) hwIterSel(Data const& init) { + Data best = init; + + for(std::size_t i = 0; i < n; ++i) { + Data current = taskD(best); + best = select(std::move(current), std::move(best)); + } + + return best; +} + +constexpr auto eIterSel = &link(n * eTaskD) ->* eSelect; +constexpr auto eIterSelStdFun = &link(n * eTaskDStdFun) ->* eSelectStdFun; + +BASELINE(IterSel, Handwritten, samples, iterations) { + celero::DoNotOptimizeAway( + hwIterSel(initVector) + ); +} + +BENCHMARK(IterSel, Skeleton, samples, iterations) { + auto iterSel = alsk::edsl::implement(eIterSel); + + celero::DoNotOptimizeAway( + iterSel(initVector) + ); +} + +BENCHMARK(IterSel, SkeletonStdFunction, samples, iterations) { + auto iterSel = alsk::edsl::implement(eIterSelStdFun); + iterSel.skeleton.task = taskD; + iterSel.skeleton.select = bench::select; + + celero::DoNotOptimizeAway( + iterSel(initVector) + ); +} diff --git a/celero/bone/loop.cpp b/celero/bone/loop.cpp new file mode 100644 index 0000000..fd40026 --- /dev/null +++ b/celero/bone/loop.cpp @@ -0,0 +1,32 @@ +#include +#include + +#include "common.h" + +using namespace bench; +using namespace alsk::arg; + +constexpr unsigned samples = 50, iterations = 100; +constexpr unsigned n = 100, vecSize = 100; + +void hwLoop() { + for(std::size_t i = 0; i < n; ++i) taskV(); +} + +constexpr auto eLoop = seq(n * eTaskV); +constexpr auto eLoopStdFun = seq(n * eTaskVStdFun); + +BASELINE(Loop, Handwritten, samples, iterations) { + hwLoop(); +} + +BENCHMARK(Loop, Skeleton, samples, iterations) { + auto loop = alsk::edsl::implement(eLoop); + loop(); +} + +BENCHMARK(Loop, SkeletonStdFunction, samples, iterations) { + auto loop = alsk::edsl::implement(eLoopStdFun); + loop.skeleton.task = taskV; + loop(); +} diff --git a/celero/bone/serial.cpp b/celero/bone/serial.cpp new file mode 100644 index 0000000..e146a5c --- /dev/null +++ b/celero/bone/serial.cpp @@ -0,0 +1,70 @@ +#include +#include + +#include "common.h" + +using namespace bench; +using namespace alsk::arg; +using namespace alsk::edsl; + +constexpr unsigned samples = 50, iterations = 100; +constexpr std::size_t vecSize = 100'000; +constexpr int minValue = -250, maxValue = +250; + +decltype(auto) hwSerial(int min, int max) { + Task task0{vecSize}, task1{vecSize}; + Data v0 = task0(min, max), v1 = task1(min, max); + + Data const& v = select(v0, v1); + return project(v, rand()); +} + +decltype(auto) hwSerialBad(int min, int max) { + Task task0{vecSize}, task1{vecSize}; + Data v2 = select(task0(min, max), task1(min, max)); + return project(v2, rand()); +} + +constexpr auto eRand = makeOperand(); +constexpr auto lTask = link, P<1>)>(eTask); +constexpr auto eSerial = link(int, int)>(lTask & lTask & link, R<1>)>(eSelect) & eRand & link, R<3>)>(eProject)); + +constexpr auto eRandStdFun = makeOperand>(); +constexpr auto lTaskStdFun = link, P<1>)>(eTaskStdFun); +constexpr auto eSerialStdFun = link(int, int)>( + lTaskStdFun & lTaskStdFun & link, R<1>)>(eSelectStdFun) & + eRandStdFun & link, R<3>)>(eProjectStdFun)); + +BASELINE(Serial, Handwritten, samples, iterations) { + celero::DoNotOptimizeAway( + hwSerial(minValue, maxValue) + ); +} + +BENCHMARK(Serial, HandwrittenBad, samples, iterations) { + celero::DoNotOptimizeAway( + hwSerialBad(minValue, maxValue) + ); +} + +BENCHMARK(Serial, Skeleton, samples, iterations) { + auto serial = alsk::edsl::implement(eSerial); + serial.skeleton.task<0>().size = vecSize; + serial.skeleton.task<1>().size = vecSize; + celero::DoNotOptimizeAway( + serial(minValue, maxValue) + ); +} + +BENCHMARK(Serial, SkeletonStdFunction, samples, iterations) { + auto serial = alsk::edsl::implement(eSerialStdFun); + serial.skeleton.task<0>() = Task{vecSize}; + serial.skeleton.task<1>() = Task{vecSize}; + serial.skeleton.task<2>() = bench::select; + serial.skeleton.task<3>() = rand; + serial.skeleton.task<4>() = project; + + celero::DoNotOptimizeAway( + serial(minValue, maxValue) + ); +} diff --git a/celero/bone/while.cpp b/celero/bone/while.cpp new file mode 100644 index 0000000..f468c3a --- /dev/null +++ b/celero/bone/while.cpp @@ -0,0 +1,21 @@ +#include +#include + +#include "common.h" + +using namespace bench; +using namespace alsk::arg; + +constexpr unsigned samples = 50, iterations = 100; +constexpr unsigned n = 100, vecSize = 100; + +bool test(int& c) { return --c; } + +void hwLoop(int& c) { + while(test(c)) taskV(); +} + +BASELINE(While, Handwritten, samples, iterations) { + int count = n; + hwLoop(count); +} diff --git a/celero/executor/common.h b/celero/executor/common.h new file mode 100644 index 0000000..1abec63 --- /dev/null +++ b/celero/executor/common.h @@ -0,0 +1,57 @@ +#ifndef ALSK_CELERO_EXECUTOR_COMMON_H +#define ALSK_CELERO_EXECUTOR_COMMON_H + +#include +#include + +#include + +#include + +#include "../bone/common.h" + +namespace bench { + +constexpr auto buildExprFarm() { + using namespace alsk::arg; + using namespace alsk::edsl; + return 20 * eTaskV<1000>; +} + +constexpr auto exprFarm = buildExprFarm(); + +constexpr auto buildExprFarmSel() { + using namespace alsk::arg; + using namespace alsk::edsl; + return link(link, P<1>)>(eTask) & link)>((50 * link)>(eTaskD)) ->* eSelect)); +} + +constexpr auto exprFarmSel = buildExprFarmSel(); + +constexpr auto buildExprTwo() { + using namespace alsk::arg; + using namespace alsk::edsl; + + constexpr auto farmsel = link)>(1000 * link)>(eTaskD)) ->* eSelect; + constexpr auto serial = link(P<0>, P<1>)>(link, P<1>)>(eTask) & farmsel); + return link(2 * serial); +} + +constexpr auto exprTwo = buildExprTwo(); + +constexpr auto buildExprTwoS() { + using namespace alsk::arg; + using namespace alsk::edsl; + + constexpr auto farmsel = link(1000 * link)>(eTaskD)) ->* eSelect; + constexpr auto itersel = &link)>(2 * farmsel) ->* eSelect; + constexpr auto serial = link(P<0>, P<1>)>(link, P<1>)>(eTask) & itersel); + constexpr auto loop = &link, P<1>)>(2 * serial); + return link(2 * loop); +} + +constexpr auto exprTwoS = buildExprTwoS(); + +} + +#endif diff --git a/celero/executor/farm.cpp b/celero/executor/farm.cpp new file mode 100644 index 0000000..4ba87ff --- /dev/null +++ b/celero/executor/farm.cpp @@ -0,0 +1,52 @@ +#include + +#include "common.h" + +constexpr unsigned samples = 12, iterations = 10, cores = 4; + +BASELINE(ExecFarm, Sequential, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprFarm); + f(); +} + +BENCHMARK(ExecFarm, FirstLevelEqui, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprFarm); + f.executor.cores = cores; + f(); +} + +BENCHMARK(ExecFarm, FirstLevelGreedy, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprFarm); + f.executor.cores = cores; + f(); +} + +BENCHMARK(ExecFarm, FirstLevelNoOpti, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprFarm); + f.executor.cores = cores; + f(); +} + +BENCHMARK(ExecFarm, DynamicPool, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprFarm); + f.executor.cores = cores; + f(); +} + +BENCHMARK(ExecFarm, StaticPool, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprFarm); + f.executor.cores = cores; + f(); +} + +BENCHMARK(ExecFarm, StaticPoolId, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprFarm); + f.executor.cores = cores; + f(); +} + +BENCHMARK(ExecFarm, StaticThread, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprFarm); + f.executor.cores = cores; + f(); +} diff --git a/celero/executor/farmsel.cpp b/celero/executor/farmsel.cpp new file mode 100644 index 0000000..6458fa9 --- /dev/null +++ b/celero/executor/farmsel.cpp @@ -0,0 +1,62 @@ +#include + +#include "common.h" + +constexpr unsigned samples = 12, iterations = 10, cores = 4; +constexpr std::size_t vecSize = 100'000; +constexpr int minValue = -250, maxValue = +250; + +BASELINE(ExecFarmSel, Sequential, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprFarmSel); + f.skeleton.task<0>().size = vecSize; + f(minValue, maxValue); +} + +BENCHMARK(ExecFarmSel, FirstLevelEqui, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprFarmSel); + f.executor.cores = cores; + f.skeleton.task<0>().size = vecSize; + f(minValue, maxValue); +} + +BENCHMARK(ExecFarmSel, FirstLevelGreedy, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprFarmSel); + f.executor.cores = cores; + f.skeleton.task<0>().size = vecSize; + f(minValue, maxValue); +} + +BENCHMARK(ExecFarmSel, FirstLevelNoOpti, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprFarmSel); + f.executor.cores = cores; + f.skeleton.task<0>().size = vecSize; + f(minValue, maxValue); +} + +BENCHMARK(ExecFarmSel, DynamicPool, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprFarmSel); + f.executor.cores = cores; + f.skeleton.task<0>().size = vecSize; + f(minValue, maxValue); +} + +BENCHMARK(ExecFarmSel, StaticPool, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprFarmSel); + f.executor.cores = cores; + f.skeleton.task<0>().size = vecSize; + f(minValue, maxValue); +} + +BENCHMARK(ExecFarmSel, StaticPoolId, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprFarmSel); + f.executor.cores = cores; + f.skeleton.task<0>().size = vecSize; + f(minValue, maxValue); +} + +BENCHMARK(ExecFarmSel, StaticThread, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprFarmSel); + f.executor.cores = cores; + f.skeleton.task<0>().size = vecSize; + f(minValue, maxValue); +} diff --git a/celero/executor/sequential.cpp b/celero/executor/sequential.cpp new file mode 100644 index 0000000..5f5209f --- /dev/null +++ b/celero/executor/sequential.cpp @@ -0,0 +1,3 @@ +#include + +#include "common.h" diff --git a/celero/executor/twolevels.cpp b/celero/executor/twolevels.cpp new file mode 100644 index 0000000..8a4615e --- /dev/null +++ b/celero/executor/twolevels.cpp @@ -0,0 +1,62 @@ +#include + +#include "common.h" + +constexpr unsigned samples = 12, iterations = 10, cores = 4; +constexpr std::size_t vecSize = 1000; +constexpr int minValue = -250, maxValue = +250; + +BASELINE(ExecTwoLevels, Sequential, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprTwo); + f.skeleton.task.task<0>().size = vecSize; + f(minValue, maxValue); +} + +BENCHMARK(ExecTwoLevels, FirstLevelEqui, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprTwo); + f.executor.cores = cores; + f.skeleton.task.task<0>().size = vecSize; + f(minValue, maxValue); +} + +BENCHMARK(ExecTwoLevels, FirstLevelGreedy, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprTwo); + f.executor.cores = cores; + f.skeleton.task.task<0>().size = vecSize; + f(minValue, maxValue); +} + +BENCHMARK(ExecTwoLevels, FirstLevelNoOpti, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprTwo); + f.executor.cores = cores; + f.skeleton.task.task<0>().size = vecSize; + f(minValue, maxValue); +} + +BENCHMARK(ExecTwoLevels, DynamicPool, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprTwo); + f.executor.cores = cores; + f.skeleton.task.task<0>().size = vecSize; + f(minValue, maxValue); +} + +BENCHMARK(ExecTwoLevels, StaticPool, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprTwo); + f.executor.cores = cores; + f.skeleton.task.task<0>().size = vecSize; + f(minValue, maxValue); +} + +BENCHMARK(ExecTwoLevels, StaticPoolId, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprTwo); + f.executor.cores = cores; + f.skeleton.task.task<0>().size = vecSize; + f(minValue, maxValue); +} + +BENCHMARK(ExecTwoLevels, StaticThread, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprTwo); + f.executor.cores = cores; + f.skeleton.task.task<0>().size = vecSize; + f(minValue, maxValue); +} diff --git a/celero/executor/twolevelshard.cpp b/celero/executor/twolevelshard.cpp new file mode 100644 index 0000000..0558804 --- /dev/null +++ b/celero/executor/twolevelshard.cpp @@ -0,0 +1,62 @@ +#include + +#include "common.h" + +constexpr unsigned samples = 12, iterations = 10, cores = 4; +constexpr std::size_t vecSize = 1'000; +constexpr int minValue = -250, maxValue = +250; + +BASELINE(ExecTwoLevelsHard, Sequential, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprTwoS); + f.skeleton.task.task.task<0>().size = vecSize; + f(minValue, maxValue); +} + +BENCHMARK(ExecTwoLevelsHard, FirstLevelEqui, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprTwoS); + f.executor.cores = cores; + f.skeleton.task.task.task<0>().size = vecSize; + f(minValue, maxValue); +} + +BENCHMARK(ExecTwoLevelsHard, FirstLevelGreedy, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprTwoS); + f.executor.cores = cores; + f.skeleton.task.task.task<0>().size = vecSize; + f(minValue, maxValue); +} + +BENCHMARK(ExecTwoLevelsHard, FirstLevelNoOpti, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprTwoS); + f.executor.cores = cores; + f.skeleton.task.task.task<0>().size = vecSize; + f(minValue, maxValue); +} + +BENCHMARK(ExecTwoLevelsHard, DynamicPool, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprTwoS); + f.executor.cores = cores; + f.skeleton.task.task.task<0>().size = vecSize; + f(minValue, maxValue); +} + +BENCHMARK(ExecTwoLevelsHard, StaticPool, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprTwoS); + f.executor.cores = cores; + f.skeleton.task.task.task<0>().size = vecSize; + f(minValue, maxValue); +} + +BENCHMARK(ExecTwoLevelsHard, StaticPoolId, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprTwoS); + f.executor.cores = cores; + f.skeleton.task.task.task<0>().size = vecSize; + f(minValue, maxValue); +} + +BENCHMARK(ExecTwoLevelsHard, StaticThread, samples, iterations) { + auto f = alsk::edsl::implement(bench::exprTwoS); + f.executor.cores = cores; + f.skeleton.task.task.task<0>().size = vecSize; + f(minValue, maxValue); +} diff --git a/celero/inc/udm.h b/celero/inc/udm.h new file mode 100644 index 0000000..ef31f3b --- /dev/null +++ b/celero/inc/udm.h @@ -0,0 +1,40 @@ +#ifndef BENCH_INC_UDM_H +#define BENCH_INC_UDM_H + +#include +#include +#include + +class GetRusageUDM: public celero::UserDefinedMeasurementTemplate { + std::string getName() const override { return "time"; } + + bool reportSize() const override { return false; } + // bool reportMean() const override { return false; } + bool reportVariance() const override { return false; } + bool reportStandardDeviation() const override { return false; } + bool reportSkewness() const override { return false; } + bool reportKurtosis() const override { return false; } + bool reportZScore() const override { return false; } + bool reportMin() const override { return false; } + bool reportMax() const override { return false; } +}; + +class GetRusage { + int _who; + struct rusage _begin, _end; + int _iterations; + +public: + explicit GetRusage(int who = RUSAGE_SELF): _who{who} {} + void start(int iterations) { _iterations = iterations; getrusage(_who, &_begin); } + void stop() { getrusage(_who, &_end); } + + std::size_t get() { + auto begin = _begin.ru_utime, end = _end.ru_utime; + auto totalUs = (end.tv_sec - begin.tv_sec) * 1e6 + (end.tv_usec - begin.tv_usec); + return totalUs/_iterations; + } +}; + + +#endif diff --git a/celero/main.cpp b/celero/main.cpp new file mode 100644 index 0000000..228efc4 --- /dev/null +++ b/celero/main.cpp @@ -0,0 +1,2 @@ +#include +CELERO_MAIN diff --git a/celero/thread.cpp b/celero/thread.cpp new file mode 100644 index 0000000..3c4e4f6 --- /dev/null +++ b/celero/thread.cpp @@ -0,0 +1,36 @@ +#include +#include + +constexpr unsigned samples = 20; +constexpr unsigned iterations = 500; + +constexpr unsigned count = 1'000'000; + +namespace { + +unsigned r; +void *f(void * = nullptr) { + r = 0; + for(unsigned volatile i = 0; i < count; ++i) r += r; + return &r; +} + +} + +BASELINE(Thread, None, samples, iterations) { + celero::DoNotOptimizeAway(f()); +} + +BENCHMARK(Thread, cthread, samples, iterations) { + void *r; + pthread_t thread; + pthread_create(&thread, NULL, f, NULL); + pthread_join(thread, &r); + celero::DoNotOptimizeAway(r); +} + +BENCHMARK(Thread, stdthread, samples, iterations) { + std::thread thread{f, nullptr}; + thread.join(); + celero::DoNotOptimizeAway(thread); +} diff --git a/examples/basic_edsl.cpp b/examples/basic_edsl.cpp new file mode 100644 index 0000000..610c81c --- /dev/null +++ b/examples/basic_edsl.cpp @@ -0,0 +1,28 @@ +#include +#include + +struct Gen { + int value; + int operator()() { return value++; } +}; + +int transform(int v, std::mt19937& rng) { + std::uniform_int_distribution d(-3, 3); + return v + d(rng); +} + +int main() { + auto gen = alsk::edsl::makeOperand(); + auto transform = alsk::edsl::makeOperand, alsk::arg::RNG), FN(::transform)>(); + auto selectMin = alsk::edsl::makeOperand>>(); + + constexpr auto body = (10*alsk::edsl::link()>(gen, transform)) ->* selectMin; + auto algo = alsk::edsl::implement(body); + algo.skeleton.task.task<0>() = Gen{5}; + + algo.executor.repeatability.upTo(8); + algo.executor.cores = 8; + + auto r = algo(); + std::printf("%d\n", r); +} diff --git a/examples/basic_raw.cpp b/examples/basic_raw.cpp new file mode 100644 index 0000000..51d7bc1 --- /dev/null +++ b/examples/basic_raw.cpp @@ -0,0 +1,41 @@ +#include + +struct Gen { + int value; + int operator()() { return value++; } +}; + +int transform(int v, std::mt19937& rng) { + std::uniform_int_distribution d(-3, 3); + return v + d(rng); +} + +/* raw interface */ +using Structure = +alsk::S, + Fn> +>; + +using Links = +alsk::L(), + int(), + int(alsk::arg::R<0>, alsk::arg::RNG) + >, + int(int, int) +>; + +using Skeleton = alsk::BuildSkeletonT; + +int main() { + auto algo = alsk::implement(); + algo.skeleton.n = 10; + algo.skeleton.task.task<0>() = Gen{5}; + + algo.executor.repeatability.upTo(8); + algo.executor.cores = 8; + + auto r = algo(); + std::printf("%d\n", r); +} diff --git a/examples/dynamicpool.cpp b/examples/dynamicpool.cpp new file mode 100644 index 0000000..8f21487 --- /dev/null +++ b/examples/dynamicpool.cpp @@ -0,0 +1,32 @@ +#include + +#include + +using namespace alsk::arg; + +int main() { + alsk::exec::ExecutorState> state; + + state.config(4); + + constexpr int n = 40; + std::array, n> futures; + + std::puts("begin"); + + for(int i = 0; i < n; ++i) { + futures[i] = state.run([i] { for(int x = 0; x < 20'000'000+5'000'000*i; ++x); }); + } + + std::puts("wait"); + + std::promise p; + std::future f = state.run([] { return 42; }, p); + + std::printf("with value: %d\n", f.get()); + + for(int i = 0; i < n; ++i) + futures[i].wait(); + + std::puts("end"); +} diff --git a/examples/farmsel.cpp b/examples/farmsel.cpp new file mode 100644 index 0000000..03e40b0 --- /dev/null +++ b/examples/farmsel.cpp @@ -0,0 +1,52 @@ +#include +#include + +constexpr unsigned benchN = 32; +constexpr int benchMin = -250; +constexpr int benchMax = +250; + +constexpr unsigned benchVSize = 1'000'000; + +/** + * Functions + */ +namespace bench { + +using C = std::vector; + +struct Task { + std::size_t size; + + auto operator()(int min, int max) { + C v(size); + std::generate_n(std::begin(v), size, [&, i=0]() mutable { return (++i)%(max-min+1) + min; }); + return v; + }; +}; + +C select(C const& a, C const& b) { + C::value_type sumA = std::accumulate(std::begin(a), std::end(a), C::value_type{}); + C::value_type sumB = std::accumulate(std::begin(b), std::end(b), C::value_type{}); + + return sumA < sumB? a : b; +} + +} + +using namespace alsk::arg; +using tmp::Pack; + +using SkelFarmSel = alsk::FarmSel< + R<1>(int, int), + Pack, P<1>)>, + Pack +>; + +int main() { + auto farmSel = alsk::implement(); + farmSel.skeleton.task = bench::Task{benchVSize}; + farmSel.skeleton.select = bench::select; + farmSel.skeleton.n = benchN; + + auto volatile r = farmSel(benchMin, benchMax); +} diff --git a/examples/repeatability.cpp b/examples/repeatability.cpp new file mode 100644 index 0000000..8ac54a6 --- /dev/null +++ b/examples/repeatability.cpp @@ -0,0 +1,170 @@ +#include +#include +#include +#include + +#include + +template +using Executor = alsk::exec::StaticThread; + +namespace { + +using RNG = std::mt19937; +using namespace alsk; + +int task(RNG& rng) { + std::uniform_int_distribution dist(-100, 100); + + int a = dist(rng); + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + int b = dist(rng); + + return a - b; +} + +int sel(int a, int b) { return a + b; } + +constexpr auto oSel = alsk::edsl::link(); + +} // namespace + +void testA0() { + constexpr unsigned n = 20; + + auto farm = [] { + RNG rng; + + std::array ri; + + { + std::array ti; + for (unsigned i = 0; i < n; ++i) + ti[i] = std::thread{[&r = ri[i]](RNG& rng) { r = task(rng); }, + std::ref(rng)}; + for (unsigned i = 0; i < n; ++i) + ti[i].join(); + } + + return std::accumulate(std::begin(ri), std::end(ri), 0, sel); + }; + + std::printf("taskA0 [n=%u]\n", n); + for(unsigned i = 0; i < 8; ++i) + std::printf(" [x=%u] %5d\n", i, farm()); +} + +void testA1() { + auto eFarm = alsk::edsl::link( + (20*alsk::edsl::link), FN(task)>()) ->* oSel + ); + + auto farm = alsk::edsl::implement(eFarm); + + std::printf("testA1 [n=%lu]\n", farm.skeleton.n); + for(unsigned k = 1; k <= 8; ++k) { + RNG rng{}; + + farm.executor.cores = k; + std::printf(" [k=%u] %5d\n", k, farm(rng)); + } +} + +void testA2() { + auto eFarm = alsk::edsl::link( + (20*alsk::edsl::link()) ->* oSel + ); + + auto farm = alsk::edsl::implement(eFarm); + farm.executor.repeatability.upTo(8); + + std::printf("testA2 [n=%lu, r=%lu]\n", farm.skeleton.n, farm.state.context.maxId()); + for(unsigned k = 1; k <= 8; ++k) { + farm.executor.cores = k; + std::printf(" [k=%u] %5d\n", k, farm()); + farm.state.context.reset(); + } +} + +void testA3() { + constexpr auto oTask = alsk::edsl::link(); + auto eFarm = alsk::edsl::link( + (11*alsk::edsl::link()>(oTask & oTask)) ->* oSel + ); + + auto farm = alsk::edsl::implement(eFarm); + farm.executor.repeatability.upTo(8); + + std::printf("testA3 [n=%lu, r=%lu]\n", farm.skeleton.n, farm.state.context.maxId()); + for(unsigned k = 1; k <= 8; ++k) { + farm.executor.cores = k; + std::printf(" [k=%u] %5d\n", k, farm()); + farm.state.context.reset(); + } +} + +void testB0() { + constexpr unsigned n0 = 10, n1 = 8; + + auto farm = [] { + RNG rng; + + std::array ri; + + { + auto localTask = [&rng] { + std::array rj; + + std::array tj; + for (unsigned j = 0; j < n1; ++j) + tj[j] = std::thread{[&r = rj[j]](RNG& rng) { r = task(rng); }, + std::ref(rng)}; + for (unsigned j = 0; j < n1; ++j) + tj[j].join(); + + return std::accumulate(std::begin(rj), std::end(rj), 0, sel); + }; + + std::array ti; + for (unsigned i = 0; i < n0; ++i) + ti[i] = std::thread{[&r = ri[i], &localTask] { r = localTask(); }}; + for (unsigned i = 0; i < n0; ++i) + ti[i].join(); + } + + return std::accumulate(std::begin(ri), std::end(ri), 0, sel); + }; + + std::printf("taskB0 [n0=%u, n1=%u]\n", n0, n1); + for(unsigned i = 0; i < 4; ++i) + std::printf(" [x=%u] %5d\n", i, farm()); +} + +void testB1() { + auto eFarm = alsk::edsl::link( + (10*alsk::edsl::link()>( + alsk::edsl::link() & + (8*alsk::edsl::link()) ->* oSel + )) ->* oSel + ); + + auto farm = alsk::edsl::implement(eFarm); + farm.executor.repeatability.upTo(8); + + std::printf("testB1 [n0=%lu, n1=%lu, r=%lu]\n", farm.skeleton.n, farm.skeleton.task.task<1>().n, farm.state.context.maxId()); + for(unsigned k = 1; k <= 8; ++k) { + farm.executor.cores = k; + std::printf(" [k=%u] %5d\n", k, farm()); + farm.state.context.reset(); + } +} + +int main() { + testA0(); + testA1(); + testA2(); + testA3(); + + testB0(); + testB1(); +} diff --git a/examples/serial.cpp b/examples/serial.cpp new file mode 100644 index 0000000..612d05c --- /dev/null +++ b/examples/serial.cpp @@ -0,0 +1,15 @@ +#include + +using namespace alsk::arg; + +using Skel = alsk::Serial< + R<2>(int, int, int), + tmp::Pack, int(P<0>, P<1>)>, + tmp::Pack, int(R<0>, P<2>)>, + tmp::Pack, int(R<0>, R<1>)> +>; + +int main() { + auto task = alsk::implement(); + return task(4, 2, 3); +} diff --git a/examples/serial_itersel.cpp b/examples/serial_itersel.cpp new file mode 100644 index 0000000..7d09fe9 --- /dev/null +++ b/examples/serial_itersel.cpp @@ -0,0 +1,26 @@ +#include + +int produce(int a, int b) { + return rand()%(a|b); +} + +using namespace alsk; +using namespace alsk::arg; + +constexpr auto add = edsl::link, P<1>), std::plus>(); +constexpr auto mul = edsl::link, P<2>), std::multiplies>(); +constexpr auto min = edsl::link>>(); +constexpr auto prod = edsl::link), FN(produce)>(); + +using Skel = decltype(getSkeleton( + edsl::link(int, int, int)>( + add & + edsl::link, P<1>)>(seq(3 * prod) ->* min) & + mul + ) +)); + +int main() { + auto task = alsk::implement(); + std::printf("%d\n", task(10, 20, 5)); +} diff --git a/examples/tests.cpp b/examples/tests.cpp new file mode 100644 index 0000000..a92b5c4 --- /dev/null +++ b/examples/tests.cpp @@ -0,0 +1,105 @@ +#include + +#include +#include +#include +#include + +using namespace alsk::arg; +using namespace alsk::edsl; + +void example0(int count) { + struct Do { int operator()(int x) { std::puts("Do"); return x+1; } }; + struct Then { void operator()(int v) { std::printf("Then {%d}\n", v); } }; + struct Done { int operator()(int x, int y) { std::puts("Done"); return x*y; } }; + + auto aDo = makeOperand), Do>(); + auto aThen = makeOperand(); + auto aDone = makeOperand(); + + auto in = link(int)>( + aDo & + link)>( + 4 * link)>(aThen) + ) & + link, R<0>)>(aDone) + ); + + auto a = link(count * link(P<0>)>(in)); + + auto f = implement(a); + f(7); + + auto fIn = implement(in); + std::printf("result: %d\n", fIn(5)); +} + +void example1() { + // TODO? not really stateful here + struct Generate { int value; int operator()(int b) { return ++value+b; } }; auto generate = makeOperand(); + struct Transform0 { int operator()(int x) { return x+1; } }; auto transform0 = makeOperand(); + struct Transform1 { int operator()(int x) { return x-2; } }; auto transform1 = makeOperand(); + struct Produce { int operator()(int x, int y) { return x*y; } }; auto produce = makeOperand(); + struct Select { + int mod; + int operator()(int a, int b) { if(a%mod == b%mod) return a b%mod)? a : b; } + }; + auto select = makeOperand(); + + auto innerTask = link(int)>( + link)>(generate) & + link)>(transform0) & + link)>(transform1) & + link, R<1>)>(produce) + ); + auto task = link(10 * link(P<0>)>(innerTask)) ->* select; + + auto f = implement(task); + f.skeleton.select.mod = 5; + + std::printf("results: {"); + for(int i = 4; i < 9; ++i) std::printf("%d, ", f(i)); + std::puts("}"); +} + +std::mutex m; + +void use(unsigned int n) { unsigned long long volatile v{}; for(unsigned int i{}; i < n; ++i) for(unsigned int j{}; j < 500; ++j) ++v; } +void example2() { + struct Info { void operator()(std::size_t id) { + std::lock_guard lg{m}; + std::cerr << std::this_thread::get_id() << ' ' << id << std::endl; + } }; //auto info = makeOperand(); + struct Generate { int v; int operator()(std::mt19937& g) { return v+g(); } }; auto generate = makeOperand(); + struct Transform0 { int operator()(int x) { use(1000); return x+1; } }; auto transform0 = makeOperand(); + struct Transform1 { int operator()(int x) { use(1000); return x-2; } }; auto transform1 = makeOperand(); + struct Produce { int operator()(int x, int y) { return x*y; } }; auto produce = makeOperand(); + struct Select { + int mod; + int operator()(int a, int b) { if(a%mod == b%mod) return a b%mod)? a : b; } + }; + auto select = makeOperand(); + + auto innerSeq = link(int)>( + link(generate) & + link)>(transform0) & + link)>(transform1) & + link, R<1>)>(produce) + ); + auto innerTask0 = link(16 * link(P<0>)>(innerSeq)) ->* select; + auto innerTask = &link(30 * link(innerTask0)) ->* select; + auto task = link(2 * link)>(innerTask)); + + auto f = implement(task); + f.executor.cores = 4; + f.executor.repeatability.upTo(f.executor.cores); + f.skeleton.task.select.mod = 12; + f.skeleton.task.task.select.mod = 17; + + for(int i = 4; i < 9; ++i) f(i); +} + +int main(int argc, char**) { + example0(argc); + example2(); +} diff --git a/inc/catch.hpp b/inc/catch.hpp new file mode 100644 index 0000000..2a2d77a --- /dev/null +++ b/inc/catch.hpp @@ -0,0 +1,17877 @@ +/* + * Catch v2.13.3 + * Generated: 2020-10-31 18:20:31.045274 + * ---------------------------------------------------------- + * This file has been merged from multiple headers. Please don't edit it directly + * Copyright (c) 2020 Two Blue Cubes Ltd. All rights reserved. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ +#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED +#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED +// start catch.hpp + + +#define CATCH_VERSION_MAJOR 2 +#define CATCH_VERSION_MINOR 13 +#define CATCH_VERSION_PATCH 3 + +#ifdef __clang__ +# pragma clang system_header +#elif defined __GNUC__ +# pragma GCC system_header +#endif + +// start catch_suppress_warnings.h + +#ifdef __clang__ +# ifdef __ICC // icpc defines the __clang__ macro +# pragma warning(push) +# pragma warning(disable: 161 1682) +# else // __ICC +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wpadded" +# pragma clang diagnostic ignored "-Wswitch-enum" +# pragma clang diagnostic ignored "-Wcovered-switch-default" +# endif +#elif defined __GNUC__ + // Because REQUIREs trigger GCC's -Wparentheses, and because still + // supported version of g++ have only buggy support for _Pragmas, + // Wparentheses have to be suppressed globally. +# pragma GCC diagnostic ignored "-Wparentheses" // See #674 for details + +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wunused-variable" +# pragma GCC diagnostic ignored "-Wpadded" +#endif +// end catch_suppress_warnings.h +#if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER) +# define CATCH_IMPL +# define CATCH_CONFIG_ALL_PARTS +#endif + +// In the impl file, we want to have access to all parts of the headers +// Can also be used to sanely support PCHs +#if defined(CATCH_CONFIG_ALL_PARTS) +# define CATCH_CONFIG_EXTERNAL_INTERFACES +# if defined(CATCH_CONFIG_DISABLE_MATCHERS) +# undef CATCH_CONFIG_DISABLE_MATCHERS +# endif +# if !defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) +# define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER +# endif +#endif + +#if !defined(CATCH_CONFIG_IMPL_ONLY) +// start catch_platform.h + +#ifdef __APPLE__ +# include +# if TARGET_OS_OSX == 1 +# define CATCH_PLATFORM_MAC +# elif TARGET_OS_IPHONE == 1 +# define CATCH_PLATFORM_IPHONE +# endif + +#elif defined(linux) || defined(__linux) || defined(__linux__) +# define CATCH_PLATFORM_LINUX + +#elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || defined(__MINGW32__) +# define CATCH_PLATFORM_WINDOWS +#endif + +// end catch_platform.h + +#ifdef CATCH_IMPL +# ifndef CLARA_CONFIG_MAIN +# define CLARA_CONFIG_MAIN_NOT_DEFINED +# define CLARA_CONFIG_MAIN +# endif +#endif + +// start catch_user_interfaces.h + +namespace Catch { + unsigned int rngSeed(); +} + +// end catch_user_interfaces.h +// start catch_tag_alias_autoregistrar.h + +// start catch_common.h + +// start catch_compiler_capabilities.h + +// Detect a number of compiler features - by compiler +// The following features are defined: +// +// CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported? +// CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported? +// CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported? +// CATCH_CONFIG_DISABLE_EXCEPTIONS : Are exceptions enabled? +// **************** +// Note to maintainers: if new toggles are added please document them +// in configuration.md, too +// **************** + +// In general each macro has a _NO_ form +// (e.g. CATCH_CONFIG_NO_POSIX_SIGNALS) which disables the feature. +// Many features, at point of detection, define an _INTERNAL_ macro, so they +// can be combined, en-mass, with the _NO_ forms later. + +#ifdef __cplusplus + +# if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) +# define CATCH_CPP14_OR_GREATER +# endif + +# if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) +# define CATCH_CPP17_OR_GREATER +# endif + +#endif + +// We have to avoid both ICC and Clang, because they try to mask themselves +// as gcc, and we want only GCC in this block +#if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && !defined(__CUDACC__) +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic push" ) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic pop" ) + +# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) + +#endif + +#if defined(__clang__) + +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic push" ) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic pop" ) + +// As of this writing, IBM XL's implementation of __builtin_constant_p has a bug +// which results in calls to destructors being emitted for each temporary, +// without a matching initialization. In practice, this can result in something +// like `std::string::~string` being called on an uninitialized value. +// +// For example, this code will likely segfault under IBM XL: +// ``` +// REQUIRE(std::string("12") + "34" == "1234") +// ``` +// +// Therefore, `CATCH_INTERNAL_IGNORE_BUT_WARN` is not implemented. +# if !defined(__ibmxl__) && !defined(__CUDACC__) +# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) /* NOLINT(cppcoreguidelines-pro-type-vararg, hicpp-vararg) */ +# endif + +# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \ + _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"") + +# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wparentheses\"" ) + +# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wunused-variable\"" ) + +# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"" ) + +# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wunused-template\"" ) + +#endif // __clang__ + +//////////////////////////////////////////////////////////////////////////////// +// Assume that non-Windows platforms support posix signals by default +#if !defined(CATCH_PLATFORM_WINDOWS) + #define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS +#endif + +//////////////////////////////////////////////////////////////////////////////// +// We know some environments not to support full POSIX signals +#if defined(__CYGWIN__) || defined(__QNX__) || defined(__EMSCRIPTEN__) || defined(__DJGPP__) + #define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS +#endif + +#ifdef __OS400__ +# define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS +# define CATCH_CONFIG_COLOUR_NONE +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Android somehow still does not support std::to_string +#if defined(__ANDROID__) +# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING +# define CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Not all Windows environments support SEH properly +#if defined(__MINGW32__) +# define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH +#endif + +//////////////////////////////////////////////////////////////////////////////// +// PS4 +#if defined(__ORBIS__) +# define CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Cygwin +#ifdef __CYGWIN__ + +// Required for some versions of Cygwin to declare gettimeofday +// see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin +# define _BSD_SOURCE +// some versions of cygwin (most) do not support std::to_string. Use the libstd check. +// https://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/api/a01053_source.html line 2812-2813 +# if !((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \ + && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)) + +# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING + +# endif +#endif // __CYGWIN__ + +//////////////////////////////////////////////////////////////////////////////// +// Visual C++ +#if defined(_MSC_VER) + +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION __pragma( warning(push) ) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION __pragma( warning(pop) ) + +// Universal Windows platform does not support SEH +// Or console colours (or console at all...) +# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) +# define CATCH_CONFIG_COLOUR_NONE +# else +# define CATCH_INTERNAL_CONFIG_WINDOWS_SEH +# endif + +// MSVC traditional preprocessor needs some workaround for __VA_ARGS__ +// _MSVC_TRADITIONAL == 0 means new conformant preprocessor +// _MSVC_TRADITIONAL == 1 means old traditional non-conformant preprocessor +# if !defined(__clang__) // Handle Clang masquerading for msvc +# if !defined(_MSVC_TRADITIONAL) || (defined(_MSVC_TRADITIONAL) && _MSVC_TRADITIONAL) +# define CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +# endif // MSVC_TRADITIONAL +# endif // __clang__ + +#endif // _MSC_VER + +#if defined(_REENTRANT) || defined(_MSC_VER) +// Enable async processing, as -pthread is specified or no additional linking is required +# define CATCH_INTERNAL_CONFIG_USE_ASYNC +#endif // _MSC_VER + +//////////////////////////////////////////////////////////////////////////////// +// Check if we are compiled with -fno-exceptions or equivalent +#if defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND) +# define CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED +#endif + +//////////////////////////////////////////////////////////////////////////////// +// DJGPP +#ifdef __DJGPP__ +# define CATCH_INTERNAL_CONFIG_NO_WCHAR +#endif // __DJGPP__ + +//////////////////////////////////////////////////////////////////////////////// +// Embarcadero C++Build +#if defined(__BORLANDC__) + #define CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN +#endif + +//////////////////////////////////////////////////////////////////////////////// + +// Use of __COUNTER__ is suppressed during code analysis in +// CLion/AppCode 2017.2.x and former, because __COUNTER__ is not properly +// handled by it. +// Otherwise all supported compilers support COUNTER macro, +// but user still might want to turn it off +#if ( !defined(__JETBRAINS_IDE__) || __JETBRAINS_IDE__ >= 20170300L ) + #define CATCH_INTERNAL_CONFIG_COUNTER +#endif + +//////////////////////////////////////////////////////////////////////////////// + +// RTX is a special version of Windows that is real time. +// This means that it is detected as Windows, but does not provide +// the same set of capabilities as real Windows does. +#if defined(UNDER_RTSS) || defined(RTX64_BUILD) + #define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH + #define CATCH_INTERNAL_CONFIG_NO_ASYNC + #define CATCH_CONFIG_COLOUR_NONE +#endif + +#if !defined(_GLIBCXX_USE_C99_MATH_TR1) +#define CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER +#endif + +// Various stdlib support checks that require __has_include +#if defined(__has_include) + // Check if string_view is available and usable + #if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # define CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW + #endif + + // Check if optional is available and usable + # if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # define CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL + # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) + + // Check if byte is available and usable + # if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # include + # if __cpp_lib_byte > 0 + # define CATCH_INTERNAL_CONFIG_CPP17_BYTE + # endif + # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) + + // Check if variant is available and usable + # if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # if defined(__clang__) && (__clang_major__ < 8) + // work around clang bug with libstdc++ https://bugs.llvm.org/show_bug.cgi?id=31852 + // fix should be in clang 8, workaround in libstdc++ 8.2 + # include + # if defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) + # define CATCH_CONFIG_NO_CPP17_VARIANT + # else + # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT + # endif // defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) + # else + # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT + # endif // defined(__clang__) && (__clang_major__ < 8) + # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) +#endif // defined(__has_include) + +#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) +# define CATCH_CONFIG_COUNTER +#endif +#if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) && !defined(CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH) +# define CATCH_CONFIG_WINDOWS_SEH +#endif +// This is set by default, because we assume that unix compilers are posix-signal-compatible by default. +#if defined(CATCH_INTERNAL_CONFIG_POSIX_SIGNALS) && !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS) +# define CATCH_CONFIG_POSIX_SIGNALS +#endif +// This is set by default, because we assume that compilers with no wchar_t support are just rare exceptions. +#if !defined(CATCH_INTERNAL_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_WCHAR) +# define CATCH_CONFIG_WCHAR +#endif + +#if !defined(CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_CPP11_TO_STRING) +# define CATCH_CONFIG_CPP11_TO_STRING +#endif + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_NO_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_CPP17_OPTIONAL) +# define CATCH_CONFIG_CPP17_OPTIONAL +#endif + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_NO_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_CPP17_STRING_VIEW) +# define CATCH_CONFIG_CPP17_STRING_VIEW +#endif + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_VARIANT) && !defined(CATCH_CONFIG_NO_CPP17_VARIANT) && !defined(CATCH_CONFIG_CPP17_VARIANT) +# define CATCH_CONFIG_CPP17_VARIANT +#endif + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_BYTE) && !defined(CATCH_CONFIG_NO_CPP17_BYTE) && !defined(CATCH_CONFIG_CPP17_BYTE) +# define CATCH_CONFIG_CPP17_BYTE +#endif + +#if defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT) +# define CATCH_INTERNAL_CONFIG_NEW_CAPTURE +#endif + +#if defined(CATCH_INTERNAL_CONFIG_NEW_CAPTURE) && !defined(CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NEW_CAPTURE) +# define CATCH_CONFIG_NEW_CAPTURE +#endif + +#if !defined(CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED) && !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) +# define CATCH_CONFIG_DISABLE_EXCEPTIONS +#endif + +#if defined(CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_NO_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_POLYFILL_ISNAN) +# define CATCH_CONFIG_POLYFILL_ISNAN +#endif + +#if defined(CATCH_INTERNAL_CONFIG_USE_ASYNC) && !defined(CATCH_INTERNAL_CONFIG_NO_ASYNC) && !defined(CATCH_CONFIG_NO_USE_ASYNC) && !defined(CATCH_CONFIG_USE_ASYNC) +# define CATCH_CONFIG_USE_ASYNC +#endif + +#if defined(CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_NO_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_ANDROID_LOGWRITE) +# define CATCH_CONFIG_ANDROID_LOGWRITE +#endif + +#if defined(CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_NO_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_GLOBAL_NEXTAFTER) +# define CATCH_CONFIG_GLOBAL_NEXTAFTER +#endif + +// Even if we do not think the compiler has that warning, we still have +// to provide a macro that can be used by the code. +#if !defined(CATCH_INTERNAL_START_WARNINGS_SUPPRESSION) +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION +#endif +#if !defined(CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION +#endif +#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS +#endif +#if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS +#endif +#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS +#endif +#if !defined(CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS +#endif + +// The goal of this macro is to avoid evaluation of the arguments, but +// still have the compiler warn on problems inside... +#if !defined(CATCH_INTERNAL_IGNORE_BUT_WARN) +# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) +#endif + +#if defined(__APPLE__) && defined(__apple_build_version__) && (__clang_major__ < 10) +# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS +#elif defined(__clang__) && (__clang_major__ < 5) +# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS +#endif + +#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS +#endif + +#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) +#define CATCH_TRY if ((true)) +#define CATCH_CATCH_ALL if ((false)) +#define CATCH_CATCH_ANON(type) if ((false)) +#else +#define CATCH_TRY try +#define CATCH_CATCH_ALL catch (...) +#define CATCH_CATCH_ANON(type) catch (type) +#endif + +#if defined(CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_NO_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) +#define CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#endif + +// end catch_compiler_capabilities.h +#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line +#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) +#ifdef CATCH_CONFIG_COUNTER +# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ ) +#else +# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ ) +#endif + +#include +#include +#include + +// We need a dummy global operator<< so we can bring it into Catch namespace later +struct Catch_global_namespace_dummy {}; +std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy); + +namespace Catch { + + struct CaseSensitive { enum Choice { + Yes, + No + }; }; + + class NonCopyable { + NonCopyable( NonCopyable const& ) = delete; + NonCopyable( NonCopyable && ) = delete; + NonCopyable& operator = ( NonCopyable const& ) = delete; + NonCopyable& operator = ( NonCopyable && ) = delete; + + protected: + NonCopyable(); + virtual ~NonCopyable(); + }; + + struct SourceLineInfo { + + SourceLineInfo() = delete; + SourceLineInfo( char const* _file, std::size_t _line ) noexcept + : file( _file ), + line( _line ) + {} + + SourceLineInfo( SourceLineInfo const& other ) = default; + SourceLineInfo& operator = ( SourceLineInfo const& ) = default; + SourceLineInfo( SourceLineInfo&& ) noexcept = default; + SourceLineInfo& operator = ( SourceLineInfo&& ) noexcept = default; + + bool empty() const noexcept { return file[0] == '\0'; } + bool operator == ( SourceLineInfo const& other ) const noexcept; + bool operator < ( SourceLineInfo const& other ) const noexcept; + + char const* file; + std::size_t line; + }; + + std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ); + + // Bring in operator<< from global namespace into Catch namespace + // This is necessary because the overload of operator<< above makes + // lookup stop at namespace Catch + using ::operator<<; + + // Use this in variadic streaming macros to allow + // >> +StreamEndStop + // as well as + // >> stuff +StreamEndStop + struct StreamEndStop { + std::string operator+() const; + }; + template + T const& operator + ( T const& value, StreamEndStop ) { + return value; + } +} + +#define CATCH_INTERNAL_LINEINFO \ + ::Catch::SourceLineInfo( __FILE__, static_cast( __LINE__ ) ) + +// end catch_common.h +namespace Catch { + + struct RegistrarForTagAliases { + RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ); + }; + +} // end namespace Catch + +#define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \ + CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \ + CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION + +// end catch_tag_alias_autoregistrar.h +// start catch_test_registry.h + +// start catch_interfaces_testcase.h + +#include + +namespace Catch { + + class TestSpec; + + struct ITestInvoker { + virtual void invoke () const = 0; + virtual ~ITestInvoker(); + }; + + class TestCase; + struct IConfig; + + struct ITestCaseRegistry { + virtual ~ITestCaseRegistry(); + virtual std::vector const& getAllTests() const = 0; + virtual std::vector const& getAllTestsSorted( IConfig const& config ) const = 0; + }; + + bool isThrowSafe( TestCase const& testCase, IConfig const& config ); + bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ); + std::vector filterTests( std::vector const& testCases, TestSpec const& testSpec, IConfig const& config ); + std::vector const& getAllTestCasesSorted( IConfig const& config ); + +} + +// end catch_interfaces_testcase.h +// start catch_stringref.h + +#include +#include +#include +#include + +namespace Catch { + + /// A non-owning string class (similar to the forthcoming std::string_view) + /// Note that, because a StringRef may be a substring of another string, + /// it may not be null terminated. + class StringRef { + public: + using size_type = std::size_t; + using const_iterator = const char*; + + private: + static constexpr char const* const s_empty = ""; + + char const* m_start = s_empty; + size_type m_size = 0; + + public: // construction + constexpr StringRef() noexcept = default; + + StringRef( char const* rawChars ) noexcept; + + constexpr StringRef( char const* rawChars, size_type size ) noexcept + : m_start( rawChars ), + m_size( size ) + {} + + StringRef( std::string const& stdString ) noexcept + : m_start( stdString.c_str() ), + m_size( stdString.size() ) + {} + + explicit operator std::string() const { + return std::string(m_start, m_size); + } + + public: // operators + auto operator == ( StringRef const& other ) const noexcept -> bool; + auto operator != (StringRef const& other) const noexcept -> bool { + return !(*this == other); + } + + auto operator[] ( size_type index ) const noexcept -> char { + assert(index < m_size); + return m_start[index]; + } + + public: // named queries + constexpr auto empty() const noexcept -> bool { + return m_size == 0; + } + constexpr auto size() const noexcept -> size_type { + return m_size; + } + + // Returns the current start pointer. If the StringRef is not + // null-terminated, throws std::domain_exception + auto c_str() const -> char const*; + + public: // substrings and searches + // Returns a substring of [start, start + length). + // If start + length > size(), then the substring is [start, size()). + // If start > size(), then the substring is empty. + auto substr( size_type start, size_type length ) const noexcept -> StringRef; + + // Returns the current start pointer. May not be null-terminated. + auto data() const noexcept -> char const*; + + constexpr auto isNullTerminated() const noexcept -> bool { + return m_start[m_size] == '\0'; + } + + public: // iterators + constexpr const_iterator begin() const { return m_start; } + constexpr const_iterator end() const { return m_start + m_size; } + }; + + auto operator += ( std::string& lhs, StringRef const& sr ) -> std::string&; + auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&; + + constexpr auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef { + return StringRef( rawChars, size ); + } +} // namespace Catch + +constexpr auto operator "" _catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef { + return Catch::StringRef( rawChars, size ); +} + +// end catch_stringref.h +// start catch_preprocessor.hpp + + +#define CATCH_RECURSION_LEVEL0(...) __VA_ARGS__ +#define CATCH_RECURSION_LEVEL1(...) CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL2(...) CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL3(...) CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL4(...) CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL5(...) CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(__VA_ARGS__))) + +#ifdef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define INTERNAL_CATCH_EXPAND_VARGS(...) __VA_ARGS__ +// MSVC needs more evaluations +#define CATCH_RECURSION_LEVEL6(...) CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(__VA_ARGS__))) +#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL6(CATCH_RECURSION_LEVEL6(__VA_ARGS__)) +#else +#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL5(__VA_ARGS__) +#endif + +#define CATCH_REC_END(...) +#define CATCH_REC_OUT + +#define CATCH_EMPTY() +#define CATCH_DEFER(id) id CATCH_EMPTY() + +#define CATCH_REC_GET_END2() 0, CATCH_REC_END +#define CATCH_REC_GET_END1(...) CATCH_REC_GET_END2 +#define CATCH_REC_GET_END(...) CATCH_REC_GET_END1 +#define CATCH_REC_NEXT0(test, next, ...) next CATCH_REC_OUT +#define CATCH_REC_NEXT1(test, next) CATCH_DEFER ( CATCH_REC_NEXT0 ) ( test, next, 0) +#define CATCH_REC_NEXT(test, next) CATCH_REC_NEXT1(CATCH_REC_GET_END test, next) + +#define CATCH_REC_LIST0(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST1(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0) ) ( f, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST2(f, x, peek, ...) f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ ) + +#define CATCH_REC_LIST0_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST1_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0_UD) ) ( f, userdata, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST2_UD(f, userdata, x, peek, ...) f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ ) + +// Applies the function macro `f` to each of the remaining parameters, inserts commas between the results, +// and passes userdata as the first parameter to each invocation, +// e.g. CATCH_REC_LIST_UD(f, x, a, b, c) evaluates to f(x, a), f(x, b), f(x, c) +#define CATCH_REC_LIST_UD(f, userdata, ...) CATCH_RECURSE(CATCH_REC_LIST2_UD(f, userdata, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) + +#define CATCH_REC_LIST(f, ...) CATCH_RECURSE(CATCH_REC_LIST2(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) + +#define INTERNAL_CATCH_EXPAND1(param) INTERNAL_CATCH_EXPAND2(param) +#define INTERNAL_CATCH_EXPAND2(...) INTERNAL_CATCH_NO## __VA_ARGS__ +#define INTERNAL_CATCH_DEF(...) INTERNAL_CATCH_DEF __VA_ARGS__ +#define INTERNAL_CATCH_NOINTERNAL_CATCH_DEF +#define INTERNAL_CATCH_STRINGIZE(...) INTERNAL_CATCH_STRINGIZE2(__VA_ARGS__) +#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define INTERNAL_CATCH_STRINGIZE2(...) #__VA_ARGS__ +#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) +#else +// MSVC is adding extra space and needs another indirection to expand INTERNAL_CATCH_NOINTERNAL_CATCH_DEF +#define INTERNAL_CATCH_STRINGIZE2(...) INTERNAL_CATCH_STRINGIZE3(__VA_ARGS__) +#define INTERNAL_CATCH_STRINGIZE3(...) #__VA_ARGS__ +#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) (INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) + 1) +#endif + +#define INTERNAL_CATCH_MAKE_NAMESPACE2(...) ns_##__VA_ARGS__ +#define INTERNAL_CATCH_MAKE_NAMESPACE(name) INTERNAL_CATCH_MAKE_NAMESPACE2(name) + +#define INTERNAL_CATCH_REMOVE_PARENS(...) INTERNAL_CATCH_EXPAND1(INTERNAL_CATCH_DEF __VA_ARGS__) + +#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) decltype(get_wrapper()) +#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__)) +#else +#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) INTERNAL_CATCH_EXPAND_VARGS(decltype(get_wrapper())) +#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__))) +#endif + +#define INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(...)\ + CATCH_REC_LIST(INTERNAL_CATCH_MAKE_TYPE_LIST,__VA_ARGS__) + +#define INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_0) INTERNAL_CATCH_REMOVE_PARENS(_0) +#define INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_0, _1) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_1) +#define INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_0, _1, _2) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_1, _2) +#define INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_0, _1, _2, _3) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_1, _2, _3) +#define INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_0, _1, _2, _3, _4) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_1, _2, _3, _4) +#define INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_0, _1, _2, _3, _4, _5) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_1, _2, _3, _4, _5) +#define INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_0, _1, _2, _3, _4, _5, _6) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_1, _2, _3, _4, _5, _6) +#define INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_0, _1, _2, _3, _4, _5, _6, _7) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_1, _2, _3, _4, _5, _6, _7) +#define INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_1, _2, _3, _4, _5, _6, _7, _8) +#define INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9) +#define INTERNAL_CATCH_REMOVE_PARENS_11_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10) + +#define INTERNAL_CATCH_VA_NARGS_IMPL(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N + +#define INTERNAL_CATCH_TYPE_GEN\ + template struct TypeList {};\ + template\ + constexpr auto get_wrapper() noexcept -> TypeList { return {}; }\ + template class...> struct TemplateTypeList{};\ + template class...Cs>\ + constexpr auto get_wrapper() noexcept -> TemplateTypeList { return {}; }\ + template\ + struct append;\ + template\ + struct rewrap;\ + template class, typename...>\ + struct create;\ + template class, typename>\ + struct convert;\ + \ + template \ + struct append { using type = T; };\ + template< template class L1, typename...E1, template class L2, typename...E2, typename...Rest>\ + struct append, L2, Rest...> { using type = typename append, Rest...>::type; };\ + template< template class L1, typename...E1, typename...Rest>\ + struct append, TypeList, Rest...> { using type = L1; };\ + \ + template< template class Container, template class List, typename...elems>\ + struct rewrap, List> { using type = TypeList>; };\ + template< template class Container, template class List, class...Elems, typename...Elements>\ + struct rewrap, List, Elements...> { using type = typename append>, typename rewrap, Elements...>::type>::type; };\ + \ + template