int PMIReadLine(int fd, char *buf, int maxlen) { int rc; /* If no data is read, PMIU_readline doesn't place a null in the * buffer. We make sure that buf[0] is always valid */ buf[0] = 0; rc = PMIU_readline(fd, buf, maxlen); if (pmidebug) { if (rc < 0) { DBG_PRINTFCOND(1, ("Read on fd %d returned rc %d\n", fd, rc)); } else { DBG_PRINTFCOND(1, ("Read from fd %d the line :%s:\n", fd, buf)); } DBG_COND(1, fflush(stdout)); } return rc; }
int PMI_Init( int *spawned ) { char *p; int notset = 1; int rc; PMI_initialized = PMI_UNINITIALIZED; /* FIXME: Why is setvbuf commented out? */ /* FIXME: What if the output should be fully buffered (directed to file)? unbuffered (user explicitly set?) */ /* setvbuf(stdout,0,_IONBF,0); */ setbuf(stdout,NULL); /* PMIU_printf( 1, "PMI_INIT\n" ); */ /* Get the value of PMI_DEBUG from the environment if possible, since we may have set it to help debug the setup process */ p = getenv( "PMI_DEBUG" ); if (p) PMI_debug = atoi( p ); /* Get the fd for PMI commands; if none, we're a singleton */ rc = getPMIFD(¬set); if (rc) { return rc; } if ( PMI_fd == -1 ) { /* Singleton init: Process not started with mpiexec, so set size to 1, rank to 0 */ PMI_size = 1; PMI_rank = 0; *spawned = 0; PMI_initialized = SINGLETON_INIT_BUT_NO_PM; /* 256 is picked as the minimum allowed length by the PMI servers */ PMI_kvsname_max = 256; PMI_keylen_max = 256; PMI_vallen_max = 256; return( 0 ); } /* If size, rank, and debug are not set from a communication port, use the environment */ if (notset) { if ( ( p = getenv( "PMI_SIZE" ) ) ) PMI_size = atoi( p ); else PMI_size = 1; if ( ( p = getenv( "PMI_RANK" ) ) ) { PMI_rank = atoi( p ); /* Let the util routine know the rank of this process for any messages (usually debugging or error) */ PMIU_Set_rank( PMI_rank ); } else PMI_rank = 0; if ( ( p = getenv( "PMI_DEBUG" ) ) ) PMI_debug = atoi( p ); else PMI_debug = 0; /* Leave unchanged otherwise, which indicates that no value was set */ } /* FIXME: Why does this depend on their being a port??? */ /* FIXME: What is this for? */ #ifdef USE_PMI_PORT if ( ( p = getenv( "PMI_TOTALVIEW" ) ) ) PMI_totalview = atoi( p ); if ( PMI_totalview ) { char buf[PMIU_MAXLINE], cmd[PMIU_MAXLINE]; /* FIXME: This should use a cmd/response rather than a expecting the server to set a value in this and only this case */ /* FIXME: And it most ceratainly should not happen *before* the initialization handshake */ PMIU_readline( PMI_fd, buf, PMIU_MAXLINE ); PMIU_parse_keyvals( buf ); PMIU_getval( "cmd", cmd, PMIU_MAXLINE ); if ( strncmp( cmd, "tv_ready", PMIU_MAXLINE ) != 0 ) { PMIU_printf( 1, "expecting cmd=tv_ready, got %s\n", buf ); return( PMI_FAIL ); } } #endif PMII_getmaxes( &PMI_kvsname_max, &PMI_keylen_max, &PMI_vallen_max ); /* FIXME: This is something that the PM should tell the process, rather than deliver it through the environment */ if ( ( p = getenv( "PMI_SPAWNED" ) ) ) PMI_spawned = atoi( p ); else PMI_spawned = 0; if (PMI_spawned) *spawned = 1; else *spawned = 0; if ( ! PMI_initialized ) PMI_initialized = NORMAL_INIT_WITH_PM; return( 0 ); }