GithubHelp home page GithubHelp logo

sdrave / charm4py Goto Github PK

View Code? Open in Web Editor NEW

This project forked from charmplusplus/charm4py

0.0 1.0 0.0 1.19 MB

Parallel Programming with Python and Charm++

Home Page: https://charm4py.readthedocs.io

License: Other

Python 100.00%

charm4py's Introduction

Charm4py

https://travis-ci.com/UIUC-PPL/charm4py.svg?branch=master http://readthedocs.org/projects/charm4py/badge/?version=latest

Charm4py (Charm++ for Python -formerly CharmPy-) is a distributed computing and parallel programming framework for Python, for the productive development of fast, parallel and scalable applications. It is built on top of Charm++, a C++ adaptive runtime system that has seen extensive use in the scientific and high-performance computing (HPC) communities across many disciplines, and has been used to develop applications that run on a wide range of devices: from small multi-core devices up to the largest supercomputers.

Please see the Documentation for more information.

Short Example

The following computes Pi in parallel, using any number of machines and processors:

from charm4py import charm, Chare, Group, Reducer, Future
from math import pi
import time

class Worker(Chare):

    def work(self, n_steps, pi_future):
        h = 1.0 / n_steps
        s = 0.0
        for i in range(self.thisIndex, n_steps, charm.numPes()):
            x = h * (i + 0.5)
            s += 4.0 / (1.0 + x**2)
        # perform a reduction among members of the group, sending the result to the future
        self.reduce(pi_future, s * h, Reducer.sum)

def main(args):
    n_steps = 1000
    if len(args) > 1:
        n_steps = int(args[1])
    mypi = Future()
    workers = Group(Worker)  # create one instance of Worker on every processor
    t0 = time.time()
    workers.work(n_steps, mypi)  # invoke 'work' method on every worker
    print('Approximated value of pi is:', mypi.get(),  # 'get' blocks until result arrives
          'Error is', abs(mypi.get() - pi), 'Elapsed time=', time.time() - t0)
    exit()

charm.start(main)

This is a simple example and demonstrates only a few features of Charm4py. Some things to note from this example:

  • Chares (pronounced chars) are distributed Python objects.
  • A Group is a type of distributed collection where one instance of the specified chare type is created on each processor.
  • Remote method invocation in Charm4py is asynchronous.

In this example, there is only one chare per processor, but multiple chares (of the same or different type) can exist on any given processor, which can bring flexibility and also performance benefits (like dynamic load balancing). Please refer to the documentation for more information.

Contact

We would like feedback from the community. If you have feature suggestions, support questions or general comments, please visit our forum or emails us at <[email protected]>, or

Main author at <[email protected]>

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.