To build/run MPI programs is a little bit stricky and need much effort to complete.
Thank you Nik for his exhautive instruction regarding this issue in Sun Studio Forum ^_^
1)Create a collection tool to build a MPI project Yes, it is also important to use MPI compilers to build MPI projects.
If you have "mpicc", "mpiCC" and "mpif90" in the same directory,
where "mpirun" is located, you can create a new "Tool Collection",
and use it to build MPI projects. Here is an example. I installed
MPI "Cluster Tools 8.1" in standard location: /opt/SUNWhpc/HPC8.1/sun
To use it from the Sun Studio IDE I created a new "Tool Collection":
- main menu Tools -> Options
this opens "Options" dialog
- select "C/C++", "Build Tools" tab
- press "Add ..." button (in the left bottom corner)
specify Tool Collection name, for example: MPISunStudioExpress
- set the fields:
Base Directory: /opt/SUNWhpc/HPC8.1/sun/bin
C Compiler: /opt/SUNWhpc/HPC8.1/sun/bin/mpicc
C++ Compiler: /opt/SUNWhpc/HPC8.1/sun/bin/mpiCC
Fortran Compiler: /opt/SUNWhpc/HPC8.1/sun/bin/mpif90
Make Command: /opt/SSX200903/SUNWspro/bin/dmake
- press "Ok" button
Now, select your MPI project, right click -> Properties
this opens "Project Properties" dialog
- select "Build" and change the "Tool Collection" - select "MPISunStudioExpress" from the list
- press "Ok" button
Now it should be able to build this project.
If you don't have "mpicc" and other necessary wrappers, you can download MPI "Cluster Tools 8.1"
from this page:
http://www.sun.com/software/products/clustertools/
2)Create script file to run a standard project
Yes, you are right, this is a hack (to use a shell script), and it may not work well in some cases.
First of all, I'm using a "Project with Existing Sources" - this type of projects gives more freedom.
Standard projects (like Sample projects) are not convenient (IMHO), because they use their own
makefiles, and it is hard to understand what is wrong is something goes wrong.
So, if you use a standard project, you can try to add this shell script to the project.
Here is an example:
1. Create a new shell script "mpirun.src.sh" in the same directory where your sources are.
You can do it in the IDE, or in terminal window:
echo '#!/bin/sh' >> mpirun.src.sh
echo 'mpirun -n 16 $*' >> mpirun.src.sh
2. Add these commands to the Makefile, so that it will build mpirun16.sh
# build build: .build-post pwd ls -l src cp mpirun.src.sh mpirun16.sh chmod 777 mpirun16.sh
3. Do "Clean and Build", make sure it was successful. It is possible that in your case
there is a "src" directory, so adjust the location of the source script accordingly.
(It is compulsory to fisnish this stage before commencing fourth stage)
4. As soon as the build is successful, specify this "mpirun16.sh" as Output for Linker in Project Properties (for standard project) or as Build Result (if you use a project with existing sources)
5. Insert the name of the executable in the list of arguments (in Project Properties. Run section).
Example:
dist/Debug/MPISunStudioExpress-Solaris-x86/mpi_prime_numbers_5 1 2
where "dist/.../mpi_prime_numbers_5" is the name of my executable, and "1 2" - its arguments.
I hope this solution is acceptable for you, though it looks very complicated :-)
The main problem with the existing projects is that one important field is missed in project properties: Command to Run. That's why we have to invent our own hacks to implement this feature.