User Tools

Site Tools


howto:java

This is an old revision of the document!


Using Java

Example Java Script

Hello.java
/*
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
 */
/*
 * Copyright (c) 2011      Cisco Systems, Inc.  All rights reserved.
 *
 */
 
import mpi.*;
import java.net.InetAddress;
 
class Hello {
    static public void main(String[] args) throws MPIException {
        MPI.Init(args);
 
        int myrank = MPI.COMM_WORLD.getRank();
        int size = MPI.COMM_WORLD.getSize() ;
        InetAddress IP;
        try {
            IP = InetAddress.getLocalHost().getLocalHost();
            System.out.println("Hello world from rank " + myrank + " of " + size+" I'm running on "+IP.getLocalHost());
        }
            catch (Exception e) {
        }
        MPI.Finalize();
    }
}
$ module add openmpi/openmpi-1.10.0_gcc-4.7.2
$ mpijavac Hello.java
java_test.qsub
#!/bin/bash
#PBS -l select=2:ncpus=8:mpiprocs=8
#PBS -l walltime=00:01:00
#PBS -q netboot
#PBS -M YOUREMAILADDRESS
#PBS -m be
#PBS -V
#PBS -e /lustre/SCRATCH5/users/USERNAME/java_test/std_err.txt
#PBS -o /lustre/SCRATCH5/users/USERNAME/java_test/std_out.txt
#PBS -N JAVA_TEST
#PBS -mb
 
MODULEPATH=/opt/gridware/bioinformatics/modules:$MODULEPATH
source /etc/profile.d/modules.sh
 
module add openmpi/openmpi-1.10.0_gcc-4.7.2
 
NP=`cat ${PBS_NODEFILE} | wc -l`
 
cd /lustre/SCRATCH5/users/USERNAME/java_test
mpirun -np ${NP} -machinefile ${PBS_NODEFILE} java Hello
$ qsub java_test.qsub

Notes:

  • Replace USERNAME with your user name.
  • Replace YOUREMAILADDRESS with your email address.
/app/dokuwiki/data/attic/howto/java.1445606167.txt.gz · Last modified: 2021/12/09 16:42 (external edit)