I'm trying to see if I can use Chapel for writing parallel code for use in a Python-based climate model: https://github.com/CliMT/climt
I don't have any experience with Chapel, but it seems very promising for my use-case. I had a few questions about how to integrate Chapel code into my current workflow:
I know you can build importable .so
files, but can the compilation stop when the Cython file is generated? I can then include it into the distribution and use standard setuptools
to compile my project on Travis.
Can I pass numpy
arrays to a Python extension written in Chapel?
If answer to 2. is yes, and my computation is embarassingly parallel in one dimension of the array, is there an elegant way to express this paralellism in Chapel?
If I write Chapel code that works on multiple nodes and compile it to a Python extension, how do I run it? Can I use mpirun python my_code.py
kind of a command?
One of the most common languages in Python. Anyone interested in a job that uses Python will need to answer questions about the language in their job interview. One of the best ways to prepare for a Python interview is to study common questions and answers.
For most people, the technical questions an interviewer might ask in a Python interview might sound like a foreign language. In some respects, they would be right.
This Python exercise helps you learn Python using sets of detailed programming Questions from basic to advance. It covers questions on core Python concepts as well as applications of Python on various domains. How to get list of parameters name from a function in Python? How to Print Multiple Arguments in Python?
Unfortunately not currently. However, we do leave the generated .pxd and .py(x) files in the directory with the .so, so you could make use of those in the meanwhile (this wasn't a feature request we've considered, so if you felt motivated, definitely feel free to open an issue on our Github page: https://github.com/chapel-lang/chapel/issues).
For reference, we do this because the Cython compilation command is rather tricky. I had thought we printed the Cython command used with the chpl compilation flag --print-commands
, but that doesn't look to be the case (I'll make an issue for that).
You can pass 1 dimensional numpy arrays of known primitive types to Chapel from Python. We're hoping to add support for other numpy arrays soon (hopefully in 1.21, slated for March 2020)
This is definitely doable on arrays in Chapel - I would recommend using a forall
loop when traversing this dimension of your array for your computation, which will divide the indices in that dimension into a number of tasks determined by Chapel. (For those not familiar with forall
loops, this link gives a good overview of the concept)
For example:
forall x in arr.domain.dim(1) {
// traverses the first dimension of arr's domain in parallel
...
}
chpl_setup
function. Doing so will take care of distributing the Chapel code for you when you run your Python program.For example, you could write:
import MyChplLib
MyChplLib.chpl_setup(4)
...
to run your program with 4 locales (nodes).
I should probably mention that as of the 1.20 release, we don't have support for array arguments in multilocale libraries. We're still figuring out priorities for the 1.21 release, so feedback on how fast you want that would be super helpful!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With