I had to spend a while searching C++ forums until I understood what you meant. Thank you for the "pointer".
Just for completeness in case anyone gets this post as a Google result: char *data = new char(25); // pointer to character initialized with 25 char *data = new char[25]; // pointer to character array of length 25 As I mentioned, I'm relatively "new" to C++. This wasn't an MPI problem at all. On Wed, Jun 12, 2013 at 6:50 PM, Brian Budge <brian.bu...@gmail.com> wrote: > You appear to be using new and delete[] together. Instead you should > be using new[] and delete[] and new and delete together. > > Brian > > On Wed, Jun 12, 2013 at 4:44 PM, Corey Allen > <corey.al...@cajkhenderson.com> wrote: > > I have done a search on this and I haven't found an explanation. I am > not a > > C/C++ nor MPI expert. I am getting a strange error when I use the C++ new > > keyword to allocate memory and then call a file read on OpenMPI. (Tech > > detail: 4-core Intel running Ubuntu 64-bit and OpenMPI 1.4.5. Everything > is > > local. Total processes is 5.) > > > > In the source code you can see three different approaches to allocating > the > > memory for the char array where the file's contents will go. With the > > C-style and MPI Alloc choices, there is no error even with buffer sizes > in > > the MB range. However, if I use the C++ new keyword, I get an error for > any > > read larger than 24 bytes. > > > > As I say, I'm not a C/C++ expert, but if I'm writing C++ code I was under > > the impression it was wise to use the C++ new approach rather than > malloc. > > Am I missing something in getting this to work with MPI? > > > > Error (the important bit): > > > > *** glibc detected *** MPIIO_Test: free(): invalid next size (fast): > > 0x00000000015524e0 *** > > > > Code: > > > > int main(int argc, char* argv[]){ > > int my_rank; > > MPI_Status status ; > > int errorCode; > > MPI_File _filehandle; > > > > MPI_Init(&argc, &argv); > > MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); > > > > // Open File > > errorCode = MPI_File_open(MPI_COMM_WORLD, "TEST1A", MPI_MODE_RDONLY, > > MPI_INFO_NULL, &_filehandle); > > > > if (errorCode != 0) > > { > > int errorStringLen; > > char *errorString = (char*) malloc(MPI_MAX_ERROR_STRING); > > > > // Get MPI file I/O error string and print it > > MPI_Error_string(errorCode, errorString, &errorStringLen); > > > > printf("MPI Error opening Data File: %s \n", errorString); > > > > free(errorString); > > } > > > > // Works with new at 24, fails at 25 > > int dataLength = 25, numBytesRead; > > char *data = NULL; > > // data = (char*) malloc(dataLength); > > data = new char(dataLength); > > // MPI_Alloc_mem(dataLength, MPI_INFO_NULL, &data); > > > > // File I/O > > errorCode = MPI_File_read_at(_filehandle, my_rank*dataLength, data, > > dataLength, MPI_CHAR, &status); > > MPI_Get_count(&status, MPI_CHAR, &numBytesRead); > > printf("Rank: %d Start: %d Expected: %d Read: %d \n", my_rank, > > my_rank*dataLength, dataLength, numBytesRead); > > > > if (errorCode != 0) > > { > > int errorStringLen; > > char *errorString = (char*) malloc(MPI_MAX_ERROR_STRING); > > > > // Get MPI file I/O error string and print it > > MPI_Error_string(errorCode, errorString, &errorStringLen); > > > > printf("MPI Error reading from Data File: %s \n", errorString); > > > > free(errorString); > > } > > > > // Free memory > > // free(data); > > delete[] data; > > // MPI_Free_mem(data); > > > > // Close file > > MPI_File_close(&_filehandle); > > > > MPI_Finalize(); > > return 0; > > } > > > > > > > > > > _______________________________________________ > > users mailing list > > us...@open-mpi.org > > http://www.open-mpi.org/mailman/listinfo.cgi/users > _______________________________________________ > users mailing list > us...@open-mpi.org > http://www.open-mpi.org/mailman/listinfo.cgi/users >