MPI_Comm_spawn问题(临时解决方法,求高人解答)
最近用到MPI中的自动创建进程,我的程序要求是,在一个循环中,每次循环算法自己决定需要创建的进程个数,然后调用MPI_Comm_spawn创建进程。我的部分原始代码如下:
父进程部分代码
while( loop_times < MAX_LOOP )
{
loop_times++;
if( Change_Dim_Size )
{
Change_Dim_Size = false;
// select the dimension size of each subspace
rand_sub_dim = group_dim_size[ random_int_num() ];
group_size = dim / rand_sub_dim; // determine the number of child processes
}
// create child process
MPI_Comm_spawn(child, MPI_ARGV_NULL, group_size, MPI_INFO_NULL, 0, MPI_COMM_SELF, &intercomm, MPI_ERRCODES_IGNORE);
MPI_Intercomm_merge(intercomm, 0, &intracomm);
//broadcast the function number to every child process
MPI_Bcast(&funToRun[k], 1, MPI_INT, 0, intracomm );
//broadcast the size to every child process
MPI_Bcast( &rand_sub_dim, 1, MPI_INT, 0, intracomm );
//broadcast the size to every child process
MPI_Bcast( final_global_best, dim, MPI_DOUBLE, 0, intracomm );
// shuffle the permutation of all dimensions
random_shuffle( dim_index, dim_index + dim );
//MPI_Bcast( dim_index, dim, MPI_INT, 0, MPI_COMM_WORLD );
int *buffer = new int[ rand_sub_dim ];
double *send_population = new double[rand_sub_dim * Population_size];

博主在使用MPI的MPI_Comm_spawn功能时遇到问题,即在循环中动态创建进程,发现子进程虽执行完MPI_Finalize()但未完全结束,占用系统资源导致后续创建进程失败。尝试通过ulimit -n增大文件描述符限制和MPI_Comm_disconnect无果。为解决此问题,博主调整程序架构,预先创建最大数量的进程并在循环中启用所需的部分。希望能找到更好的解决方案。
&spm=1001.2101.3001.5002&articleId=30714997&d=1&t=3&u=5ba1555e0b7f41058144ac8f08102092)
4119

被折叠的 条评论
为什么被折叠?



