Using OpenMP in the Java language

Source: Internet
Author: User

From the middle of last year, began to learn Java, mainly to maintain the company's Java-written server software. At present, the server software encountered a problem, when downloading large files, if you download a lot of users at the same time, the server software work will be abnormal, some users can not download. Server hardware is mostly multi-core, so using OpenMP in the Java language can improve the performance of your server software.

Today, we tested it, and OpenMP is also available in the Java language. The following is a detailed test procedure:

1. Download Jomp1.0b.jar

Https://www2.epcc.ed.ac.uk/computing/research_activities/jomp/download/jomp1.0b.jar

2. Deploy Jomp1.0b.jar to the JDK's lib and append to Classpath.

It can also be used as an application class without appending to the system variable, but directly decompressing it.

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
for (i = 0; i <; i++)
{
System.out.println ("i =" + i);
}
}
}

4. Generate Java files from Jomp:

Java Jomp.compiler.Jomp testjavaopenmp. (This is not with the jomp extension)

Generates a Testjavaopenmp.java file.

5. Compile Testjavaopenmp.java:

Javac Testjavaopenmp.java. Generate Testjavaopenmp.class File

6. Run:

java-djomp.threads=2 TESTJAVAOPENMP

A 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

A 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

As you can see, the results are similar to the results in the C + + language. Whether it really runs on multicore requires a comparison of elapsed time to know.

Reference pages:

Https://www2.epcc.ed.ac.uk/computing/research_activities/jomp/download.html

Using OpenMP in the Java language

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.