{"id":22871797,"url":"https://github.com/fcf-framework/fcfparallel","last_synced_at":"2025-06-13T22:33:52.762Z","repository":{"id":267705217,"uuid":"902089226","full_name":"fcf-framework/fcfParallel","owner":"fcf-framework","description":"CPP header library for CPU/GPU parallel computing uses native compiler and OpenCL","archived":false,"fork":false,"pushed_at":"2025-01-19T07:34:42.000Z","size":301,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-06T17:39:51.869Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fcf-framework.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-11T22:13:53.000Z","updated_at":"2025-01-19T07:34:43.000Z","dependencies_parsed_at":"2025-01-09T04:39:50.180Z","dependency_job_id":"c6f594f8-8423-41d2-bed2-69921f2c8a4f","html_url":"https://github.com/fcf-framework/fcfParallel","commit_stats":null,"previous_names":["fcf-framework/fcfparallel"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fcf-framework%2FfcfParallel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fcf-framework%2FfcfParallel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fcf-framework%2FfcfParallel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fcf-framework%2FfcfParallel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fcf-framework","download_url":"https://codeload.github.com/fcf-framework/fcfParallel/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246465219,"owners_count":20781919,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-13T13:30:56.401Z","updated_at":"2025-03-31T11:45:08.010Z","avatar_url":"https://github.com/fcf-framework.png","language":"C++","readme":"## C++11 fcfParallel library for parallel calculations \n\n\u003ca name=\"short_description\"\u003e\u003c/a\u003e\n### Brief description\n\nC++11 header library for CPU/GPU parallel computing uses native compiler and OpenCL.\n\n### Attention! Cloning the library with the option --recursive\n\n**Example:**\n\n```bash\ngit clone --recursive https://github.com/fcf-framework/fcfParallel.git\n```\n\n### Fast start. Simple example\n\nThe simple example of overlaying blur in a BMP file. The example is available in the repository https://github.com/fcf-framework/fcfParallelExamples.git\n\n**impl.cpp file**\n\nSince the library is implemented in the form of header files, first you need to announce its implementation. \nTo do this, you need to connect the header file `fcfParallel/parallel.hpp` with the declared macro `FCF_PARALLEL_IMPLEMENTATION` (only for fcfParallel library) or `FCF_IMPLEMENTATION` (for all libraries).\nIt is advisable to do this in a separate file so as not to reassemble each time.\n\n```c++\n#define FCF_IMPLEMENTATION\n#include \u003cfcfImage/image.hpp\u003e\n#include \u003cfcfParallel/parallel.hpp\u003e\n```\n\n**main.cpp file**\n\nWe now proceed to the main programm.\n\n*Declaring a handler function*\n\nThe parallel computation subroutine is declared the macro FCF_PARALLEL_UNIT. The first parameter is the name of the unit, the second is an options (JS/JSON object) and the third will be the code for the implementation of the action.\n\nThe subroutine should contain a main function called FCF_PARALLEL_MAIN. The first argument of this function should be a pointer to the `FCFParallelTask` structure, which contains progress information. The rest of the argument is set by the developer.\n\nWhen transferring arguments by pointer from the main program to `FCF_PARALLEL_MAIN`, it is necessary to use the macro `FCF_PARALLEL_GLOBAL` when declaring them, which is analogous to the specificator `__global__` of the OpenCL compiler.\n\n*Launching parallel computing*\n\nTo run parallel calculations, the `fcf:::Parallel::Executor` object is used.\n\nTo perform the action, call the operator() method.\n\nThe first argument is a reference to the object `fcf:::Parallel::Call`, which contains action parameters. The remaining arguments correspond to the 1-N arguments of the `FCF_PARALLEL_MAIN` function.\n\nTransfer of arguments to operator() method:\n\n1. The transfer of the argument by value is done simply by transferring the value.\n\n2. If the argument of the function `FCF_PARALLEL_MAIN` is a pointer and does not require a calculation result, then you need to use the function `fcf:::Parallel:::refArg` to transfer data. The source data can be either an pointer or an object `std::vector`.\n\n3. If the argument is a pointer in the memory of which the result of the calculation is recorded, then the function `fcf::::Parallel:::refArg` should contain the following parameters when transmitting the argument:\n\n\t```\n\tfcf::Parallel::refArg(\n\t  outputRGB,\n\n\t  // Indicates that after performing calculations,\n\t  // you need to unload the result\n\t  fcf::Parallel::ArgUpload(true),\n\n\t  // When enabling upload, you must specify\n\t  // the split parameter.\n\t  // This parameter indicates that the data during unloading is divided\n\t  // between devices, and their size corresponds to the number of iterations.\n\t  fcf::Parallel::ArgSplit(fcf::Parallel::PS_FULL),\n\n\t  // Number of elements per iteration\n\t  fcf::Parallel::ArgSplitSize(3)\n    )\n\t```\n\nThe example of the program itself is below.\n\n```c++\n#include \u003ciostream\u003e\n#include \u003cfcfImage/image.hpp\u003e\n#include \u003cfcfParallel/parallel.hpp\u003e\n\n//\n// Pixel processing function performed on CPU/GPU\n//\nFCF_PARALLEL_UNIT(\n    blur,\n    {},\n    void FCF_PARALLEL_MAIN(const FCFParallelTask* a_task,\n                           int a_blur,\n                           int a_width,\n                           int a_height,\n                           FCF_PARALLEL_GLOBAL const char* a_source,\n                           FCF_PARALLEL_GLOBAL char* a_result) {\n      int offset = a_task-\u003elowIndex * 3;\n      int y = a_task-\u003elowIndex / a_width;\n      int x = a_task-\u003elowIndex % a_width;\n      int begby = max(y - a_blur, 0);\n      int endby = min(y + a_blur + 1, a_height);\n      int begbx = max(x - a_blur, 0);\n      int endbx = min(x + a_blur + 1, a_width);\n      int c     = (endby - begby) * (endbx - begbx);\n\n      for(int channel = 0; channel \u003c 3; ++channel) {\n        int value = 0;\n        for(int by = begby; by \u003c endby; ++by) {\n          for(int bx = begbx; bx \u003c endbx; ++bx) {\n            int bRawIndex = (by * a_width + bx) * 3;\n            value += (int)(unsigned char)a_source[bRawIndex + channel];\n          }\n        }\n        a_result[offset + channel] = (char)(value / c);\n      }\n    }\n)\n\nvoid printHelp(){\n  std::cout \u003c\u003c \"An example application illustrating the use of fcfParallel\" \u003c\u003c std::endl;\n  std::cout \u003c\u003c \"  Application launch format: parallel-example-001-blur SOURCE_BMP_FILE OUTPUT_BMP_FILE\" \u003c\u003c std::endl;\n  std::cout \u003c\u003c \"  Options:\" \u003c\u003c std::endl;\n  std::cout \u003c\u003c \"    SOURCE_BMP_FILE - Source BMP file.\" \u003c\u003c std::endl;\n  std::cout \u003c\u003c \"    OUTPUT_BMP_FILE - Resulting BMP file with the blur effect applied.\" \u003c\u003c std::endl;\n}\n\nint main(int a_argc, char* a_argv[]){\n  //\n  // Processing command line arguments\n  std::string sourceFilePath;\n  std::string outputFilePath;\n  for(int i = 1; i \u003c a_argc; ++i) {\n    if (!std::strcmp(a_argv[i], \"-h\") || !std::strcmp(a_argv[i], \"--help\")) {\n      printHelp();\n      return 0;\n    } else if (sourceFilePath.empty()) {\n      sourceFilePath = a_argv[i];\n    } else if (outputFilePath.empty()) {\n      outputFilePath = a_argv[i];\n    }\n\n  }\n  if (sourceFilePath.empty() || outputFilePath.empty()) {\n    std::cout \u003c\u003c \"Incorrent command line parameters. Use --help option for got help.\" \u003c\u003c std::endl;\n    return 1;\n  }\n\n  //\n  // Loading BMP image from file\n  std::vector\u003cchar\u003e sourceRGB;\n  size_t            sourceRGBWidth;\n  size_t            sourceRGBHeight;\n  try {\n    fcf::Image::loadRGBFromBmpFile(sourceFilePath, sourceRGB, sourceRGBWidth, sourceRGBHeight);\n  } catch(std::exception\u0026 e){\n    std::cerr \u003c\u003c \"Invalid load BMP file: \" \u003c\u003c e.what() \u003c\u003c std::endl;\n    return 1;\n  }\n\n  // Result image\n  std::vector\u003cchar\u003e outputRGB(sourceRGB.size());\n\n  //The object that will contain debugging information\n  fcf::Union state;\n\n  //\n  // Performing parallel calculations\n  try {\n    // Object initialization\n    fcf::Parallel::Executor executor;\n    executor.initialize();\n\n    fcf::Parallel::Call call;\n    // Unit name to execute declared macro FCF_PARALLEL_UNIT\n    call.name = \"blur\";\n    // Number of iterations\n    call.size = sourceRGBWidth * sourceRGBHeight;\n    // Specify the object in which you will need to record debugging information\n    call.state = \u0026state;\n\n    // Running parallel computing\n    executor(call,\n             (unsigned int)5,\n             (unsigned int)sourceRGBWidth,\n             (unsigned int)sourceRGBHeight,\n             fcf::Parallel::refArg(sourceRGB),\n             fcf::Parallel::refArg(outputRGB,\n                                   fcf::Parallel::ArgSplit(fcf::Parallel::PS_FULL),\n                                   fcf::Parallel::ArgUpload(true),\n                                   fcf::Parallel::ArgSplitSize(3)\n                                  )\n             );\n  } catch(std::exception\u0026 e) {\n    std::cerr \u003c\u003c \"Error in performing parallel calculations: \" \u003c\u003c e.what() \u003c\u003c std::endl;\n    return 1;\n  }\n\n  //\n  // Record the result in a BMP file\n  try {\n    fcf::Image::writeRGBToBmpFile(outputFilePath, outputRGB, sourceRGBWidth, sourceRGBHeight);\n  } catch(std::exception\u0026 e){\n    std::cerr \u003c\u003c \"Invalid write BMP file: \" \u003c\u003c e.what() \u003c\u003c std::endl;\n    return 1;\n  }\n\n  //\n  // Displaying debugging information\n  std::cout \u003c\u003c \"Time spent on implementation: \" \u003c\u003c ((double)state[\"duration\"]/(1000*1000*1000)) \u003c\u003c \" sec\" \u003c\u003c std::endl;\n  std::cout \u003c\u003c \"Actions performed on the following devices: \" \u003c\u003c std::endl;\n  for(fcf::Union\u0026 dev : state[\"devices\"]) {\n    std::cout \u003c\u003c \"    Engine: \"\u003c\u003c dev[\"engine\"] \u003c\u003c \"; Device: \" \u003c\u003c dev[\"device\"] \u003c\u003c std::endl;\n  }\n\n  return 0;\n}\n```\n\n**CMakeLists.txt file (Build)**\n\nThe build parameters are presented on the basis of CMake.\n\nIn order to build this example, you will need to link and include OpenCL. (https://github.com/KhronosGroup/OpenCL-SDK).\n\n ```cmake\nfind_package(OpenCL REQUIRED)\ninclude_directories(${OpenCL_INCLUDE_DIR})\ninclude_directories(${CMAKE_SOURCE_DIR}/libraries)\n\nadd_executable(\"blur\" impl.cpp main.cpp)\ntarget_link_libraries(\"blur\" ${OpenCL_LIBRARY})\n ```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffcf-framework%2Ffcfparallel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffcf-framework%2Ffcfparallel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffcf-framework%2Ffcfparallel/lists"}