Commit 2417f106 authored by Shen Yu's avatar Shen Yu
Browse files

modified: Makefile

	modified:   createMPIComm.cpp
	modified:   createMPIComm.h
	modified:   mpi_player.cpp
	modified:   read_run.cpp
	modified:   read_run.h

    1. fix paser input file error
    2. add debug option
parent f46a509d
OPT = -std=c++11 -D_DEBUG
mpi_player: createMPIComm.o read_run.o mpi_player.o mpi_player: createMPIComm.o read_run.o mpi_player.o
mpicxx -o mpi_player createMPIComm.o read_run.o mpi_player.o mpicxx -o mpi_player createMPIComm.o read_run.o mpi_player.o $(OPT)
createMPIComm.o: createMPIComm.cpp createMPIComm.o: createMPIComm.cpp
mpicxx -c createMPIComm.cpp mpicxx -c createMPIComm.cpp $(OPT)
read_run.o: read_run.cpp read_run.o: read_run.cpp
mpicxx -c read_run.cpp mpicxx -c read_run.cpp $(OPT)
mpi_player.o: mpi_player.cpp mpi_player.o: mpi_player.cpp
mpicxx -c mpi_player.cpp mpicxx -c mpi_player.cpp $(OPT)
clean:
rm mpi_player *.o 2>/dev/null
...@@ -5,13 +5,27 @@ ...@@ -5,13 +5,27 @@
#include <cstring> #include <cstring>
#include <mpi.h> #include <mpi.h>
#ifdef _DEBUG
#include <cstdio>
#endif
using namespace std; using namespace std;
int createMPIComm(ifstream& inFile, map<int, MPI_Comm>& COMM_LIST) int createMPIComm(char* INPUTFILENAME, map<int, MPI_Comm>& COMM_LIST)
{ {
int myid;
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
int nComm = 0; int nComm = 0;
string logline; string logline;
set<int> my_comm_ids; set<int> my_comm_ids;
ifstream inFile;
inFile.open(INPUTFILENAME);
#ifdef _DEBUG
printf("myid: %d: input filename: %s\n", myid, INPUTFILENAME);
#endif
while (getline(inFile, logline)) while (getline(inFile, logline))
{ {
double LOG_CALLTIME, LOG_ENDTIME; double LOG_CALLTIME, LOG_ENDTIME;
...@@ -19,6 +33,11 @@ int createMPIComm(ifstream& inFile, map<int, MPI_Comm>& COMM_LIST) ...@@ -19,6 +33,11 @@ int createMPIComm(ifstream& inFile, map<int, MPI_Comm>& COMM_LIST)
sscanf(logline.c_str(), "%lf, %lf, %d, %d", &LOG_CALLTIME, &LOG_ENDTIME, &FUNC_ID, &COMM_ID); sscanf(logline.c_str(), "%lf, %lf, %d, %d", &LOG_CALLTIME, &LOG_ENDTIME, &FUNC_ID, &COMM_ID);
my_comm_ids.insert(COMM_ID); my_comm_ids.insert(COMM_ID);
} }
inFile.close();
#ifdef _DEBUG
printf("myid: %d: total comms: %d\n", myid, my_comm_ids.size());
#endif
// every process collects numbers of comms of all processes // every process collects numbers of comms of all processes
int nprocs; int nprocs;
...@@ -26,6 +45,11 @@ int createMPIComm(ifstream& inFile, map<int, MPI_Comm>& COMM_LIST) ...@@ -26,6 +45,11 @@ int createMPIComm(ifstream& inFile, map<int, MPI_Comm>& COMM_LIST)
vector<int> ncomm(nprocs); vector<int> ncomm(nprocs);
int my_ncomm = my_comm_ids.size(); int my_ncomm = my_comm_ids.size();
MPI_Allgather(&my_ncomm, 1, MPI_INT, &ncomm[0], 1, MPI_INT, MPI_COMM_WORLD); MPI_Allgather(&my_ncomm, 1, MPI_INT, &ncomm[0], 1, MPI_INT, MPI_COMM_WORLD);
#ifdef _DEBUG
printf("myid: %d: my_ncomm: %d\n", myid, my_ncomm);
#endif
// every process collects all comms from all processes // every process collects all comms from all processes
// every process transform comms from set to sendbuf and // every process transform comms from set to sendbuf and
...@@ -45,6 +69,10 @@ int createMPIComm(ifstream& inFile, map<int, MPI_Comm>& COMM_LIST) ...@@ -45,6 +69,10 @@ int createMPIComm(ifstream& inFile, map<int, MPI_Comm>& COMM_LIST)
} }
displs[nprocs] = recv_comm_size; displs[nprocs] = recv_comm_size;
#ifdef _DEBUG
printf("myid: %d: recv_comm_size: %d\n", myid, recv_comm_size);
#endif
vector<int> recvbuf(recv_comm_size); vector<int> recvbuf(recv_comm_size);
MPI_Allgatherv(&sendbuf[0], my_ncomm, MPI_INT, MPI_Allgatherv(&sendbuf[0], my_ncomm, MPI_INT,
&recvbuf[0], &recvcounts[0], &displs[0], MPI_INT, &recvbuf[0], &recvcounts[0], &displs[0], MPI_INT,
...@@ -54,8 +82,6 @@ int createMPIComm(ifstream& inFile, map<int, MPI_Comm>& COMM_LIST) ...@@ -54,8 +82,6 @@ int createMPIComm(ifstream& inFile, map<int, MPI_Comm>& COMM_LIST)
for(const auto& id : recvbuf) for(const auto& id : recvbuf)
all_comm_ids.insert(id); all_comm_ids.insert(id);
int myid;
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
// create each comm in all_comm_ids // create each comm in all_comm_ids
for(const auto& id: all_comm_ids) for(const auto& id: all_comm_ids)
{ {
......
int createMPIComm(std::ifstream& inFile, std::map<int, MPI_Comm>& COMM_LIST); int createMPIComm(char* INPUTFILENAME, std::map<int, MPI_Comm>& COMM_LIST);
#include <fstream> #include <fstream>
#include <cstring> #include <cstring>
#include <iostream>
#include <map> #include <map>
#include <mpi.h> #include <mpi.h>
#include "read_run.h" #include "read_run.h"
...@@ -15,22 +16,54 @@ int main(int argc, char* argv[]) ...@@ -15,22 +16,54 @@ int main(int argc, char* argv[])
int myid; int myid;
MPI_Comm_rank(MPI_COMM_WORLD, &myid); MPI_Comm_rank(MPI_COMM_WORLD, &myid);
int namelen;
char myhostname[MPI_MAX_PROCESSOR_NAME];
MPI_Get_processor_name(myhostname, &namelen);
char INPUTFILENAME[4096]; char INPUTFILENAME[4096];
sprintf(INPUTFILENAME, "%s/MSGLOG.%s.%d.csv", INPUTFILE_DIR, myhostname, myid); sprintf(INPUTFILENAME, "%s/MSGLOG.%d.csv", INPUTFILE_DIR, myid);
ifstream inFile;
inFile.open(INPUTFILENAME);
// create all communitors // create all communitors
map<int, MPI_Comm> COMM_LIST; map<int, MPI_Comm> COMM_LIST;
createMPIComm(inFile, COMM_LIST); int ncomm = createMPIComm(INPUTFILENAME, COMM_LIST);
if(myid == 0) cout<<ncomm<<" comms are created"<<endl;
#ifdef _DEBUG
// check all comms
char outlog[4096];
sprintf(outlog, "myid %d: comms size list:", myid);
//for(const auto& [i, comm_i] : COMM_LIST)
for(const auto& cm : COMM_LIST)
{
int ss;
MPI_Comm_size(cm.second, &ss);
char ll[128];
sprintf(ll, " %d - %d", cm.first, ss);
strcat(outlog, ll);
}
cout<<outlog<<endl;
sprintf(outlog, "myid %d: comms rank list:", myid);
// for(const auto& [i, comm_i] : COMM_LIST)
for(const auto& cm : COMM_LIST)
{
int ss;
MPI_Comm_rank(cm.second, &ss);
char ll[128];
sprintf(ll, " %d - %d", cm.first, ss);
strcat(outlog, ll);
}
cout<<outlog<<endl;
#endif
// read the log and replay the mpi functions // read the log and replay the mpi functions
ifstream inFile;
inFile.open(INPUTFILENAME);
string logline; string logline;
int err;
while (getline(inFile, logline)) while (getline(inFile, logline))
read_run(logline.c_str(), COMM_LIST); {
err = read_run(logline, COMM_LIST);
}
if(myid == 0) cout<<"all records are replayed, error code: "<<err<<endl;
inFile.close(); inFile.close();
MPI_Finalize(); MPI_Finalize();
return 0; return 0;
......
This diff is collapsed.
int read_run(const char* LOG, std::map<int, MPI_Comm>& COMM_LIST); int read_run(std::string LOG, std::map<int, MPI_Comm>& COMM_LIST);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment