Since the middle of last year, I began to learn Java, mainly to maintain the server software compiled by the company using Java. Currently, this server software encounters a problem. If many users download large files at the same time, the server software may encounter exceptions, and some users cannot download the software. The server hardware is basically a multi-core processor. Therefore, using OpenMP in Java may improve the performance of server software.
Today, I tested that OpenMP can also be used in Java. The detailed test process is as follows:
1. Download jomp1.0b. jar
Http://www2.epcc.ed.ac.uk/computing/research_activities/jomp/index_1.html
2. Deploy jomp1.0b. jar under JDK lib and append it to CLASSPATH. The JDK version I used is 1.6.0 _ 19 (the latest JDK is 1.6.0 _ 20 ).
You can also directly decompress the package instead of adding it to the system variables and use it as an application class.
3. Write the test code TestJavaOpenMP. jomp. The extension must be jomp.
Import java. util .*;
Public class TestJavaOpenMP
{
Public static void main (String [] agrs)
{
Int I;
// Omp parallel
For (I = 0; I <20; I ++)
{
System. out. println ("I =" + I );
}
}
}
4. java files generated by jomp:
Java jomp. compiler. Jomp TestJavaOpenMP. (The jomp extension is not included here)
Generate the TestJavaOpenMP. java file.
5. Compile TestJavaOpenMP. java:
Java TestJavaOpenMP. java. Generate the TestJavaOpenMP. class File
6. Run:
Java-Djomp. threads = 2 TestJavaOpenMP
One running result:
I = 0
I = 10
I = 1
I = 2
I = 11
I = 12
I = 3
I = 13
I = 14
I = 4
I = 15
I = 5
I = 16
I = 6
I = 17
I = 7
I = 18
I = 8
I = 9
I = 19
Java-Djomp. threads = 4 TestJavaOpenMP
One running result:
I = 15
I = 0
I = 10
I = 5
I = 11
I = 1
I = 16
I = 2
I = 12
I = 6
I = 13
I = 14
I = 3
I = 17
I = 18
I = 19
I = 4
I = 7
I = 8
I = 9
The running result is similar to that in C/C ++. Check whether it is running on multiple cores. You need to compare the running time to know.
Reference webpage:
Http://www.hipecc.wichita.edu/jomp.html
Http://www2.epcc.ed.ac.uk/computing/research_activities/jomp/index_1.html