Build a JAVA Parallel Development Environment MPJ Express (PART3) and win7mpj under Win7
In the first two parts, we set up a parallel development environment and tested the parallel development.
Build a JAVA Parallel Development Environment MPJ Express (PART1) http://blog.csdn.net/baimafujinji/article/details/45195159 under Win7
Build a JAVA Parallel Development Environment MPJ Express (PART2) in Win7)
Http://blog.csdn.net/baimafujinji/article/details/45195285
Of course, in this process, it is inevitable to have one or more problems. Let's discuss the problems that may arise.
Problem 1: After we build the development environment, we need to try the mpjdaemon Batch Processing Command. A possible problem at this time is: Port is not available, as shown in.
The problem is that the port is unavailable. Find the folder where the configuration file mpjexpress. conf is located and open it with notepad, as shown below. As shown in the preceding figure, port.1 = 10000 and port.2 = 10001 by default.
At this point, we only need to adjust the port, for example, to change it to the following result (of course, we should ensure that 8888 and 8889 are not occupied)
Save the file after modification. The problem is solved.
Question 2: notice that we saved the decompressed MPJ Express file under path D: \ mpj-v0_43 and assigned the environment variable MPJ_HOME to D: \ mpj-v0_43. What changes will happen if we save the file under path D: \ Program Files \ mpj-v0_43 and change the environment variable assignment accordingly?
This seems to be a completely non-problem, but once we do this, we will encounter the following situation when we use the mpjdaemon Batch Processing Command.
An error is returned!
Error: Unable to access jarfile D: \ Program
The system cannot access the corresponding jar file. But why? This is because the folder name of Program Files is invalid. The folder name is of course no problem in Windows, and it will not become a problem for most of our daily application development. However, in MPJ Express, the folder name cannot contain spaces. We all know that when entering an instruction in the console, spaces are usually used to separate operators and operands, or spaces can be considered meaningful, therefore, the batch processing commands in MPJ Express may cause confusion when parsing a path name with spaces. This is the problem. Therefore, you only need to slightly adjust the storage path of the MPJ Express file to eliminate such problems.
In addition, an easy way to view the current environment variable settings in the command line is to use the echo command, such
Problem 3: In addition to the console operation interface, the previous issue also appears in Eclipse. Recall that in PART2, we wrote this when setting the VM arguments parameter.
-Jar D: // mpj-v0_43/lib/starter. jar
-Np 4
We use an absolute path! More often, we are used to writing relative paths. In this case, you need to select "Window" in the menu bar and select "Preferences" from the drop-down menu, as shown below.
Select "String Substitution" from the list on the left and create a new "replace variable", as shown below.
After completing the preceding steps, we can use the relative path in the following format.
-Jar $ {MPJ_HOME}/lib/starter. jar
Note that the value of MPJ_HOME cannot be equal to a path with spaces. Otherwise, the following error occurs. The principle is the same as that of Question 2.
Question 4: Finally, let's discuss how to compile and run parallel programs under the command.
Edit the following code and save it to a file named HelloWorld. java.
Import mpi .*;
Public class HelloWorld {
Public static void main (String [] args) throws Exception
{
MPI. Init (args );
Int me = MPI. COMM_WORLD.Rank ();
Int size = MPI. COMM_WORLD.Size ();
System. out. println ("Hi from" + me + "of" + size + "\ n ");
MPI. Finalize ();
}
}
Example of compiling command: javac-cp.; % MPJ_HOME %/lib/mpj. jar HelloWorld. java
Example of Executing command: mpjrun. bat-np 4 HelloWorld a // where a is a specified parameter
The execution result is as follows.
This is the first scenario for executing parallel computing, that is, executing the MPJ Express program under multi-core configuration.
The number following mpjrun. bat-np is used to specify the number of cores.
Another scenario is to execute the MPJ Express program in the Cluster configuration.
Cluster configuration: If developers want to execute parallel JAVA programs on the distributed memory platform (including the cluster and computer network), they will sample this configuration scenario.
There are four options for this cluster configuration:
1) niodev-use Java NIO Sockets
2) mxdev-use Myrinet eXpress (MX) library for Myrinet networks
3) hybdev-cluster for multi-core processing
4) native-use a native MPI library (curretly only tested under MS-MPI for Windows)
Write a file named "machines" and specify all the host names or IP addresses used for concurrent execution.
Execution Method
For niodev, hybdev and mxdev
1) enable the protection: mpjdaemon. bat-boot
-You will need to manually execute this command on every machine that has enabled the daemon.
2) execution command example: mpjrun. bat-np 4-dev niodev HelloWorld
-- The device in-dev <device> can be niodev, hybdev, or mxdev.
3) Terminate the daemon command: mpjdaemon. bat-halt
For native
1) Compile JNI wrapper library (for details about the compilation method, see the help documentation of MPJ Express)
2) execution command example: mpjrun. bat-np 4-dev native HelloWorld
The full text is complete.