Пример #1
0
/*
 * This is the client side of the PMIserver setup.  It communicates to the
 * client the information needed to connect to the server (currently the
 * FD of a pre-existing socket).
 *
 * The env_pmi_fd and port must be static because putenv doesn't make a copy
 * of them.  It is ok to use static variable since this is called only within
 * the client; this routine will be called only once (in the forked process,
 * before the exec).
 *
 * Another wrinkle is that in order to support -(g)envnone (no environment
 * variables in context of created process), we need to add the environment
 * variables to the ones set *after* environment variables are removed, rather
 * than using putenv.
 */
int PMISetupInClient(int usePort, PMISetup * pmiinfo)
{
    static char env_pmi_fd[100];
    static char env_pmi_port[1024];

    if (usePort == 0) {
        close(pmiinfo->fdpair[0]);
        MPL_snprintf(env_pmi_fd, sizeof(env_pmi_fd), "PMI_FD=%d", pmiinfo->fdpair[1]);
        if (MPIE_Putenv(pmiinfo->pWorld, env_pmi_fd)) {
            MPL_internal_error_printf("Could not set environment PMI_FD");
            return 1;
        }
    } else {
        /* We must communicate the port name to the process */
        if (pmiinfo->portName) {
            MPL_snprintf(env_pmi_port, sizeof(env_pmi_port), "PMI_PORT=%s", pmiinfo->portName);
            if (MPIE_Putenv(pmiinfo->pWorld, env_pmi_port)) {
                MPL_internal_error_printf("Could not set environment PMI_PORT");
                perror("Reason: ");
                return 1;
            }
        } else {
            MPL_internal_error_printf("Required portname was not defined\n");
            return 1;
        }

    }
    /* Indicate that this is a spawned process */
    /* MPIE_Putenv(pmiinfo->pWorld, "PMI_SPAWNED=1"); */
    return 0;
}
Пример #2
0
int myspawn( ProcessWorld *pWorld, void *data )
{
    SetupInfo    *s = (SetupInfo *)data;
    ProcessWorld *p, **pPtr;

    p = pUniv.worlds;
    pPtr = &(pUniv.worlds);
    while (p) {
	pPtr = &p->nextWorld;
	p    = *pPtr;
    }
    *pPtr = pWorld;

    /* Fork Processes may call a routine that is passed s but not pWorld;
       this makes sure that all routines can access the current world */
    s->pmiinfo.pWorld = pWorld;

    /* FIXME: This should be part of the PMI initialization in the clients */
    MPIE_Putenv( pWorld, "PMI_SPAWNED=1" );

    MPIE_ForkProcesses( pWorld, 0, mypreamble, s,
			mypostfork, 0, mypostamble, 0 );
    return 0;
}