X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=distancecommand.cpp;h=ec32ffeb9e2e28b7398f78c5dd5fd858de2326a0;hb=89d6711c2beed6ee75fb00e5e57f1a91564d3e89;hp=47e22ad47d21e9320dd5ee60bb6d40525793662d;hpb=fdc1f6eaf544f695fc1511f24bddd7e6069c33ba;p=mothur.git diff --git a/distancecommand.cpp b/distancecommand.cpp index 47e22ad..ec32ffe 100644 --- a/distancecommand.cpp +++ b/distancecommand.cpp @@ -199,13 +199,15 @@ int DistanceCommand::execute(){ if (output != "lt") { MPI_File outMPI; int amode=MPI_MODE_CREATE|MPI_MODE_WRONLY; + + //char* filename = new char[outputFile.length()]; + //memcpy(filename, outputFile.c_str(), outputFile.length()); - char filename[outputFile.length()]; + char filename[1024]; strcpy(filename, outputFile.c_str()); MPI_File_open(MPI_COMM_WORLD, filename, amode, MPI_INFO_NULL, &outMPI); - - if (m->control_pressed) { MPI_File_close(&outMPI); delete distCalculator; return 0; } + //delete filename; if (pid == 0) { //you are the root process @@ -249,11 +251,15 @@ int DistanceCommand::execute(){ int amode=MPI_MODE_APPEND|MPI_MODE_WRONLY|MPI_MODE_CREATE; // MPI_File outMPI; MPI_File inMPI; - - char filename[outputFile.length()]; + + //char* filename = new char[outputFile.length()]; + //memcpy(filename, outputFile.c_str(), outputFile.length()); + + char filename[1024]; strcpy(filename, outputFile.c_str()); - + MPI_File_open(MPI_COMM_SELF, filename, amode, MPI_INFO_NULL, &outMPI); + //delete filename; //wait on chidren for(int b = 1; b < processors; b++) { @@ -264,14 +270,15 @@ int DistanceCommand::execute(){ MPI_Recv(&fileSize, 1, MPI_LONG, b, tag, MPI_COMM_WORLD, &status); string outTemp = outputFile + toString(b) + ".temp"; - char buf[outTemp.length()]; - strcpy(buf, outTemp.c_str()); + + char* buf = new char[outTemp.length()]; + memcpy(buf, outTemp.c_str(), outTemp.length()); MPI_File_open(MPI_COMM_SELF, buf, MPI_MODE_DELETE_ON_CLOSE|MPI_MODE_RDONLY, MPI_INFO_NULL, &inMPI); - + delete buf; + int count = 0; - while (count < fileSize) { //read 1000 characters at a time - //send freqs + while (count < fileSize) { char buf2[1]; MPI_File_read(inMPI, buf2, 1, MPI_CHAR, &status); MPI_File_write(outMPI, buf2, 1, MPI_CHAR, &status); @@ -335,6 +342,14 @@ int DistanceCommand::execute(){ if (output == "square") { convertMatrix(outputFile); } + ifstream fileHandle; + fileHandle.open(outputFile.c_str()); + if(fileHandle) { + gobble(fileHandle); + if (fileHandle.eof()) { m->mothurOut(outputFile + " is blank. This can result if there are no distances below your cutoff."); m->mothurOutEndLine(); } + } + + #ifdef USE_MPI } #endif @@ -485,11 +500,13 @@ int DistanceCommand::driverMPI(int startLine, int endLine, MPI_File& outMPI, flo //send results to parent int length = outputString.length(); - char buf[length]; - strcpy(buf, outputString.c_str()); + + char* buf = new char[length]; + memcpy(buf, outputString.c_str(), length); MPI_File_write_shared(outMPI, buf, length, MPI_CHAR, &status); outputString = ""; + delete buf; } @@ -510,11 +527,15 @@ int DistanceCommand::driverMPI(int startLine, int endLine, string file, long& si MPI_File outMPI; int amode=MPI_MODE_CREATE|MPI_MODE_WRONLY; + + //char* filename = new char[file.length()]; + //memcpy(filename, file.c_str(), file.length()); - char filename[file.length()]; + char filename[1024]; strcpy(filename, file.c_str()); - + MPI_File_open(MPI_COMM_SELF, filename, amode, MPI_INFO_NULL, &outMPI); + //delete filename; int startTime = time(NULL); @@ -552,14 +573,13 @@ int DistanceCommand::driverMPI(int startLine, int endLine, string file, long& si //send results to parent int length = outputString.length(); - char buf[length]; - strcpy(buf, outputString.c_str()); + char* buf = new char[length]; + memcpy(buf, outputString.c_str(), length); MPI_File_write(outMPI, buf, length, MPI_CHAR, &status); size += outputString.length(); outputString = ""; - - + delete buf; } //m->mothurOut(toString(endLine-1) + "\t" + toString(time(NULL) - startTime)); m->mothurOutEndLine();