I need to read in few input files(each contains a 2d matrix of integers) and store them in a vector of 2d vectors. below is code I wrote:
int main(int argc, char *argv[]) {
/*
int my_rank;
int p;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Comm_size(MPI_COMM_WORLD, &p);
*/
std::vector<std::vector<std::vector<int > > > matrices(argc);
for(int i=1; i<argc; ++i){
std::string line;
std::ifstream fp(argv[i]);
std::vector<std::vector<int> > matrix;
if (fp.is_open()) {
while (getline(fp, line)) {
if(line!=""){
//add a new row to file
std::vector<int> newRow;
//parse each row put the values in the file buffer
std::stringstream buff(line);
//buffValue is each number in a row
int buffValue;
while (buff >> buffValue) {
newRow.push_back(buffValue);
}
matrix.push_back(newRow);
}
}
}
else {
std::cout << "Failed to read files" << std::endl;
}
matrices.push_back(matrix);
}
//MPI_Finalize();
return 0;
}
I have two questions here:
when I read in one single file of 175M, the program ended up taking 900M in resident memory. This is a problem because I usually need to read in 4 files with few hundred M's per file. and it will eventually take multiple G's of memory. Is this because of the way I read/store the integers?
If I uncomment the lines involve MPI, the resident memory usage goes up to 1.7G, is this normal or I'm doing something wrong here, I'm using MPICH.