From dev-return-2955-archive-asf-public=cust-asf.ponee.io@singa.incubator.apache.org Wed Jul 3 14:03:21 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 239AA180109 for ; Wed, 3 Jul 2019 16:03:20 +0200 (CEST) Received: (qmail 12619 invoked by uid 500); 3 Jul 2019 14:03:19 -0000 Mailing-List: contact dev-help@singa.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@singa.incubator.apache.org Delivered-To: mailing list dev@singa.incubator.apache.org Received: (qmail 12350 invoked by uid 99); 3 Jul 2019 14:03:19 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 Jul 2019 14:03:19 +0000 From: GitBox To: dev@singa.apache.org Subject: [GitHub] [incubator-singa] nudles commented on a change in pull request #468: Distributted module Message-ID: <156216259902.18407.1952009714746603573.gitbox@gitbox.apache.org> Date: Wed, 03 Jul 2019 14:03:19 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit nudles commented on a change in pull request #468: Distributted module URL: https://github.com/apache/incubator-singa/pull/468#discussion_r299973462 ########## File path: src/dist/communicator.cc ########## @@ -0,0 +1,150 @@ +#include "singa/dist/communicator.h" +#include +namespace singa{ + +static uint64_t getHostHash(const char* string) { + // Based on DJB2, result = result * 33 + char + uint64_t result = 5381; + for (int c = 0; string[c] != '\0'; c++){ + result = ((result << 5) + result) + string[c]; + } + return result; +} + + +static void getHostName(char* hostname, int maxlen) { + gethostname(hostname, maxlen); + for (int i=0; i< maxlen; i++) { + if (hostname[i] == '.') { + hostname[i] = '\0'; + return; + } + } +} + + +Communicator::Communicator(int nDev): nDev(nDev){ + MPICHECK(MPI_Init(NULL, NULL)); + // get MPI Global Ranks and total Ranks + MPICHECK(MPI_Comm_rank(MPI_COMM_WORLD, &MPIRankInGlobal)); + MPICHECK(MPI_Comm_size(MPI_COMM_WORLD, &totalMPIRanksInGlobal)); + //std::cout<<"g rank " << MPIRankInGlobal << "\n"; + + //calculating MPIRankInLocal which is used in selecting a GPU + MPIRankInLocal=0; + uint64_t hostHashs[totalMPIRanksInGlobal]; + char hostname[1024]; + getHostName(hostname, 1024); + hostHashs[MPIRankInGlobal] = getHostHash(hostname); + MPICHECK(MPI_Allgather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, hostHashs, + sizeof(uint64_t), MPI_BYTE, MPI_COMM_WORLD)); + for (int p=0; p