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

📄 d.c

📁 Parallel programming/Lou Baker, Bradley J.Smith .—New York:McGraw-Hill Book Co.
💻 C
字号:
/* PSPH - Parallel SPH program
 * Bradley Smith,  and Lou Baker, Dagonet Software
 */
static char sccs_id[] = "@(#) /home/bsmith/src/psph/SCCS/s.d.c 1.6 94/01/06";

/* Generalized Spawn PVM
 */

#include "all.h"
#include "pvm3.h"

#define DEBUG


/* Global variables */
extern int Rank, NProc;
extern MPI_Comm Comm;
extern int *AllDest;
extern int *PVM_tid;
extern int PVM_proc, PVM_nproc; 
/* Global message buffers */
PMsgBuf GSendBuf, GRecvBuf;


/* Initialize process similar to PVM_Init of mpi_pvm.c
 but generalized!
 */
int
PVM_GInit(char *name, char **sargv,int flag,char *where,int n)
{
 int i,tid,myid,ntospawn,numt=-100;
 Comm = MPI_COMM_WORLD;
 myid= pvm_mytid();   /* Initializes PVM */
 tid = pvm_parent();	/* Check if we are children or the parent */
#ifdef DEBUG
Debug(" entered PVM_GInit myid %d, tid(parent)=%d\n",myid,tid);
printf(" id's= %d %d n=%d\n",myid,tid,n);
#endif
 if(n>0)
   ntospawn=n-1;/* for compatibility, count n includes parent itself! */
 else ntospawn= -n;
 if(tid < 0) /* Parent */
	{
	
	/* Set number of processors */
	PVM_nproc = (n>0)?n: 1+ntospawn;
	/* Allocate the list */
	if(n<=0) n=2;
#ifdef DEBUG
Debug(" Parent calling New n=%d\n",n);
#endif
	PVM_tid = (int *) New((SIZETYPE) n * sizeof(int));
#ifdef DEBUG
Debug(" PVM_GInit n= %d\n",n);
#endif
	PVM_tid[0] = myid;
	if(!n){Debug(" bad spawn n=0\n");}
	if(n==1)
		{
		PVM_proc = 0;
		return(MPI_SUCCESS);
		}
	/* Spawn n-1 other tasks */
	if(n>0)
		numt=pvm_spawn(name, sargv, flag,where, ntospawn, &PVM_tid[1]);
printf(" spawn numt=%d of %d\n",numt,ntospawn);/* we are master so printf ok*/		
printf(" tid(child)=%d\n",PVM_tid[1]);
	/* Send number and tids of tasks to each */
	pvm_initsend(PvmDataDefault);
	pvm_pkint(&n,1,1);
	pvm_pkint(PVM_tid, n, 1);
	pvm_mcast(&PVM_tid[1], n-1, 0);
	}
 else
	{
	/* Children */
	pvm_recv(tid,0);
    /* Recieve number of tasks */
	pvm_upkint(&PVM_nproc, 1,1);

	/* Allocate list */
	PVM_tid = (int *) New((SIZETYPE) PVM_nproc * sizeof(int));

	/* Get the rest of the stuff */
	pvm_upkint(PVM_tid, PVM_nproc, 1);
	}

 /* Now we need to identify ourselves */
 MPI_Comm_size(Comm, &NProc);
 MPI_Comm_rank(Comm, &Rank);
 tid = myid;
 for(i=0; i<PVM_nproc; i++)
	{
	if(tid == PVM_tid[i])
		{
        PVM_proc = i;
		break;
		}
	}
/* following code borrowed from InitMPISystem in send.c*/
 /* Set up an array that is all destinations */
 AllDest = (int *) New(sizeof(int)*NProc);
 for(i=0; i<NProc; i++)
    AllDest[i] = i;

 /* Allocate our own send and receive buffers - global */
 GSendBuf = NewMsgBuf(SEND_BUF, BUF_ALLOC);
 GRecvBuf = NewMsgBuf(RECV_BUF, BUF_ALLOC);
/* preceeding code borrowed from InitMPISystem in send.c*/

 return(MPI_SUCCESS);
} 


⌨️ 快捷键说明

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