Determine Number Of Threads Available¶
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
get_server_maximum_host_count()
.
1from agiparallel.client import *
2from agiparallel.infrastructure import *
3
4if __name__ == "__main__":
5 with ClusterJobScheduler("localhost") as client:
6 client.connect()
7 num_hosts = client.get_server_maximum_host_count()
8 print(f'There are {num_hosts} 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.
The value returned from get_server_maximum_host_count()
is calculated by summing the capacity of all agents
currently connected to the cluster.