📄 pgon.c
字号:
/* PSPH - Parallel SPH program
* Brad Smith and Lou Baker, Dagonet Software
*/
static char sccs_id[] = "@(#) /home2/bsmith/src/psph/SCCS/s.pgon.c 1.4 94/03/15 (PSPH)";
/* MPI Implementation for Intel Paragon */
#include "all.h"
/* Some compilers require at least one external reference */
extern int NProc;
#ifdef PGON_MSG
static pid_t *pids; /* Task id array */
static int PGON_nproc,PGON_proc;
static long p_type;
#define PGON_PTYPE p_type
/* Initialize n copies of the named process */
int
PGON_Init(int n, int argc, char **argv)
{
int i;
int num;
if((num=numnodes()) > 1)
PGON_nproc = num; /* Already initialized */
else
PGON_nproc = n;
if(n<=1 && num == 1)
{
PGON_proc = 0;
return(MPI_SUCCESS);
}
if(num <= 1 && n > 1)
{
#ifdef NOTDEF /* Doesn't work with IP switch */
/* Initialize partition */
if(nx_initve(NULL, (long)n, NULL, &argc, argv) <= 0)
return(MPI_FAILURE);
/* Fork them */
pids = New(sizeof(pid_t) * n);
if((i=nx_nfork(NULL, -1, 0, pids)) < 0)
return(MPI_FAILURE);
if(i > 0) /* Controlling process stays out of things */
{
nx_waitall();
Exit(0);
}
#else
printf("Specify number of processes with '-sz' option as in: psph -plk -sz 4\n");
return(MPI_FAILURE);
#endif
}
PGON_proc = mynode();
#ifdef OLD
setptype(PGON_PTYPE);
#endif
p_type = myptype();
return(MPI_SUCCESS);
}
int
PGON_Rank()
{
return PGON_proc;
}
int
PGON_Nproc()
{
return(PGON_nproc);
}
void
PGON_Abort(int errcode)
{
int i;
/* Kill everyone */
kill(0, SIGTERM);
/* Kill ourselves */
Exit(0);
}
/* Overkill - but the paragon wants longs, not ints */
static long *Ldest;
/* Now capable of doing a multisend */
int
PGON_Send(void *buf, int count, MPI_Datatype data_type, int *dest, int ndest, int tag)
{
int i;
if(!Ldest)
Ldest = (long *) New(sizeof(long)*PGON_nproc);
/* Copy to long array (probably overkill, but we want portability) */
for(i=0; i<ndest; i++)
Ldest[i] = (long) dest[i];
/* Begin multi-send */
gsendx((long) tag, buf, (long) (count * _MPI_SizeDataType(data_type)), Ldest, (long)ndest);
return(MPI_SUCCESS);
}
int
PGON_Receive(void *buf, int count, int data_type, int source,
int tag, MPI_Status *status)
{
long info[8];
if(source >= PGON_nproc || source < MPI_ANY_SOURCE)
{
UserMessage("PVM_Receive: Attempt to receive on bad source=%d\n", source);
return(MPI_FAILURE);
}
/* Blocking extended receive */
crecvx((long) tag, buf, (long) (count * _MPI_SizeDataType(data_type)), (long)source,
(long) PGON_PTYPE, info);
/* Grab message stats */
status->count = (int) (info[1] / _MPI_SizeDataType(data_type));
status->source = (int) info[2];
status->tag = (int)info[0];
return(MPI_SUCCESS);
}
int
PGON_Isend(void *buf, int count, MPI_Datatype data_type, int dest,
int tag, MPI_Comm_request *request)
{
request->msgid = isend(tag, buf, (count * _MPI_SizeDataType(data_type)), dest, PGON_PTYPE);
request->is_send = TRUE;
request->status.tag = tag;
request->status.source = dest;
request->status.count = count;
return(MPI_SUCCESS);
}
int
PGON_Irecv(void *buf, int count, MPI_Datatype data_type, int source,
int tag, MPI_Comm_request *request)
{
/* NOT IMPLEMENTED */
return(MPI_FAILURE);
}
int
PGON_Wait(MPI_Comm_request *request, MPI_Status *status)
{
msgwait(request->msgid);
return(MPI_SUCCESS);
}
int
PGON_Test(MPI_Comm_request *request, MPI_Status *status)
{
return(msgdone(request->msgid));
}
int
PGON_Probe(int source, int tag, int *flag, MPI_Status *status)
{
long info[8];
if(!iprobex((long) tag,(long)source, (long) -1, info))
{
*flag = FALSE;
return(MPI_SUCCESS);
}
/* Count is inaccurate (in bytes) - but that's OK */
status->count = (int) info[1];
status->source = (int) info[2];
status->tag = (int) info[0];
*flag = TRUE;
return(MPI_SUCCESS);
}
#endif /* PGON_MSG */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -