Click here to Skip to main content
14,768,340 members
Home » Discussions » C / C++ / MFC
   

C / C++ / MFC

 
QuestionCalling python function from c++ Pin
Shohel hasan5-May-19 0:24
MemberShohel hasan5-May-19 0:24 
AnswerRe: Calling python function from c++ Pin
Victor Nijegorodov5-May-19 1:35
MemberVictor Nijegorodov5-May-19 1:35 
AnswerRe: Calling python function from c++ Pin
Richard MacCutchan5-May-19 2:49
mveRichard MacCutchan5-May-19 2:49 
AnswerRe: Calling python function from c++ Pin
CPallini5-May-19 10:54
mveCPallini5-May-19 10:54 
QuestionHas C++ ever considered XML style namespaces? Pin
david321729-Apr-19 20:51
Memberdavid321729-Apr-19 20:51 
AnswerRe: Has C++ ever considered XML style namespaces? Pin
Joe Woodbury29-Apr-19 21:12
professionalJoe Woodbury29-Apr-19 21:12 
AnswerRe: Has C++ ever considered XML style namespaces? Pin
Stefan_Lang2-May-19 3:10
mveStefan_Lang2-May-19 3:10 
GeneralRe: Has C++ ever considered XML style namespaces? Pin
CPallini3-May-19 1:05
mveCPallini3-May-19 1:05 
GeneralRe: Has C++ ever considered XML style namespaces? Pin
Stefan_Lang3-May-19 4:58
mveStefan_Lang3-May-19 4:58 
GeneralRe: Has C++ ever considered XML style namespaces? Pin
CPallini3-May-19 5:23
mveCPallini3-May-19 5:23 
GeneralRe: Has C++ ever considered XML style namespaces? Pin
Victor Nijegorodov3-May-19 5:54
MemberVictor Nijegorodov3-May-19 5:54 
GeneralRe: Has C++ ever considered XML style namespaces? Pin
CPallini3-May-19 6:15
mveCPallini3-May-19 6:15 
GeneralRe: Has C++ ever considered XML style namespaces? Pin
Victor Nijegorodov3-May-19 9:11
MemberVictor Nijegorodov3-May-19 9:11 
GeneralRe: Has C++ ever considered XML style namespaces? Pin
Stefan_Lang6-May-19 5:41
mveStefan_Lang6-May-19 5:41 
QuestionMFC Top Level menu position. Pin
Maximilien29-Apr-19 8:50
MemberMaximilien29-Apr-19 8:50 
AnswerRe: MFC Top Level menu position. Pin
leon de boer1-May-19 1:13
Memberleon de boer1-May-19 1:13 
QuestionImage display problem in listcontrol Pin
tianzhili439925-Apr-19 17:50
Membertianzhili439925-Apr-19 17:50 
AnswerRe: Image display problem in listcontrol Pin
Victor Nijegorodov25-Apr-19 22:07
MemberVictor Nijegorodov25-Apr-19 22:07 
GeneralRe: Image display problem in listcontrol Pin
tianzhili439925-Apr-19 23:29
Membertianzhili439925-Apr-19 23:29 
GeneralRe: Image display problem in listcontrol Pin
Victor Nijegorodov26-Apr-19 3:03
MemberVictor Nijegorodov26-Apr-19 3:03 
QuestionConversion from- C++ to C-language < free(): invalid size > Pin
zak10025-Apr-19 10:14
Memberzak10025-Apr-19 10:14 
AnswerRe: Conversion from- C++ to C-language < free(): invalid size > Pin
k505425-Apr-19 11:05
mvek505425-Apr-19 11:05 
AnswerRe: Conversion from- C++ to C-language < free(): invalid size > Pin
John R. Shaw26-Apr-19 10:19
MemberJohn R. Shaw26-Apr-19 10: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.
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 11:22
Memberzak10026-Apr-19 11:22 
GeneralRe: Conversion from- C++ to C-language < free(): invalid size > Pin
John R. Shaw26-Apr-19 13:31
MemberJohn R. Shaw26-Apr-19 13:31 

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.