0
votes

First of all apologies if I am making any mistake or asking a very basic question as I am totally new to python let alone MPI.

Problem

I am trying to run a MPI program in Python, I have researched while surfing the internet and found out that I had to install Python and Anaconda first. I installed it and after that I installed Microsoft MPI and then I opened Anaconda Command Prompt and installed mpi4py library using following command,

conda install mpi4py

It worked well till now. But now I have to run a small HelloWorld example in my Python environment using mpi4py library. Below is my program,

from mpi4py import MPI
import sys

size = MPI.COMM_WORLD.Get_size()
rank = MPI.COMM_WORLD.Get_rank()
name = MPI.Get_processor_name()

sys.stdout.write(
    "Hello, World! I am process %d of %d on %s.\n"
% (rank, size, name))

Now i am totally clueless where to write this program? Should I write it on Anaconda Command Prompt? Should I open Jupyter Notebook and write it down there or should i use some IDE like PyCharm to run this program? Then, I want to execute this program using following command,

$mpirun -np 4 ./helloworld

I am running this on my local machine but just for testing purpose i want to assign it to 4 different threads.

I know i may have asked silly things but I apologize. I am just a beginner at this and I hope you all can help me as always.

1
How do you normally run a python program? For starters, put mpirun -np 4 before that. - Zulan
As you do not have a shebang at the first line of your code, you should add the python command interpreter before helloworld. Also, you may want to save your python program under the name helloworld.py (although it is not compulsory). Your command then reads mpirun -np 4 python ./helloworld.py. Any IDE or text editor will do the job to create this last file. - jcgiret

1 Answers

0
votes

You can use any code editor or an IDE to write your code but let the IDE or Code editor know tht you wanna execute the code using Anaconda distribution of Python. I personally use Visual Studio Code to run my Anaconda Distribution of python.