简体   繁体   中英

How to resolve incubator module jdk.incubator.vector when running Java application

I am attempting to test the new Vector API introduced as an incubator module in JDK 16. For this, I have the following class:

import jdk.incubator.vector.FloatVector;
import jdk.incubator.vector.VectorSpecies;

public class Main {

    static final VectorSpecies<Float> SPECIES = FloatVector.SPECIES_256;

    static void vectorComputation(float[] a, float[] b, float[] c) {

        for (int i = 0; i < a.length; i += SPECIES.length()) {
            var m = SPECIES.indexInRange(i, a.length);

            var va = FloatVector.fromArray(SPECIES, a, i, m);
            var vb = FloatVector.fromArray(SPECIES, b, i, m);
            var vc = va.mul(va).
                    add(vb.mul(vb)).
                    neg();
            vc.intoArray(c, i, m);
        }
    }

    public static void main(String[] args) {
        float[] a = new float[]{1.0f, 3.0f, 2.0f};
        float[] b = {1.0f, -1.0f, 5.0f};
        float[] c = {1.0f, 6.0f, 1.0f};
        Main.vectorComputation(a, b, c);
        System.out.println(c);
    }
}

I was able to compile this with the following command:

javac Main.java --add-modules jdk.incubator.vector

However, when I try to run this I get the following error.

java Main --add-modules jdk.incubator.vector
Error: Unable to initialize main class Main
Caused by: java.lang.NoClassDefFoundError: jdk/incubator/vector/Vector

How would I go about resolving this class?

Anything after the main class is interpreted as arguments to your application. You need to rearrange the command to:

java --add-modules jdk.incubator.vector Main

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM