I want to use JOMP API (equivalent to OpenMP in C) but I met some problems:
This is the code I want to run:
import jomp.runtime.*;
public class Hello
{
public static void main (String argv[])
{
int myid;
//omp parallel private(myid)
{
myid = OMP.getThreadNum();
System.out.println("Hello from " + myid);
}
}
}
It is just an hello worl but I have a problem with the compiler. Please have a quick look at this page to understand:
http://www2.epcc.ed.ac.uk/computing/research_activities/jomp/download.html
But I can't, I do not understand how it works... I can only compile it with eclipse default compiler (I guess) and then I have only one thread!
I understand I have to compile this code (in a .jomp file) with
java jomp.compiler.Jomp MyFile
and then compile normally but I can't do this in ecplise neither in the terminal (I do not know how to install this compiler!)
ps: I use Ubuntu 12.04 on a Intel® Core™ i7-3610QM CPU # 2.30GHz × 8.
You just need to add the JOMP parameters to your launch configuration, this example can help you:
JOMP eclipse workaround
Related
I'm trying to get a "Hello World" like java project to be used in matlab. To start easy, I tried to make a simple netbeans project containing only 1 file with some basic functions to test.
With "HelloWorld.java" being:
public class HelloWorld{
public HelloWorld(){
setVersion(0);
}
public static void main(String[] args){
System.out.println("Hello World!");
}
public void setVersion(int aVersion){
if( aVersion < 0 ){
System.err.println("Improper version specified.");
}
else{
version = aVersion;
}
}
public int getVersion(){
return version;
}
private int version;
}
I built this in netbeans to create a .jar, but when trying to connect to it in matlab via the following code it cannot find HelloWorld when trying to make an object.
javaaddpath('C:\Users\<name>\Documents\Netbeans\HelloWorld\dist\HelloWorld.jar')
javaclasspath
myHelloObject = HelloWorld
It gives the following error
Undefined function or variable 'HelloWorld'.
Error in test (line 6)
myHelloObject = HelloWorld
However, when using "example jars" that I downloaded of the internet and connected them in matlab via the same method this seems to work, so I guess there is something wrong with the .jar generation.
What am I doing wrong? Thanks in advance.
Already found the answer: it had to do with Matlab using java 1.7 while the jar was generated in 1.8. Switching to another virtual machine (or generating the jar in another java version) solves the problems. https://nl.mathworks.com/matlabcentral/answers/130359-how-do-i-change-the-java-virtual-machine-jvm-that-matlab-is-using-on-windows
I have downloaded eclipse Luna. But the format printing is not working. let consider the simple code given below:
public class Test {
public static void main(String args[]) {
int a=4;
System.out.printf("%d",a);
}
}
It is showing error message below:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, int)
What may be the possible cause and solution?
Your Compiler compliance level might not be correct.
You can find it in Eclipse here:
Project > Properties > Java Compiler
Make sure it's set to 1.5 or higher.
i have got my answer from the comment of #Katja Christiansen. the comment has given below, as #Katja Christiansen not write the solution in asnswer for that i am wrriting it here let other can find that the problem has solved..
"Maybe project specific compiler settings are enabled? Open the properties of your Java project, select "Java Compiler" and check if "Enable project specific settings" is enabled and if the selected JDK differs from the Eclipse JDK settings. – Katja Christiansen "
after trying it, the printf has solved and it solved for all the existing project.
Thanks #Katja Christiansen for ur cooperation.
I'm using Eclipse Luna and the following main method runs for me:
public class StackOverflow {
public static void main(String[] args) {
int a = 4;
System.out.printf("%d", a);
}
}
Gives me the output of:
4
Try using the format method:
int a = 4;
System.out.format("%d", a);
I have the following helloworld class
class HelloWorld {
public static void main (String args[]) {
System.out.println("Hello World");
}
}
This is in an ASCII streamfile on the IFS called helloworld.java. When I try and compile this in QSH I get the following error
javac helloworld.java
helloworld.java:2: ')' expected
public static void main (String args[]) {
¢
I can't see a missing ')' in line 2. I suspect this is a codepage error because I've also never seen ¢ as placeholder on compile output.
Any ideas ?
Personally, I would suggest edit, compile, and test, your java code on a workstation (PC or Mac) and not trying to compile on the IBM i.
It's much more efficient that way.
Once you have code that works the way you want it to on your workstation, create a deployable JAR file and move that to the IBM i for further testing.
OK, again having some problems with caliper.
I am now running on Linux, trying to use the beta snapshot. I am attempting to run Google's caliper via commandline using just the jar. (Beta snapshot)
I do not have access to maven on this machine, and installing it is out of the question. I would just like to use a jar and, maybe once this is working, I can write up a script or something.
Here is what I am doing:
1. Using small example Benchmark:
import com.google.caliper.Benchmark;
public class Tutorial {
public static class Benchmark1 {
#Benchmark void timeNanoTime(int reps) {
for (int i = 0; i < reps; i++) {
System.nanoTime();
}
}
}
}
2. Compile with javac -cp caliper-1.0-beta-SNAPSHOT-all.jar Tutorial.java
3. (Attempt to) run with
java -cp caliper-1.0-beta-SNAPSHOT-all.jar com.google.caliper.runner.CaliperMain Tutorial.Benchmark1, receive message Benchmark class not found: Tutorial.Benchmark1.
I've tried to work this out from bits and pieces of information from various sources but I am really having a heck of a time with this. I would appreciate any input.
I believe you really need no maven, this should work.
Your own class doesn't get found and I think it's a problem of your classpath. As they're usually more problem with nested classes try simply
java -cp caliper-1.0-beta-SNAPSHOT-all.jar com.google.caliper.runner.CaliperMain Tutorial
If the message changes to something like "class contains no benchmarks", then you'll know more. If you insists on using nested class, you may need to call Tutorial$Benchmark1 (unprobable, but possible; java class naming is sick).
Please try also
java -cp caliper-1.0-beta-SNAPSHOT-all.jar Tutorial.Benchmark1
to see if your class lies on the classpath (the message should change to something like "no main method").
See also this older post.
I am trying to run this project called "hello user". I am new to Java, so wrote a simple program that takes your name, and displays "Hello ". while Running it, I get the following error:
run:
Error: Could not find or load main class hello.world.HelloWorld
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
But when I run file HelloWorld.java, it does it fine
I am doing this on Netbeans IDE 7.2
Rather than the coding error, it could be related to IDE. Since the "Run File" runs okay, but 'Run Project" does not, I believe you have something to set up in IDE itself. Right click the project, and select "Set is as Main", now run the project. I am just giving it a guess, may not help you. But it worth a shot.If it does not help, please paste your code too.
Your class needs a public static void main(String[] args) function. And moreover I suspect that the error could be in the package.
If you want your class in <main_package>.<sub_package>, The directory structure is
- main_package
- sub_package
-HelloWorld.java
And be sure to write your class like this.
package main_package.sub_package;
public class HelloWorld {
public static void main(String[] args){
System.out.println("Hello " + args[o]);
}
}
This is all due to the naming convention in Java
You need to run the .class file containing the public static void main(String[] args) method..
Here, your HelloWorld.java file might contain a class with main() method.. So, you can run it..
This is because, execution of any Java program starts with the invocation of main().. JVM needs an entry point to your code.. Which is main().. If it doesn't find one.. It will not run..
So, make sure, whatever class file you are running, it should have main() method..
UPDATE :- And for the starting point, may be you can skip using packages.. Just go with plain Java class without packages..
This message can also appear in Eclipse (Juno 4.2.2 in my case) and I have found two potential causes for it.
In my cases:
1. a DTD was in error. I deleted the file and that solved the issue*.
2. having cleaned the project, an external Jar that I had built externally had been deleted as could be seen from Properties -> Java Build Path -> Libraries.*
*Having solved either of the above issues, it was necessary to restart Eclipse
if you are using intellij idea then just rebuilding (clean and build) project might solve your problem . because intellij might be still trying to load the old classes which are not there or changed
Make sure you call looks like below:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("hello user");
}
}
To run a Java class in stand alone mode, public static void main(String[] args) is the entry method, which is must.