WIN7 Building Java Parallel development environment MPJ Express (PART2)

Source: Internet
Author: User

In the previous section, we have successfully built a parallel development environment based on MPJ Express in Windows, and in this section we will write a simple program in eclipse to try out the environment we just built.


First create a project in Eclipse, as shown in.


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5D/13/wKioL1UhWFLAa9LKAAK_UbJ9Zl4750.jpg "style=" float: none; "title=" Je_08.png "alt=" Wkiol1uhwflaa9lkaak_ubj9zl4750.jpg "/>


Enter the project name mympjexpress or mpjexpress (you can take any) and click the "Finish" button.


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5D/17/wKiom1UhVxKACfVCAAKpHyv8K7Q926.jpg "style=" float: none; "title=" Je_09.png "alt=" Wkiom1uhvxkacfvcaakphyv8k7q926.jpg "/>


In the already created project, create a new class, as shown below.


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/5D/13/wKioL1UhWF7gn6KuAANw0kgQ-6s233.jpg "style=" float: none; "title=" Je_10.png "alt=" Wkiol1uhwf7gn6kuaanw0kgq-6s233.jpg "/>


Enter a name for the class, such as Hellworld or Mpjhelloworld (which can be taken), and then click the Finish button. As shown below


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/5D/17/wKiom1UhVx3TLItPAAKPOmnltQc782.jpg "style=" float: none; "title=" Je_11.png "alt=" Wkiom1uhvx3tlitpaakpomnltqc782.jpg "/>


Next in the edit area, enter the code

Import Java.net.inetaddress;import mpi.*;p ublic class Mpjhelloworld {public static void main (string[] args) throws Except ion{string [] tmps = MPI. Init (args); int me = MPI.COMM_WORLD.Rank (); int size = MPI.COMM_WORLD.Size (); inetaddress strip= inetaddress.getlocalhost (); System.out.println ("Thread No.:" + Me + ", IP:" +strip "), if (me = = 0) {System.out.println (" Count of Args: "+ tmps.length);        for (int i=0;i<tmps.length;i++) System.out.println ("args[" + i+ "]=" + tmps[i]); }mpi. Finalize ();}}

After entering the above code, the reader will find the compiler to prompt some errors, let us solve these problems.


First, join Mpj.jar. Mpj.jar is located in the MPJ Express installation directory under the Lib directory. To do this, first right-click the project "Mpjexpress" that you are editing, and in the context menu, select "Properties"

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/5D/13/wKioL1UhXTWhE2TpAAR6s6Le40s649.jpg "style=" float: none; "title=" Je_12.png "alt=" Wkiol1uhxtwhe2tpaar6s6le40s649.jpg "/>


In the pop-up Properties dialog box, select Java Build Path from the list on the left, as shown in, and then select Libraries in the tab on the right.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/5D/18/wKiom1UhW_qj5cfHAALdyTGvJAY836.jpg "style=" float: none; "title=" Je_13.png "alt=" Wkiom1uhw_qj5cfhaaldytgvjay836.jpg "/>


Click the "Add External JAR" button on the right, then select the directory where the Mpj.jar file is located, that is, under the Lib subdirectory of MPJ Express's installation directory, as shown below. Note that in our example, the installation directory for MPJ Express is

D:\mpj-v0_43\lib


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5D/18/wKiom1UhYVWR-Tz7AAL7bpwHCWs738.jpg "style=" float: none; "title=" Je_19.png "alt=" Wkiom1uhyvwr-tz7aal7bpwhcws738.jpg "/>


You can see that the original error has disappeared after the successful introduction of Mpj.jar, as shown below.


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/5D/18/wKiom1UhaIrwwfd7AAWHefoKAWo982.jpg "title=" je_22. PNG "alt=" wkiom1uhairwwfd7aawhefokawo982.jpg "/>


But the configuration has not completely ended. At this point, we select "Run" in the menu bar and select "Run Configurations" from the drop-down menu, as shown below


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/5D/13/wKioL1UhZWagGSdhAAP50FQL6dU761.jpg "title=" je_21. PNG "alt=" wkiol1uhzwaggsdhaap50fql6du761.jpg "/>


As shown, first select the item we are editing (for example, Mpjhelloworld) from the list on the left, and then add the following parameters to the VM arguments (the meanings of these parameters will be explained in detail later)

-jar D:/mpj-v0_43/lib/starter.jar
-NP 4


Then randomly enter several parameters to do the test in program argumesnts, for example: Arg1 Arg2 Arg3.

When the configuration is complete, click the Apply button.


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/5D/18/wKiom1UhYUKTyrgjAAOM2yEV8hM353.jpg "style=" float: none; "title=" Je_16.png "alt=" Wkiom1uhyuktyrgjaaom2yev8hm353.jpg "/>


Run the program, the output of the program is as follows:


MPJ Express (0.43) is started in the multicore configuration
Thread no.:0, ip:l138ijhzpx9flfm/192.168.1.103
Count of Args:3
Args[0]=arg1
Args[1]=arg2
Args[2]=arg3
Thread No.:1, ip:l138ijhzpx9flfm/192.168.1.103
Thread No.:3, ip:l138ijhzpx9flfm/192.168.1.103
Thread No.:2, ip:l138ijhzpx9flfm/192.168.1.103


Because MPJ Express is not very stable, it is easy to have problems like this or that in the configuration process. In PART3, we will analyze some possible problems and discuss the specific meanings of the above parameters.


Not finished, to be continued ...

This article from "White Horse Negative Gold" blog, reproduced please contact the author!

WIN7 Building Java Parallel development environment MPJ Express (PART2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.