Click here to Skip to main content
15,896,339 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: MFC Top Level menu position. Pin
leon de boer1-May-19 0:13
leon de boer1-May-19 0:13 
QuestionImage display problem in listcontrol Pin
tianzhili439925-Apr-19 16:50
tianzhili439925-Apr-19 16:50 
AnswerRe: Image display problem in listcontrol Pin
Victor Nijegorodov25-Apr-19 21:07
Victor Nijegorodov25-Apr-19 21:07 
GeneralRe: Image display problem in listcontrol Pin
tianzhili439925-Apr-19 22:29
tianzhili439925-Apr-19 22:29 
GeneralRe: Image display problem in listcontrol Pin
Victor Nijegorodov26-Apr-19 2:03
Victor Nijegorodov26-Apr-19 2:03 
QuestionConversion from- C++ to C-language < free(): invalid size > Pin
zak10025-Apr-19 9:14
zak10025-Apr-19 9:14 
AnswerRe: Conversion from- C++ to C-language < free(): invalid size > Pin
k505425-Apr-19 10:05
mvek505425-Apr-19 10:05 
AnswerRe: Conversion from- C++ to C-language < free(): invalid size > Pin
John R. Shaw26-Apr-19 9:19
John R. Shaw26-Apr-19 9:19 
The code is not very well written to begin with, so please do not write something like this for a real world application. Be sure to check if each malloc succeeded before using it or you may end up crashing your application - safety first.

I recommend breaking out the pencil an paper and working through the code. Drawing out the arrays (both 1D and 2D) would help in analyzing the code - along with the debugger.

It is a bit confusing when the traditional row/column layout is backwards:
Normal: buffer[row][column]
In this code: buffer[column][row] <<<< this is backwards.

file_buffer is not initialized which could lead to an issue if it does not actually get allocate it.
C++
file_buffer = NULL;
file_buffer size allocation is not correct - it should be using sizeof(double) not sizeof(int). This is important, because you are copying double values into the buffer. Depending on the compiler, the size of a double is probably 2 x sizeof(int). This could cause massive memory corruption.

When memory buffers are allocated one after another, then there is a strong possibility that they follow each other in memory - like so [file_buffer][send_buffer][data]. This means that the loop filling in the file_buffer would be over writing the send_buffer, due to the fact that the file_buffer is not large enough to hold an array of double values.

A little more information is required here about the most like memory lay out.
Buffer allocation layout: [[allocation size][allocated memory]]
When malloc allocates the memory, it reserves the start of the allocated block to hold the size of memory block being allocated and returns a pointer to the memory location following the allocation size data. Therefore, given the above, your code probably allocated the file_buffer and overwrote the allocation size of the send_buffer, leading to the invalid size error.

If the file_buffer is allocated, then ensure that it is freed.

You need to free each data[i] in a loop and then free the data buffer itself.

Since I do not see anything else filling in the send_buffer or recv_buffer, I am going to assume that MPI_Scatter() is filling those buffers. If that is the case, then keep in mind that the number of row does not equal the number of columns unless the size value is equal to 1.
num_cols = num_rows / size;
That implies that the following call is incorrect:
MPI_Scatter(send_buffer, num_cols, MPI_DOUBLE, recv_buffer, num_cols, MPI_DOUBLE, 0, MPI_COMM_WORLD);
Should probably written as follows:
MPI_Scatter(send_buffer, num_rows, MPI_DOUBLE, recv_buffer, num_cols, MPI_DOUBLE, 0, MPI_COMM_WORLD);

INTP
"Program testing can be used to show the presence of bugs, but never to show their absence." - Edsger Dijkstra
"I have never been lost, but I will admit to being confused for several weeks. " - Daniel Boone

GeneralRe: Conversion from- C++ to C-language < free(): invalid size > Pin
zak10026-Apr-19 10:22
zak10026-Apr-19 10:22 
GeneralRe: Conversion from- C++ to C-language < free(): invalid size > Pin
John R. Shaw26-Apr-19 12:31
John R. Shaw26-Apr-19 12:31 
GeneralRe: Conversion from- C++ to C-language < free(): invalid size > Pin
zak10026-Apr-19 14:57
zak10026-Apr-19 14:57 
GeneralRe: Conversion from- C++ to C-language < free(): invalid size > Pin
zak10026-Apr-19 17:53
zak10026-Apr-19 17:53 
GeneralRe: Conversion from- C++ to C-language < free(): invalid size > Pin
John R. Shaw30-Apr-19 4:56
John R. Shaw30-Apr-19 4:56 
GeneralRe: Conversion from- C++ to C-language < free(): invalid size > Pin
zak10030-Apr-19 5:48
zak10030-Apr-19 5:48 
QuestionPointer to Pointer: Conversion from- C++ to C-language Pin
zak10024-Apr-19 18:47
zak10024-Apr-19 18:47 
AnswerRe: Pointer to Pointer: Conversion from- C++ to C-language Pin
Victor Nijegorodov24-Apr-19 20:41
Victor Nijegorodov24-Apr-19 20:41 
GeneralRe: Pointer to Pointer: Conversion from- C++ to C-language Pin
leon de boer25-Apr-19 2:09
leon de boer25-Apr-19 2:09 
GeneralRe: Pointer to Pointer: Conversion from- C++ to C-language Pin
k505425-Apr-19 7:16
mvek505425-Apr-19 7:16 
GeneralRe: Pointer to Pointer: Conversion from- C++ to C-language Pin
Richard MacCutchan24-Apr-19 21:36
mveRichard MacCutchan24-Apr-19 21:36 
GeneralRe: Pointer to Pointer: Conversion from- C++ to C-language Pin
leon de boer25-Apr-19 2:04
leon de boer25-Apr-19 2:04 
GeneralRe: Pointer to Pointer: Conversion from- C++ to C-language Pin
Richard MacCutchan25-Apr-19 2:46
mveRichard MacCutchan25-Apr-19 2:46 
GeneralRe: Pointer to Pointer: Conversion from- C++ to C-language Pin
zak10025-Apr-19 6:52
zak10025-Apr-19 6:52 
GeneralRe: Pointer to Pointer: Conversion from- C++ to C-language Pin
Joe Woodbury29-Apr-19 6:38
professionalJoe Woodbury29-Apr-19 6:38 
GeneralRe: Pointer to Pointer: Conversion from- C++ to C-language Pin
leon de boer3-May-19 4:20
leon de boer3-May-19 4:20 
GeneralRe: Pointer to Pointer: Conversion from- C++ to C-language Pin
Joe Woodbury3-May-19 5:51
professionalJoe Woodbury3-May-19 5:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.