37 MPI_Comm_size( comm, &
n_ranks );
38 MPI_Comm_rank( comm, &
my_rank );
80 for(
int itask=0; itask<ntasks; itask++){
81 int assigned_rank = itask%
n_ranks;
83 int i_local_task = itask/
n_ranks;
84 func(itask, i_local_task);
98 void communicate(
int ntasks, F func){
99 for(
int itask=0; itask<ntasks; itask++){
100 int i_local_task = itask/
n_ranks;
101 int assigned_rank = itask%
n_ranks;
102 bool is_assigned_rank = (
my_rank==assigned_rank);
103 func(itask, i_local_task, assigned_rank, is_assigned_rank, comm);
int my_rank
The rank of the current process within the MPI communicator.
Definition: task_group.hpp:18
A class that manages the distribution and execution of tasks in parallel using the MPI library...
Definition: task_group.hpp:14
int get_max_n_local_tasks(int n_tasks)
Calculate the maximum number of tasks assigned to any process.
Definition: task_group.hpp:67
int n_ranks
The total number of processes within the MPI communicator.
Definition: task_group.hpp:19
TaskGroup()
Default constructor for the TaskGroup class.
Definition: task_group.hpp:26
void execute_task(int ntasks, F func)
Execute the given task function for each assigned task.
Definition: task_group.hpp:79
int get_n_local_tasks(int n_tasks)
Calculate the number of tasks assigned to the current process.
Definition: task_group.hpp:57
int get_my_rank()
Get the rank of the current process within the MPI communicator.
Definition: task_group.hpp:47