-:    0:Source:/home/MPI/testing/mpich2/mpich2/src/mpi/init/init.c
        -:    0:Graph:init.gcno
        -:    0:Data:init.gcda
        -:    0:Runs:4383
        -:    0:Programs:1376
        -:    1:/* -*- Mode: C; c-basic-offset:4 ; -*- */
        -:    2:/*
        -:    3: *  (C) 2001 by Argonne National Laboratory.
        -:    4: *      See COPYRIGHT in top-level directory.
        -:    5: */
        -:    6:
        -:    7:#include "mpiimpl.h"
        -:    8:#include "mpi_init.h"
        -:    9:
        -:   10:
        -:   11:/* -- Begin Profiling Symbol Block for routine MPI_Init */
        -:   12:#if defined(HAVE_PRAGMA_WEAK)
        -:   13:#pragma weak MPI_Init = PMPI_Init
        -:   14:#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
        -:   15:#pragma _HP_SECONDARY_DEF PMPI_Init  MPI_Init
        -:   16:#elif defined(HAVE_PRAGMA_CRI_DUP)
        -:   17:#pragma _CRI duplicate MPI_Init as PMPI_Init
        -:   18:#endif
        -:   19:/* -- End Profiling Symbol Block */
        -:   20:
        -:   21:/* Define MPICH_MPI_FROM_PMPI if weak symbols are not supported to build
        -:   22:   the MPI routines */
        -:   23:#ifndef MPICH_MPI_FROM_PMPI
        -:   24:#undef MPI_Init
        -:   25:#define MPI_Init PMPI_Init
        -:   26:
        -:   27:/* Fortran logical values. extern'd in mpiimpl.h */
        -:   28:/* MPI_Fint MPIR_F_TRUE, MPIR_F_FALSE; */
        -:   29:
        -:   30:/* Any internal routines can go here.  Make them static if possible */
        -:   31:#endif
        -:   32:
        -:   33:int MPIR_async_thread_initialized = 0;
        -:   34:
        -:   35:#undef FUNCNAME
        -:   36:#define FUNCNAME MPI_Init
        -:   37:
        -:   38:/*@
        -:   39:   MPI_Init - Initialize the MPI execution environment
        -:   40:
        -:   41:   Input Parameters:
        -:   42:+  argc - Pointer to the number of arguments 
        -:   43:-  argv - Pointer to the argument vector
        -:   44:
        -:   45:Thread and Signal Safety:
        -:   46:This routine must be called by one thread only.  That thread is called
        -:   47:the `main thread` and must be the thread that calls 'MPI_Finalize'.
        -:   48:
        -:   49:Notes:
        -:   50:   The MPI standard does not say what a program can do before an 'MPI_INIT' or
        -:   51:   after an 'MPI_FINALIZE'.  In the MPICH implementation, you should do
        -:   52:   as little as possible.  In particular, avoid anything that changes the
        -:   53:   external state of the program, such as opening files, reading standard
        -:   54:   input or writing to standard output.
        -:   55:
        -:   56:Notes for Fortran:
        -:   57:The Fortran binding for 'MPI_Init' has only the error return
        -:   58:.vb
        -:   59:    subroutine MPI_INIT( ierr )
        -:   60:    integer ierr
        -:   61:.ve
        -:   62:
        -:   63:.N Errors
        -:   64:.N MPI_SUCCESS
        -:   65:.N MPI_ERR_INIT
        -:   66:
        -:   67:.seealso: MPI_Init_thread, MPI_Finalize
        -:   68:@*/
        -:   69:int MPI_Init( int *argc, char ***argv )
     3070:   70:{
        -:   71:    static const char FCNAME[] = "MPI_Init";
     3070:   72:    int mpi_errno = MPI_SUCCESS;
        -:   73:    int rc;
        -:   74:    int threadLevel, provided;
     3070:   75:    MPIU_THREADPRIV_DECL;
        -:   76:    MPID_MPI_INIT_STATE_DECL(MPID_STATE_MPI_INIT);
        -:   77:
     3070:   78:    rc = MPID_Wtime_init();
        -:   79:#ifdef USE_DBG_LOGGING
        -:   80:    MPIU_DBG_PreInit( argc, argv, rc );
        -:   81:#endif
        -:   82:
     3070:   83:    MPID_CS_INITIALIZE();
        -:   84:    /* FIXME: Can we get away without locking every time.  Now, we
        -:   85:       need a MPID_CS_ENTER/EXIT around MPI_Init and MPI_Init_thread.
        -:   86:       Progress may be called within MPI_Init, e.g., by a spawned
        -:   87:       child process.  Within progress, the lock is released and
        -:   88:       reacquired when blocking.  If the lock isn't acquired before
        -:   89:       then, the release in progress is incorrect.  Furthermore, if we
        -:   90:       don't release the lock after progress, we'll deadlock the next
        -:   91:       time this process tries to acquire the lock.
        -:   92:       MPID_CS_ENTER/EXIT functions are used here instead of
        -:   93:       MPIU_THREAD_SINGLE_CS_ENTER/EXIT because
        -:   94:       MPIR_ThreadInfo.isThreaded hasn't been initialized yet.
        -:   95:    */
        -:   96:#if MPIU_THREAD_GRANULARITY == MPIU_THREAD_GRANULARITY_GLOBAL
     3070:   97:    MPID_CS_ENTER();
        -:   98:#endif
        -:   99:    
        -:  100:    MPID_MPI_INIT_FUNC_ENTER(MPID_STATE_MPI_INIT);
        -:  101:#   ifdef HAVE_ERROR_CHECKING
        -:  102:    {
        -:  103:        MPID_BEGIN_ERROR_CHECKS;
        -:  104:        {
     3070:  105:            if (MPIR_Process.initialized != MPICH_PRE_INIT) {
        4:  106:                mpi_errno = MPIR_Err_create_code( MPI_SUCCESS, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OTHER,
        -:  107:						  "**inittwice", NULL );
        -:  108:	    }
     3070:  109:            if (mpi_errno) goto fn_fail;
        -:  110:        }
        -:  111:        MPID_END_ERROR_CHECKS;
        -:  112:    }
        -:  113:#   endif /* HAVE_ERROR_CHECKING */
        -:  114:
        -:  115:    /* ... body of routine ... */
        -:  116:
        -:  117:#if (MPICH_THREAD_LEVEL == MPI_THREAD_MULTIPLE)
        -:  118:    /* If we support all thread levels, allow the use of an environment 
        -:  119:       variable to set the default thread level */
        -:  120:    {
     3066:  121:	const char *str = 0;
     3066:  122:	threadLevel = MPI_THREAD_SINGLE;
     3066:  123:	if (MPIU_GetEnvStr( "MPICH_THREADLEVEL_DEFAULT", &str )) {
    #####:  124:	    if (strcmp(str,"MULTIPLE") == 0 || strcmp(str,"multiple") == 0) {
    #####:  125:		threadLevel = MPI_THREAD_MULTIPLE;
        -:  126:	    }
    #####:  127:	    else if (strcmp(str,"SERIALIZED") == 0 || strcmp(str,"serialized") == 0) {
    #####:  128:		threadLevel = MPI_THREAD_SERIALIZED;
        -:  129:	    }
    #####:  130:	    else if (strcmp(str,"FUNNELED") == 0 || strcmp(str,"funneled") == 0) {
    #####:  131:		threadLevel = MPI_THREAD_FUNNELED;
        -:  132:	    }
    #####:  133:	    else if (strcmp(str,"SINGLE") == 0 || strcmp(str,"single") == 0) {
    #####:  134:		threadLevel = MPI_THREAD_SINGLE;
        -:  135:	    }
        -:  136:	    else {
    #####:  137:		MPIU_Error_printf( "Unrecognized thread level %s\n", str );
    #####:  138:		exit(1);
        -:  139:	    }
        -:  140:	}
        -:  141:    }
        -:  142:#else 
        -:  143:    threadLevel = MPI_THREAD_SINGLE;
        -:  144:#endif
        -:  145:
        -:  146:    /* If the user requested for asynchronous progress, request for
        -:  147:     * THREAD_MULTIPLE. */
     3066:  148:    rc = 0;
     3066:  149:    MPIU_GetEnvBool("MPICH_ASYNC_PROGRESS", &rc);
     3066:  150:    if (rc)
    #####:  151:        threadLevel = MPI_THREAD_MULTIPLE;
        -:  152:
     3066:  153:    mpi_errno = MPIR_Init_thread( argc, argv, threadLevel, &provided );
     3066:  154:    if (mpi_errno != MPI_SUCCESS) goto fn_fail;
        -:  155:
     3066:  156:    if (rc && provided == MPI_THREAD_MULTIPLE) {
    #####:  157:        mpi_errno = MPIR_Init_async_thread();
    #####:  158:        if (mpi_errno) goto fn_fail;
        -:  159:
    #####:  160:        MPIR_async_thread_initialized = 1;
        -:  161:    }
        -:  162:
        -:  163:    /* ... end of body of routine ... */
        -:  164:    
        -:  165:    MPID_MPI_INIT_FUNC_EXIT(MPID_STATE_MPI_INIT);
        -:  166:#if MPIU_THREAD_GRANULARITY == MPIU_THREAD_GRANULARITY_GLOBAL
     3066:  167:    MPID_CS_EXIT();
        -:  168:#endif
     3066:  169:    return mpi_errno;
        -:  170:    
        4:  171:  fn_fail:
        -:  172:    /* --BEGIN ERROR HANDLING-- */
        -:  173:#   ifdef HAVE_ERROR_REPORTING
        -:  174:    {
        -:  175:	mpi_errno = MPIR_Err_create_code(
        -:  176:	    mpi_errno, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OTHER, 
        -:  177:	    "**mpi_init", "**mpi_init %p %p", argc, argv);
        -:  178:    }
        -:  179:#   endif
        4:  180:    mpi_errno = MPIR_Err_return_comm( 0, FCNAME, mpi_errno );
        4:  181:    MPID_CS_EXIT();
        4:  182:    MPID_CS_FINALIZE();
        4:  183:    return mpi_errno;
        -:  184:    /* --END ERROR HANDLING-- */
        -:  185:}