Parallel programming quick sort and parallel sum examples with Fork-join, RecursiveTask, RecursiveAction

Overview

QuickSortMultiThreading

Parallel programming quick sort and parallel sum examples with Fork-join, RecursiveTask<T>, RecursiveAction

Fork-Join

Fork-Join in Java is used to make use of the cores (brain of CPU that process the instructions) in an efficient manner. The fork/join splits a bigger task into smaller sub-tasks. These sub-tasks are then distributed among the cores. The results of these subtasks are then joined to generate the final result. The splitting of a task and joining the results imitates the divide-and-conquer algorithm. The fork is responsible for splitting the task, and join is responsible for merging the results of the task to generate the final result. fork-join.png
It is worth noting here that various threads that are responsible for the completion of the sub-tasks never sit idle. In fact, they implement the work-stealing algorithm, where an idle thread steals the work from those threads that are busy.

Fork-Join pseudocode

if (my portion of the work is small enough)
  do the work directly
else
  split my work into two pieces
  invoke the two pieces and wait for the results

QuickSort Algorithm

QuickSort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the given array around the picked pivot. There are many different versions of quickSort that pick pivot in different ways.

quick-sort.gif

QuickSort Algorithm Pseudocode

quickSort(arr, beg, end)
  if (beg < end)
    pivotIndex = partition(arr,beg, end)
    quickSort(arr, beg, pivotIndex)
    quickSort(arr, pivotIndex + 1, end)

partition(arr, beg, end)
  set end as pivotIndex
  pIndex = beg - 1
  for i = beg to end-1
  if arr[i] < pivot
    swap arr[i] and arr[pIndex]
    pIndex++
  swap pivot and arr[pIndex+1]
return pIndex + 1

Resources

https://www.geeksforgeeks.org/quick-sort-using-multi-threading/
https://www.baeldung.com/java-fork-join
https://www.tutorialspoint.com/java_concurrency/concurrency_fork_join.htm
https://docs.oracle.com/javase/tutorial/essential/concurrency/forkjoin.html
https://www.javatpoint.com/fork-join-in-java

You might also like...

MFP (Mathematic language For Parallel computing) Android library

MFPAndroLib This is MFP (Mathematic language For Parallel computing) Android library project. MFP is a novel scripting programming language designed a

Sep 5, 2022

Java-Programs---For-Practice is one of the Java Programming Practice Series By Shaikh Minhaj ( minhaj-313 ). This Series will help you to level up your Programming Skills. This Java Programs are very much helpful for Beginners.

Java-Programs---For-Practice is one of the Java Programming Practice Series By Shaikh Minhaj ( minhaj-313 ).  This Series will help you to level up your Programming Skills. This Java Programs are very much helpful for Beginners.

Java-Programs---For-Practice is one of the Java Programming Practice Series By Shaikh Minhaj ( minhaj-313 ). This Series will help you to level up your Programming Skills. This Java Programs are very much helpful for Beginners. If You Have any doubt or query you can ask me here or you can also ask me on My LinkedIn Profile

Nov 8, 2022

BurritoSpigot is a fork of TacoSpigot 1.8.9 that offers several enhancements to performance as well as bug fixes. while offer extra APIs and support for plugins

🌯 BurritoSpigot 🌯 BurritoSpigot is a fork of TacoSpigot 1.8.8 that offers several enhancements to performance as well as bug fixes. while offer extr

Dec 20, 2022

GregTech CE 1.12 fork continuing progression and development

GregTech CE: Unofficial This is a fork of GregTech Community Edition for MC 1.12.2 maintained by the Gregtech CEu development team. Welcome to GregTec

Jan 1, 2023

A fork of PowerNukkit.

A fork of PowerNukkit.

多语言文档 🤔 什么是PowerNukkitX ? PowerNukkitX是基于PowerNukkit的一个分支版本,由BlocklyNukkit小组负责开发维护,如遇任何问题可提交Issue反馈。 🧾 关于Nukkit核心 Nukkit是一款为Minecraft: Pocket Editio

Dec 30, 2022

A fork of PowerNukkit.

A fork of PowerNukkit.

多语言文档 / Need to switch languages? 🤔 什么是PowerNukkitX ? PowerNukkitX是基于PowerNukkit的一个分支版本,由BlocklyNukkit小组负责开发维护,如遇任何问题可提交Issue反馈。 注意事项: PowerNukkitX要求

Dec 30, 2022

fork of autoGG for fabric to pay respect to Techno after games.

AutoTechno Description: This mod is a tribute to the youtuber Technoblade and to their family which takes on a new spin to the usual auto gg mods by i

Jul 23, 2022

FIDO2(WebAuthn) server officially certified by FIDO Alliance and Relying Party examples.

FIDO2(WebAuthn) server officially certified by FIDO Alliance and Relying Party examples.

Overview FIDO (Fast IDentity Online) is an open standard for online authentication. It is designed to solve the password problems stemming from a lot

Jan 5, 2023

Spring GraphQL examples using Netflix DGS, GraphQL Java and Spring GraphQL

spring-graphql-sample Spring GraphQL examples using the following frameworks and libraries: Netflix DGS(Domain Graph Service) framework Spring GraphQL

Dec 20, 2022
Owner
Güven TUNCAY
Güven TUNCAY
Tarea POO: Nóminas -> Implementing comparable sort

Tarea POO: Nóminas -> Implementing comparable sort

Teodoro Dawn 3 Mar 13, 2022
This app is simple and awesome notepad. It is a quick notepad editing experience when writing notes,emails,message,shoppings and to do list.

This app is simple and awesome notepad. It is a quick notepad editing experience when writing notes,emails,message,shoppings and to do list.It is easy to use and enjoy hassle free with pen and paper.

Md Arif Hossain 1 Jan 18, 2022
Discourse-java is a platform where users can freely discuss on topics they want to, and like-minded people can join in and contribute

Discourse is the 100% open source discussion platform built for the next decade of the Internet. Use it as a: mailing list discussion forum long-form

Infosys Ltd 16 Oct 19, 2022
Welcome to the EHS robotics club's GitHub repository, this will also be used as our primary community center and means of communication. Also be sure to join our remind for on the go updates @EHSFTC21

NOTICE This repository contains the public FTC SDK for the Ultimate Goal (2020-2021) competition season. Formerly this software project was hosted her

null 5 Feb 25, 2022
Doing red/green/refactor with quick and visual feedback loop on your Nanoleaf

nanoleaf-intellij-plugin Want fancy coloured and visual quick feedback for your tests? Install the Nanoleaf IntelliJ plugin. The plugin listen to your

Baptiste Lecocq 5 Dec 27, 2022
CVE-2021-44228 - Apache log4j RCE quick test

Build ./build.sh Start log4j RCE Server ./start-log4j-rce-server.sh Test Run java -cp log4j-rce-1.0-SNAPSHOT-all.jar log4j Check if you get logs in ha

Jeffrey Li 3 Feb 1, 2022
A near-real-time Mesh Join Algorithm Implementation provided with a Complete Data warehouse for METRO

Mesh Join Algorithm and Data Warehouse A complete Mesh-Join Algorithm Implementation as provided in the paper R-MESHJOIN . This is demonstrated by the

null 3 Aug 11, 2022
Java library allowing for quick development of Discord bots

Discord-Bot-Library Java library that acts as an abstraction of Discord4J, allowing for quick development of Discord bots The goal for this project wa

null 20 Apr 20, 2022
A Minecraft Plugin For 1.8.8 - 1.19.2 For Giving A Player A Custom Item On Join Which Executes A Command On Right Click

PixelPlayz Custom Item A Minecraft Plugin For 1.8.8 - 1.19.2 For Giving A Player A Custom Item On Join Which Executes A Command On Right Click Install

null 2 Sep 9, 2022
Programming Services and Processes - 04 Secure Programming Techniques

Programación de Servicios y Procesos - 04 Técnicas de Programación Segura Tema 04. Técnicas de Programación segura. Curso 2021/2022. Contenidos Introd

José Luis González Sánchez 5 Dec 27, 2022