Skip to content
This repository was archived by the owner on Jan 26, 2026. It is now read-only.

Commit 3caed78

Browse files
committed
better spawning
1 parent 23fa550 commit 3caed78

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def build_cmake(self, ext):
2929
extdir.parent.mkdir(parents=True, exist_ok=True)
3030

3131
# example of cmake args
32-
config = 'Debug'# if self.debug else 'Release' # 'RelWithDebInfo' #'Release'
32+
config = 'Debug' if self.debug else 'RelWithDebInfo' #'Release'
3333
cmake_args = [
3434
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + str(extdir.parent.absolute()),
3535
'-DCMAKE_BUILD_TYPE=' + config

src/MPITransceiver.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,29 @@ MPITransceiver::MPITransceiver()
3737
const char * _tmp = getenv("DDPT_MPI_SPAWN");
3838
if(_tmp) {
3939
int nClientsToSpawn = atol(_tmp);
40-
_tmp = getenv("DDPT_MPI_EXECUTABLE");
41-
std::string clientExe(_tmp ? _tmp : getenv("PYTHON_EXE"));
42-
if(clientExe.empty()) throw std::runtime_error("Spawning MPI processes requires setting 'DDPT_MPI_EXECUTABLE' or 'PYTHON_EXE'");
43-
44-
// 2. arguments
45-
_tmp = getenv("DDPT_MPI_EXE_ARGS");
40+
std::string clientExe;
4641
std::vector<std::string> args;
47-
if(_tmp) {
48-
std::istringstream iss(_tmp);
49-
std::copy(std::istream_iterator<std::string>(iss),
50-
std::istream_iterator<std::string>(),
51-
std::back_inserter(args));
52-
} else {
42+
_tmp = getenv("DDPT_MPI_EXECUTABLE");
43+
if(!_tmp) {
44+
_tmp = getenv("PYTHON_EXE");
45+
if(!_tmp) throw std::runtime_error("Spawning MPI processes requires setting 'DDPT_MPI_EXECUTABLE' or 'PYTHON_EXE'");
46+
clientExe = _tmp;
47+
// 2. arguments
5348
_tmp = "-c import ddptensor as dt; dt.init(True)";
5449
args.push_back("-c");
5550
args.push_back("import ddptensor as dt; dt.init(True)");
51+
} else {
52+
clientExe = _tmp;
53+
// 2. arguments
54+
_tmp = getenv("DDPT_MPI_EXE_ARGS");
55+
if(_tmp) {
56+
std::istringstream iss(_tmp);
57+
std::copy(std::istream_iterator<std::string>(iss),
58+
std::istream_iterator<std::string>(),
59+
std::back_inserter(args));
60+
}
5661
}
62+
5763
const char * clientArgs[args.size()+1];
5864
for(int i=0; i<args.size(); ++i) clientArgs[i] = args[i].c_str();
5965
clientArgs[args.size()] = nullptr;
@@ -69,7 +75,6 @@ MPITransceiver::MPITransceiver()
6975
std::cerr << "[DDPT " << rank << "] Set MPI_Info_set(\"host\", \"" << clientHost << "\")\n";
7076
}
7177
// Now spawn the client processes:
72-
// can't use Speaker yet, need Channels to be inited
7378
std::cerr << "[DDPT " << rank << "] Spawning " << nClientsToSpawn << " MPI processes ("
7479
<< clientExe << " " << _tmp << ")" << std::endl;
7580
int* errCodes = new int[nClientsToSpawn];
@@ -80,7 +85,6 @@ MPITransceiver::MPITransceiver()
8085
MPI_COMM_WORLD, &interComm, errCodes);
8186
delete [] errCodes;
8287
if (err) {
83-
// can't use Speaker yet, need Channels to be inited
8488
std::cerr << "[DDPT " << rank << "] Error in MPI_Comm_spawn. Skipping process spawning";
8589
} else {
8690
MPI_Intercomm_merge(interComm, 0, &_comm);

src/ddptensor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
as a template parameter.
1515
*/
1616

17+
#include <sched.h>
1718
#include <stdlib.h>
1819
#include <pybind11/pybind11.h>
1920
#include <pybind11/stl.h>
@@ -86,6 +87,8 @@ void init(bool cw)
8687
if(inited) return;
8788
theTransceiver = new MPITransceiver();
8889
theMediator = new MPIMediator();
90+
int cpu = sched_getcpu();
91+
std::cerr << "rank " << theTransceiver->rank() << " is running on core " << cpu << std::endl;
8992
if(cw) {
9093
_is_cw = true;
9194
if(theTransceiver->rank()) {

0 commit comments

Comments
 (0)