Click or drag to resize

Determine number of threads available to job scheduler

Problem

You need to determine the maximum number of hosts available to the cluster.

Solution

Retrieve the maximum number of hosts available to the cluster by calling getMaximumHostCount().

Java
package stkparallelcomputingserversdk.howto;

import agi.parallel.client.ClusterJobScheduler;
import agi.parallel.client.IJobScheduler;

public class DetermineNumberOfThreadsAvailable {
    public static void main(String[] args) {
        try (IJobScheduler scheduler = new ClusterJobScheduler("localhost")) {
            scheduler.connect();

            int numHosts = scheduler.getMaximumHostCount();
            System.out.format("There are %d hosts available to the job scheduler.%n", numHosts);
        }

        /*
         * The output of the application should resemble:
         * There are 4 hosts available to the job scheduler.
         */
    }
}
Discussion

Knowing the maximum number of hosts available to the job scheduler is useful when partitioning a workload into tasks. As an example, for 100 units of work and 5 maximum hosts, submit 5 tasks and each task will be assigned 20 units. In the case of 20 available hosts, it may be better to submit 20 tasks and assign only 5 units of work to each.

For the cluster job scheduler, the value returned from getMaximumHostCount is calculated by summing the capacity of all agents currently connected to the cluster.

See Also

Other Resources

STK Parallel Computing Server 2.9 API for Java