Git Product home page Git Product logo

bf-job-system's Introduction

BluFedora Job System Library

This is a C++17 library for handling of Tasks / Jobs in a multi-threaded environment.

Examples

Minimal Example

#include "concurrent/job_api.hpp"

#include <cassert>
#include <iostream>

static constexpr int k_DataSize = 100000;

static int s_ExampleData[k_DataSize] = {};

// Print the first 20 items for brevity
static void printFirst20Items()
{
  for (int i = 0; i < 20; ++i)
  {
    std::printf("data[%i] = %i\n", i, s_ExampleData[i]);
  }
}

int main()
{
   Job::Initialize(Job::MemRequirementsForConfig({}));

  // Initialize Dummy Data
  for (int i = 0; i < k_DataSize; ++i)
  {
    s_ExampleData[i] = i;
  }

  std::printf("Before:\n");
  printFirst20Items();

  auto* t = Job::ParallelFor(
   s_ExampleData, 
   k_DataSize, 
   Job::CountSplitter{6}, 
   [](int* data, std::size_t data_size) {
     for (std::size_t i = 0; i < data_size; ++i)
     {
       data[i] = data[i] * 5;
     }
   });

  Job::TaskSubmit(t);

  Job::WaitOnTask(t);

  std::printf("After:\n");
  printFirst20Items();

  // Check that the jobs finished working on all items.
  for (int i = 0; i < k_DataSize; ++i)
  {
    assert(s_ExampleData[i] == i * 5);
  }

  Job::Shutdown();

  return 0;
}

Architecture

Task

A Task is a single unit of work that can be scheduled by the Job System. Each Task has a total sizeof of 128bytes (2 * hardware interference size) with some of the bytes taken by essential bookkeeping date then the rest used for user storage.

A Tasks can be added as a child of another task, this means that when you wait on the parent Task then it will wait for all child Tasks as well.

Queues

A Queue hold a list of Tasks waiting to be executed. There are four different types of queues.

  • MAIN This queue has a guarantee that the task will be run on the main thread.
  • NORMAL Slightly lower priority than 'QueueType::HIGH'.
  • WORKER This queue has a guarantee that the task will never be run on the main thread.

Dependencies

  • C++ Standard Library (C++17 or above)
  • PCG Random

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.