⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dynamic_server.c

📁 动态进程管理的MPI的服务端设计。。。。。。
💻 C
字号:
/* manager */
#include "mpi.h"
#include <stdio.h>
#include <string.h>


int main(int argc, char *argv[])
{
	int world_size, universe_size, *universe_sizep, flag;

	MPI_Comm everyone; /* intercommunicator */

	char *worker_program;

	MPI_Init(&argc, &argv);

	MPI_Comm_size(MPI_COMM_WORLD, &world_size);

	//if (world_size != 1) error("Top heavy with management");

	MPI_Comm_get_attr(MPI_COMM_WORLD, MPI_UNIVERSE_SIZE,
			&universe_sizep, &flag);

	if (!flag) 
	{
		printf("This MPI does not support UNIVERSE_SIZE. How many\n\
		processes total?");
		scanf("%d", &universe_size);
	} 

	else universe_size = *universe_sizep;

	//if (universe_size == 1) error("No room to start workers");

	/*
	* Now spawn the workers. Note that there is a run-time determination
	* of what type of worker to spawn, and presumably this calculation must
	* be done at run time and cannot be calculated before starting
	* the program. If everything is known when the application is
	* first started, it is generally better to start them all at once
	* in a single MPI_COMM_WORLD.
	*/

	//choose_worker_program(worker_program);
	worker_program = "work_";
	argv[0]="mpirun";
	argv[1]="-np";
	argv[2]="4";
	argv[3]="./work";
	argv[4]=NULL;

	MPI_Comm_spawn(worker_program, argv, universe_size-1,
	MPI_INFO_NULL, 0, MPI_COMM_SELF, &everyone,
	MPI_ERRCODES_IGNORE);

	/*
	* Parallel code here. The communicator "everyone" can be used
	* to communicate with the spawned processes, which have ranks 0,..
	* MPI_UNIVERSE_SIZE-1 in the remote group of the intercommunicator
	* "everyone".
	*/

	MPI_Finalize();
	return 0;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -