Send and recieve 3D matrix with MPI (C)










0















I have two threads (rank 0 and 1), each containing a 3D matrix (x0,y,z) and (x1,y,z) with a different size along the x dimension. I would like to send a specific plane (x0 constant,y,z) from the first thread to the second and replace one of its face (x1 constant, y, z). The following code I made seems to work well when the two matrices have identical dimensions (even in x), but does not send the right face when x0 != x1 :



double ***alloc2(int x, int y,int z)

int i, j;

double ***array = (double ***) malloc(sizeof(double ***)*x);
for (i = 0; i<x; i++)
array[i] = (double **) malloc(sizeof(double*)*y);
for (j=0; j<y; j++)
array[i][j] = (double *) malloc(sizeof(double)*z);

return array;



int main(int argc, char *argv)

MPI_Status status;
MPI_Comm_size(MPI_COMM_WORLD, &nbr);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);

/* Some long code I skiped */
/* ... */

MPI_Datatype sub;
MPI_Type_vector(nL+1, nL+1, nL_thread, MPI_DOUBLE, &sub);
MPI_Type_commit(&sub);

if(rank == 0)
MPI_Send(&c_new[3][0][0], 1, sub, rank+1,01, MPI_COMM_WORLD);
MPI_Recv(&c_new[4][0][0], 1, sub, rank+1,10, MPI_COMM_WORLD, &status);
if(rank == 1)
MPI_Recv(&c_new[0][0][0], 1, sub, rank-1,01, MPI_COMM_WORLD, &status);
MPI_Send(&c_new[1][0][0], 1, sub, rank-1,10, MPI_COMM_WORLD);




nL is the length in the y and z dimensions, same for all threads, nL_thread is the x dimension (in this particular case, nL_thread = 3 for rank 1 and 4 for rank 0). here I am trying to replace the faces (0,y,z) of rank 1 by (3,y,z) of rank 0, and (4,y,z) of rank 0 by (1,y,z) of rank 1.










share|improve this question
























  • sizeof(double) in all allocations does not seem right. In fact the whole allocation does not make much sense.

    – Osiris
    Nov 16 '18 at 6:59











  • If you are using thread parallelisation you should use a proper 3D array, not some segmented nonsense. Different threads accessing different regions of the heap will be inefficient. See Correctly allocating multi-dimensional arrays for ways to fix the program.

    – Lundin
    Nov 16 '18 at 8:52











  • Indeed Osiris, I edited my malloc function :

    – Kyraz
    Nov 16 '18 at 9:03












  • MPI thread is not the appropriate terminology here. You can use MPI task or MPI process in order to avoid any confusion. Did you allocate your 3D matrix in contiguous memory ? This is a requirement for what you are trying to achieve. Please edit your question with a Minimal, Complete, and Verifiable example in order to clarify what you are doing.

    – Gilles Gouaillardet
    Nov 16 '18 at 14:27















0















I have two threads (rank 0 and 1), each containing a 3D matrix (x0,y,z) and (x1,y,z) with a different size along the x dimension. I would like to send a specific plane (x0 constant,y,z) from the first thread to the second and replace one of its face (x1 constant, y, z). The following code I made seems to work well when the two matrices have identical dimensions (even in x), but does not send the right face when x0 != x1 :



double ***alloc2(int x, int y,int z)

int i, j;

double ***array = (double ***) malloc(sizeof(double ***)*x);
for (i = 0; i<x; i++)
array[i] = (double **) malloc(sizeof(double*)*y);
for (j=0; j<y; j++)
array[i][j] = (double *) malloc(sizeof(double)*z);

return array;



int main(int argc, char *argv)

MPI_Status status;
MPI_Comm_size(MPI_COMM_WORLD, &nbr);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);

/* Some long code I skiped */
/* ... */

MPI_Datatype sub;
MPI_Type_vector(nL+1, nL+1, nL_thread, MPI_DOUBLE, &sub);
MPI_Type_commit(&sub);

if(rank == 0)
MPI_Send(&c_new[3][0][0], 1, sub, rank+1,01, MPI_COMM_WORLD);
MPI_Recv(&c_new[4][0][0], 1, sub, rank+1,10, MPI_COMM_WORLD, &status);
if(rank == 1)
MPI_Recv(&c_new[0][0][0], 1, sub, rank-1,01, MPI_COMM_WORLD, &status);
MPI_Send(&c_new[1][0][0], 1, sub, rank-1,10, MPI_COMM_WORLD);




nL is the length in the y and z dimensions, same for all threads, nL_thread is the x dimension (in this particular case, nL_thread = 3 for rank 1 and 4 for rank 0). here I am trying to replace the faces (0,y,z) of rank 1 by (3,y,z) of rank 0, and (4,y,z) of rank 0 by (1,y,z) of rank 1.










share|improve this question
























  • sizeof(double) in all allocations does not seem right. In fact the whole allocation does not make much sense.

    – Osiris
    Nov 16 '18 at 6:59











  • If you are using thread parallelisation you should use a proper 3D array, not some segmented nonsense. Different threads accessing different regions of the heap will be inefficient. See Correctly allocating multi-dimensional arrays for ways to fix the program.

    – Lundin
    Nov 16 '18 at 8:52











  • Indeed Osiris, I edited my malloc function :

    – Kyraz
    Nov 16 '18 at 9:03












  • MPI thread is not the appropriate terminology here. You can use MPI task or MPI process in order to avoid any confusion. Did you allocate your 3D matrix in contiguous memory ? This is a requirement for what you are trying to achieve. Please edit your question with a Minimal, Complete, and Verifiable example in order to clarify what you are doing.

    – Gilles Gouaillardet
    Nov 16 '18 at 14:27













0












0








0








I have two threads (rank 0 and 1), each containing a 3D matrix (x0,y,z) and (x1,y,z) with a different size along the x dimension. I would like to send a specific plane (x0 constant,y,z) from the first thread to the second and replace one of its face (x1 constant, y, z). The following code I made seems to work well when the two matrices have identical dimensions (even in x), but does not send the right face when x0 != x1 :



double ***alloc2(int x, int y,int z)

int i, j;

double ***array = (double ***) malloc(sizeof(double ***)*x);
for (i = 0; i<x; i++)
array[i] = (double **) malloc(sizeof(double*)*y);
for (j=0; j<y; j++)
array[i][j] = (double *) malloc(sizeof(double)*z);

return array;



int main(int argc, char *argv)

MPI_Status status;
MPI_Comm_size(MPI_COMM_WORLD, &nbr);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);

/* Some long code I skiped */
/* ... */

MPI_Datatype sub;
MPI_Type_vector(nL+1, nL+1, nL_thread, MPI_DOUBLE, &sub);
MPI_Type_commit(&sub);

if(rank == 0)
MPI_Send(&c_new[3][0][0], 1, sub, rank+1,01, MPI_COMM_WORLD);
MPI_Recv(&c_new[4][0][0], 1, sub, rank+1,10, MPI_COMM_WORLD, &status);
if(rank == 1)
MPI_Recv(&c_new[0][0][0], 1, sub, rank-1,01, MPI_COMM_WORLD, &status);
MPI_Send(&c_new[1][0][0], 1, sub, rank-1,10, MPI_COMM_WORLD);




nL is the length in the y and z dimensions, same for all threads, nL_thread is the x dimension (in this particular case, nL_thread = 3 for rank 1 and 4 for rank 0). here I am trying to replace the faces (0,y,z) of rank 1 by (3,y,z) of rank 0, and (4,y,z) of rank 0 by (1,y,z) of rank 1.










share|improve this question
















I have two threads (rank 0 and 1), each containing a 3D matrix (x0,y,z) and (x1,y,z) with a different size along the x dimension. I would like to send a specific plane (x0 constant,y,z) from the first thread to the second and replace one of its face (x1 constant, y, z). The following code I made seems to work well when the two matrices have identical dimensions (even in x), but does not send the right face when x0 != x1 :



double ***alloc2(int x, int y,int z)

int i, j;

double ***array = (double ***) malloc(sizeof(double ***)*x);
for (i = 0; i<x; i++)
array[i] = (double **) malloc(sizeof(double*)*y);
for (j=0; j<y; j++)
array[i][j] = (double *) malloc(sizeof(double)*z);

return array;



int main(int argc, char *argv)

MPI_Status status;
MPI_Comm_size(MPI_COMM_WORLD, &nbr);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);

/* Some long code I skiped */
/* ... */

MPI_Datatype sub;
MPI_Type_vector(nL+1, nL+1, nL_thread, MPI_DOUBLE, &sub);
MPI_Type_commit(&sub);

if(rank == 0)
MPI_Send(&c_new[3][0][0], 1, sub, rank+1,01, MPI_COMM_WORLD);
MPI_Recv(&c_new[4][0][0], 1, sub, rank+1,10, MPI_COMM_WORLD, &status);
if(rank == 1)
MPI_Recv(&c_new[0][0][0], 1, sub, rank-1,01, MPI_COMM_WORLD, &status);
MPI_Send(&c_new[1][0][0], 1, sub, rank-1,10, MPI_COMM_WORLD);




nL is the length in the y and z dimensions, same for all threads, nL_thread is the x dimension (in this particular case, nL_thread = 3 for rank 1 and 4 for rank 0). here I am trying to replace the faces (0,y,z) of rank 1 by (3,y,z) of rank 0, and (4,y,z) of rank 0 by (1,y,z) of rank 1.







c mpi






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 9:12







Kyraz

















asked Nov 16 '18 at 6:50









KyrazKyraz

64




64












  • sizeof(double) in all allocations does not seem right. In fact the whole allocation does not make much sense.

    – Osiris
    Nov 16 '18 at 6:59











  • If you are using thread parallelisation you should use a proper 3D array, not some segmented nonsense. Different threads accessing different regions of the heap will be inefficient. See Correctly allocating multi-dimensional arrays for ways to fix the program.

    – Lundin
    Nov 16 '18 at 8:52











  • Indeed Osiris, I edited my malloc function :

    – Kyraz
    Nov 16 '18 at 9:03












  • MPI thread is not the appropriate terminology here. You can use MPI task or MPI process in order to avoid any confusion. Did you allocate your 3D matrix in contiguous memory ? This is a requirement for what you are trying to achieve. Please edit your question with a Minimal, Complete, and Verifiable example in order to clarify what you are doing.

    – Gilles Gouaillardet
    Nov 16 '18 at 14:27

















  • sizeof(double) in all allocations does not seem right. In fact the whole allocation does not make much sense.

    – Osiris
    Nov 16 '18 at 6:59











  • If you are using thread parallelisation you should use a proper 3D array, not some segmented nonsense. Different threads accessing different regions of the heap will be inefficient. See Correctly allocating multi-dimensional arrays for ways to fix the program.

    – Lundin
    Nov 16 '18 at 8:52











  • Indeed Osiris, I edited my malloc function :

    – Kyraz
    Nov 16 '18 at 9:03












  • MPI thread is not the appropriate terminology here. You can use MPI task or MPI process in order to avoid any confusion. Did you allocate your 3D matrix in contiguous memory ? This is a requirement for what you are trying to achieve. Please edit your question with a Minimal, Complete, and Verifiable example in order to clarify what you are doing.

    – Gilles Gouaillardet
    Nov 16 '18 at 14:27
















sizeof(double) in all allocations does not seem right. In fact the whole allocation does not make much sense.

– Osiris
Nov 16 '18 at 6:59





sizeof(double) in all allocations does not seem right. In fact the whole allocation does not make much sense.

– Osiris
Nov 16 '18 at 6:59













If you are using thread parallelisation you should use a proper 3D array, not some segmented nonsense. Different threads accessing different regions of the heap will be inefficient. See Correctly allocating multi-dimensional arrays for ways to fix the program.

– Lundin
Nov 16 '18 at 8:52





If you are using thread parallelisation you should use a proper 3D array, not some segmented nonsense. Different threads accessing different regions of the heap will be inefficient. See Correctly allocating multi-dimensional arrays for ways to fix the program.

– Lundin
Nov 16 '18 at 8:52













Indeed Osiris, I edited my malloc function :

– Kyraz
Nov 16 '18 at 9:03






Indeed Osiris, I edited my malloc function :

– Kyraz
Nov 16 '18 at 9:03














MPI thread is not the appropriate terminology here. You can use MPI task or MPI process in order to avoid any confusion. Did you allocate your 3D matrix in contiguous memory ? This is a requirement for what you are trying to achieve. Please edit your question with a Minimal, Complete, and Verifiable example in order to clarify what you are doing.

– Gilles Gouaillardet
Nov 16 '18 at 14:27





MPI thread is not the appropriate terminology here. You can use MPI task or MPI process in order to avoid any confusion. Did you allocate your 3D matrix in contiguous memory ? This is a requirement for what you are trying to achieve. Please edit your question with a Minimal, Complete, and Verifiable example in order to clarify what you are doing.

– Gilles Gouaillardet
Nov 16 '18 at 14:27












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53332791%2fsend-and-recieve-3d-matrix-with-mpi-c%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53332791%2fsend-and-recieve-3d-matrix-with-mpi-c%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

Evgeni Malkin