https://github.com/Microsoft/CNTK
Raw File
Tip revision: b568283c97b0259083a3c84721da46b83c27e600 authored by Guoli Ye on 22 January 2019, 23:16:42 UTC
make the function interface of AssignSequenceError in NoGpu.cpp to be consistent with GPUMatrix.h
Tip revision: b568283
EnvironmentUtil.cpp
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.md file in the project root for full licence information.
//

#include <stdlib.h>
#include <string>
#include "Include/EnvironmentUtil.h"

namespace Microsoft { namespace MSR { namespace CNTK {

using namespace std;

// Functions here read environment variables and therefore do not require MPI initialization. 
// Moreover, they can be used without actually loading any MPI libs.

#pragma warning(push)
#pragma warning(disable : 4996) // complains about unsafe getenv.
// However, the way it's used below is safe, since we immediately 
// create an std::string from the returned value.
int EnvironmentUtil::GetTotalNumberOfMPINodes()
{
#if !HAS_MPI
    const char* p = nullptr;
#elif WIN32
    const char* p = getenv("PMI_SIZE");
#else
    const char* p = getenv("OMPI_COMM_WORLD_SIZE");
#endif

    return (!p) ? 1 : stoi(string(p));
}

int EnvironmentUtil::GetLocalMPINodeRank()
{
#if !HAS_MPI
    const char* p = nullptr;
#elif WIN32
    const char* p = getenv("PMI_RANK");
#else
    const char* p = getenv("OMPI_COMM_WORLD_RANK");
#endif

    return (!p) ? 0 : stoi(string(p));
}
#pragma warning(pop)

}}}
back to top