Class SlurmNodeDiscovery

java.lang.Object
com.scivicslab.pojoactor.core.distributed.discovery.SlurmNodeDiscovery
All Implemented Interfaces:
NodeDiscovery

public class SlurmNodeDiscovery extends Object implements NodeDiscovery
Node discovery implementation for Slurm workload manager.

This implementation reads Slurm environment variables to discover nodes in the cluster:

  • SLURM_JOB_NODELIST - List of nodes allocated to the job
  • SLURM_PROCID - Process rank (0-based index)
  • SLURM_NTASKS - Total number of tasks

Usage Example


 #!/bin/bash
 #SBATCH --nodes=10
 #SBATCH --ntasks-per-node=1

 srun java -jar myapp.jar --port=8080
 

 public static void main(String[] args) {
     NodeDiscovery discovery = new SlurmNodeDiscovery();

     if (!discovery.isApplicable()) {
         System.err.println("Not running in Slurm environment");
         System.exit(1);
     }

     DistributedActorSystem system = new DistributedActorSystem(
         discovery.getMyNodeId(),
         discovery.getMyHost(),
         discovery.getMyPort()
     );

     // Register all remote nodes
     for (NodeInfo node : discovery.getAllNodes()) {
         if (!node.getNodeId().equals(discovery.getMyNodeId())) {
             system.registerRemoteNode(
                 node.getNodeId(),
                 node.getHost(),
                 node.getPort()
             );
         }
     }
 }
 
Since:
2.5.0
Author:
devteam@scivics-lab.com
  • Constructor Details

    • SlurmNodeDiscovery

      public SlurmNodeDiscovery()
      Constructs a SlurmNodeDiscovery with default port 8080.
    • SlurmNodeDiscovery

      public SlurmNodeDiscovery(int defaultPort)
      Constructs a SlurmNodeDiscovery with specified port.
      Parameters:
      defaultPort - the default port for actor communication
  • Method Details

    • isApplicable

      public boolean isApplicable()
      Description copied from interface: NodeDiscovery
      Checks if this discovery implementation is applicable to the current environment.
      Specified by:
      isApplicable in interface NodeDiscovery
      Returns:
      true if this discovery can be used in current environment
    • getMyNodeId

      public String getMyNodeId()
      Description copied from interface: NodeDiscovery
      Returns the unique identifier for the current node.
      Specified by:
      getMyNodeId in interface NodeDiscovery
      Returns:
      the node ID
    • getMyHost

      public String getMyHost()
      Description copied from interface: NodeDiscovery
      Returns the hostname or IP address for the current node.
      Specified by:
      getMyHost in interface NodeDiscovery
      Returns:
      the host address
    • getMyPort

      public int getMyPort()
      Description copied from interface: NodeDiscovery
      Returns the default port number for actor communication.

      This can be overridden by the user if needed.

      Specified by:
      getMyPort in interface NodeDiscovery
      Returns:
      the port number
    • getAllNodes

      public List<NodeInfo> getAllNodes()
      Description copied from interface: NodeDiscovery
      Returns information about all nodes in the cluster.

      This includes the current node and all remote nodes.

      Specified by:
      getAllNodes in interface NodeDiscovery
      Returns:
      list of all node information