There for using MPICH2 from available .tar or .gz package is easier.
To download MPICH2 package goto here:http://www.mcs.anl.gov/research/projects/mpich2/downloads/index.php?s=downloads
or use here
Direct link for mpich2-1.3a2.tar.gz
change user to root or user super user privilege on every command
sudo -i
cd to the package location :
#cd /location
Then uncompress the package
#tar xzvf filename.tar.gz
go to the 'package root' :
#cd filename
then configure environment
#./configure
compile the package
# make
install the compiled package
#make install
Another small thing to do to start the mpich2 daemon:
insert the following 3 lines to the /usr/local/bin/mpdlib.py as root
import warnings
warnings.filterwarnings('ignore', '.*the md5 module is deprecated.*', DeprecationWarning)
warnings.filterwarnings('ignore', '.*the popen2 module is deprecated.*', DeprecationWarning)
file may look like this:
then, make the user specific configuration file:
cd $HOME
touch .mpd.confchmod 600 .mpd.conf
gedit .mpd.conf
add the following line to the newly created .mpd.conf file
MPD_SECRETWORD=secret
now its time to start the daemon process for MPICH2
use either:
mpd or mpd &
Now its time to enjoy your Parallel programming lessons...
here is a sample parallel program,
#include
#include
int main(int argc,char** argv)
{
int p_id,size;
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&p_id);
MPI_Comm_size(MPI_COMM_WORLD,&size);
printf("Hello from prpcess %d of %d \n",p_id,size);
MPI_Finalize();
return 0;
}
save this in a 'hpc.c' file.
compile the application
mpicc hpc.c -o hello
change access to executable of the output file
chmod +x ./hello
run the application
mpirun -np 4 ./hello
here -np 4 gives the number of processors for the application to be run on.
Final output of the above program will be something like this(warning message exists)
for further readings of parallel computing tutorials, please stay with my blog.
Discussion on any problems are welcome... :-)
regards,
chandpriyankara@engineering.com
include files here need to be as
ReplyDeletesdtio.h and
mpi.h
if there you experience an error message as bellow:
ReplyDelete"usr/local/bin/mpdboot:56: DeprecationWarning: The popen2 module is deprecated. Use the subprocess module. from popen2 import Popen4, Popen3, popen2 /usr/local/bin/mpdlib.py:15: DeprecationWarning: the md5 module is deprecated; use hashlib instead from md5 import new as md5new running mpdallexit on crimson LAUNCHED mpd on crimson via mpdboot_crimson (handle_mpd_output 399): from mpd on crimson, invalid port info: /usr/local/bin/mpdlib.py:8: DeprecationWarning: The popen2 module is deprecated. Use the subprocess module. import sys, os, signal, popen2, socket, select, inspect /usr/local/bin/mpdlib.py:15: DeprecationWarning: the md5 module is deprecated; use hashlib instead from md5 import new as md5new 38826 "
what you have to do is :
insert the following three lines at the beginning of /usr/local/bin/mpdlib.py:
import warnings
warnings.filterwarnings('ignore', '.*the md5 module is deprecated.*', DeprecationWarning) warnings.filterwarnings('ignore', '.*the popen2 module is deprecated.*', DeprecationWarning)
This comment has been removed by the author.
ReplyDeleteHere is another sample Parallel program:
ReplyDelete#include
#include
int main(int argc,char** argv)
{
int p_id,size;
int data;
MPI_Status status;
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&p_id);
MPI_Comm_size(MPI_COMM_WORLD,&size);
if(p_id==0)
{
int i =0;
for(i=1;i>%d\n",p_id,data);
}
MPI_Finalize();
return 0;
}
Here is another sample Parallel program:
ReplyDelete#include
#include
#include
int main(int argc, char *argv[]) {
int rank, size;
double a,b;
MPI_Status status;
MPI_Init(&argc, &argv); //Initialize MPI
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
a = (double)rank;
b = (double)rank;
if (size!=2){//Makes sure only two processors
if(rank==0){
fprintf(stderr ,"Run on two processors only ! \n");
}
MPI_Finalize();
exit(0);
}
if(rank==0){
printf("Processor0 ready to send \n");
MPI_Ssend(&a ,1 ,MPI_DOUBLE,1 ,111 ,MPI_COMM_WORLD);
printf("Processor0 send \n");
printf("Processor0 ready to receive \n");
MPI_Recv(&b ,1 ,MPI_DOUBLE,1 ,222 ,MPI_COMM_WORLD,&status);
printf("Processor0 received \n");
printf("#Processor0 got %f from processor1 \n" ,b);
}else {
printf("Processor1 ready to receive \n");
MPI_Recv(&b ,1 ,MPI_DOUBLE,0 ,111 ,MPI_COMM_WORLD,&status);
printf("Processor1 received \n");
printf("Processor1 ready to send \n");
MPI_Ssend(&a ,1 ,MPI_DOUBLE,0 ,222 ,MPI_COMM_WORLD);
printf("Processor1 send \n");
printf("#Processor1 got %f from processor0 \n",b);
}
MPI_Finalize();//Shut down and clean up MPI
return 0;
}
#include
ReplyDelete#include
int main()
{
int tid,i;
int n=10;
int a;
# pragma omp parallel for
for(i=0;i<n;i++)
{
a=a+1;
tid = omp_get_thread_num();
printf("<thread %d; a=%d \n",tid,a);
}
return 0;
}
compile using
gcc 1.c -o 1 -fopenmp
run ./1
#include
ReplyDelete#include
int main()
{
int tid,i;
int n=10;
int a;
# pragma omp parallel for
for(i=0;i<n;i++)
{
a=a+1;
tid = omp_get_thread_num();
printf("<thread %d; a=%d \n",tid,a);
}
return 0;
}
Compile using:
gcc 1.c -o 1 -fopenmp
Run:
./1
#include
ReplyDelete#include
#define N 1000
int main()
{
int i,sum = 0;
int a[N];
# pragma omp parallel for reduction (+:sum)
for(i=0;i<N;i++)
{
a[i] = i;
//tid = omp_get_thread_num();
sum = sum + a[i];
printf("Sum %d\n",sum);
}
printf("tSum %d\n",sum);
return 0;
}
#include
ReplyDelete#include
#define N 50
int main()
{
int tid,i,sum = 0;
int a[N];
int chunk = 10;
for(i=0;i<N;i++)
{
a[i] = i;
}
# pragma omp parallel for reduction (+:sum) schedule(static,chunk)
for(i=0;i<N;i++)
{
tid = omp_get_thread_num();
sum = sum + a[i];
printf("Thread %d; in %d ; Sum %d\n",tid,i,sum);
}
printf("tSum %d\n",sum);
return 0;
}
thank's info
ReplyDeleteit's really help me
http://murga-linux.com/puppy/viewtopic.php?t=63705
ReplyDeletetry mpich without installing anything
Got a better version to your send-receive program posted on Jun10:
ReplyDelete#include
#include
#include
int main(int argc, char *argv[])
{
int rank, size;
int sendval,recval=0;
MPI_Status status;
MPI_Init(&argc, &argv); //Initialize MPI
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
sendval = rank;
if (size!=2)
{ //Make sure only two processors are in the ring
if(rank==0)
{
fprintf(stderr,"Runs only on two processors ! \n");
}
MPI_Finalize();
//return 0;
exit(0);
}
printf("Process %d ready to send \n", rank);
MPI_Send(&sendval ,1 ,MPI_INT,((rank+1)%2) ,111 ,MPI_COMM_WORLD);
printf("Process %d has sent \n",rank);
printf("Process %d is now ready to receive \n",rank);
MPI_Recv(&recval ,1 ,MPI_INT,((rank+1)%2) ,111 ,MPI_COMM_WORLD,&status);
printf("Process %d has received \n",rank);
printf("Process %d got %d from process %d \n" ,rank, recval, (rank+1)%2);
MPI_Finalize();//Shut down and clean up MPI
return 0;
}
I /usr/local/bin/mpdlib.py does not exist
ReplyDeleteIs maybe somewhere else;
i've installed the MPICH2 and skip your warning step because i don't have phyton script that you mean,, and i have a problem like this
ReplyDeleteirvana@irvana:/media/New Volume/kuliah/Semester 7/PP/prak8$ sudo mpirun -np 4 ./mainn
[proxy:0:0@irvana] HYDU_create_process (./utils/launch/launch.c:69): execvp error on file ./mainn (Permission denied)
[proxy:0:0@irvana] HYDU_create_process (./utils/launch/launch.c:69): [proxy:0:0@irvana] HYDU_create_process (./utils/launch/launch.c:69): execvp error on file ./mainn (Permission denied)
execvp error on file ./mainn (Permission denied)
[proxy:0:0@irvana] HYDU_create_process (./utils/launch/launch.c:69): execvp error on file ./mainn (Permission denied)
what should i do? why the permission problem appear? did i miss sudo? :(
Big thanks.. :)
can i have some coding please? on main...
ReplyDeletehey even i'm getting the same error that Irval Ahadi had. please help with the error. the code is like below:
ReplyDelete#include
#include
int main(int argc,char** argv)
{
int p_id,size;
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&p_id);
MPI_Comm_size(MPI_COMM_WORLD,&size);
printf("Hello from prpcess %d of %d \n",p_id,size);
MPI_Finalize();
return 0;
}
Try moving the file to home directory in Linux and running terminal from there. I had the same problem and a friend suggested this and it worked for me.
Delete