Skip to main content

a simple python module to solve problem in a multiprocessing way.

Project description

mptrolley

a simple python module to solve problem in a multiprocessing way.

background

there are many jobs which are processed in batches. for example, in many computing tasks, you may need to run a same algorithm on many groups of different input data, and the "subproblems" are often irrelevant with each other. in this case, multiprocessing is a very simple and understandable way to accelerate. so we designed a very simple python module called mptrolley under the principle of KISS (Keep It Simple and Stupid).

terminology

problem and questions

in this passage, we define that a batched job is called a problem. in a single problem, there are may questions, and each question has a continuous numbering (begins from zero). we assume that you have already write a python function to solve a single question:

def question_function(question_index, common_context):
  ...

and we assume that you can solve your problem without any parallel in the following way:

common = ...
for i in range(question_count): # the questions should be numbered from 0 to (question_count-1)
  question_function(i, common)

in this case, mptrolley provides you a simple way to solve the problem faster with multiprocessing:

import mptrolley
common        = ...
process_count = ... # an interger to control the number of processes
mptrolley.solve_problem_with_multiprocessing(question_function, common, question_count, process_count)

the question list will be devided into process_count lists according to question_index % process_count. for some question qx and some process px, px will be used to solve qx if and only if qx.question_index % process_count == px.process_index.

install

  1. go https://github.com/GGN-2015/mptrolley/releases and download a .whl file.
  2. use pip install mptrolley-<version>-py3-none-any.whl to install the package into your local environment.

usage

import mptrolley

# define your own question function, it **MUST** have two parameters
#   question_index will be given a continuous integer index.
#   and common_context is the common information you may need during every question's solving procedure.
#   (there are many cases where we just don't need it.)
def question_function(question_index, common_context) -> None:
  ...

common        = ... # common information
process_count = ... # an interger to control the number of processes
mptrolley.solve_problem_with_multiprocessing(question_function, common, question_count, process_count)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mptrolley-0.0.1.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

mptrolley-0.0.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file mptrolley-0.0.1.tar.gz.

File metadata

  • Download URL: mptrolley-0.0.1.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for mptrolley-0.0.1.tar.gz
Algorithm Hash digest
SHA256 cad5ea6bb936e228cdc45a5b0bc1fc3fd7452bcd3ff7e60497052919a3485c4e
MD5 0bc1dc77686de5a0d46dfee0bc1aae93
BLAKE2b-256 3af0c1f80b3919247f628f9629bff21b4889fd59de837a7ef2c62e112a4169a8

See more details on using hashes here.

File details

Details for the file mptrolley-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: mptrolley-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for mptrolley-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9731212f06e422ef00e01fa61357bfc69ac2819ea9b20996f9b5d117b986b46a
MD5 83b1c0ab0b6975bcead4c685d6ebf2b4
BLAKE2b-256 e6c004a62352e281cb7b7739a787c53ce2b4f93d2deaaaadd9f3d60201f703a3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page