MPI undefined in Visual Studio 2015









up vote
0
down vote

favorite












I was trying to install and run MS-MPI following this tutorial. I have installed MS-MPI and all my system variables are set correctly, see: vars



I have set all links in VSlib in linkerlib32includes



Having these linked to the project, I would expect MPI to work. In IDE no syntax errors are shown, MPI functions are recognized, just as in next picture. However compiling an c++ source file with MPI functions produces Undeclared identifiers errors. What do I do wrong? recognized



Here is my code if it matters



 /*
* Transmit a message in a 3-process system.
*/
#include <mpi.h>
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>

#define BUFSIZE 10
int main(int argc, char *argv)
int size, rank;
int slave;
int buf[BUFSIZE];
int n, value;
float rval;
MPI_Status status;
/* Initialize MPI */
MPI_Init(&argc, &argv);
/*
* Determine size in the world group.
*/
MPI_Comm_size(MPI_COMM_WORLD, &size);
if (size == 3) /* Correct number of processes *
/*
* Determine my rank in the world group.
* The master will be rank 0 and the slaves, rank 1...size-1
*/

MPI_Comm_rank(MPI_COMM_WORLD, &rank);

if (rank == 0) /* Master */
buf[0] = 5; buf[1] = 1; buf[2] = 8; buf[3] = 7; buf[4] = 6;
buf[5] = 5; buf[6] = 4; buf[7] = 2; buf[8] = 3; buf[9] = 1;
printf("n Sending the values 5,1,8,7,6,5,4,2,3,1");
printf("n -----------------------------");
for (slave = 1; slave < size; slave++)
printf("n from master %d to slave %d", rank, slave);
MPI_Send(buf, 10, MPI_INT, slave, 1, MPI_COMM_WORLD);

printf("nn Receiving the results from slaves");
printf("n ---------------------------------");
MPI_Recv(&value, 1, MPI_INT, 1, 11, MPI_COMM_WORLD, &status);
printf("n Minimum %4d from slave 1", value);
MPI_Recv(&value, 1, MPI_INT, 2, 21, MPI_COMM_WORLD, &status);
printf("n Sum %4d from slave 2", value);
MPI_Recv(&value, 1, MPI_INT, 1, 12, MPI_COMM_WORLD, &status);
printf("n Maximum %4d from slave 1", value);
MPI_Recv(&rval, 1, MPI_FLOAT, 2, 22, MPI_COMM_WORLD, &status);
printf("n Average %4.2f from slave 2n", rval);

else
if (rank == 1) /* minmax slave */
MPI_Recv(buf, 10, MPI_INT, 0, 1, MPI_COMM_WORLD, &status);
value = 100;
for (n = 0; n<BUFSIZE; n++)
if (value>buf[n]) value = buf[n];

MPI_Send(&value, 1, MPI_INT, 0, 11, MPI_COMM_WORLD);
value = 0;
for (n = 0; n<BUFSIZE; n++)
if (value<buf[n]) value = buf[n];

MPI_Send(&value, 1, MPI_INT, 0, 12, MPI_COMM_WORLD);

else /* sumave slave */
MPI_Recv(buf, 10, MPI_INT, 0, 1, MPI_COMM_WORLD, &status);
value = 0;
for (n = 0; n<BUFSIZE; n++)
value = value + buf[n];

MPI_Send(&value, 1, MPI_INT, 0, 21, MPI_COMM_WORLD);
rval = (float)value / BUFSIZE;
MPI_Send(&rval, 1, MPI_FLOAT, 0, 22, MPI_COMM_WORLD);



MPI_Finalize();
return(0);
}









share|improve this question

















  • 1




    The #include for stdafx.h must be first.
    – Hans Passant
    yesterday














up vote
0
down vote

favorite












I was trying to install and run MS-MPI following this tutorial. I have installed MS-MPI and all my system variables are set correctly, see: vars



I have set all links in VSlib in linkerlib32includes



Having these linked to the project, I would expect MPI to work. In IDE no syntax errors are shown, MPI functions are recognized, just as in next picture. However compiling an c++ source file with MPI functions produces Undeclared identifiers errors. What do I do wrong? recognized



Here is my code if it matters



 /*
* Transmit a message in a 3-process system.
*/
#include <mpi.h>
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>

#define BUFSIZE 10
int main(int argc, char *argv)
int size, rank;
int slave;
int buf[BUFSIZE];
int n, value;
float rval;
MPI_Status status;
/* Initialize MPI */
MPI_Init(&argc, &argv);
/*
* Determine size in the world group.
*/
MPI_Comm_size(MPI_COMM_WORLD, &size);
if (size == 3) /* Correct number of processes *
/*
* Determine my rank in the world group.
* The master will be rank 0 and the slaves, rank 1...size-1
*/

MPI_Comm_rank(MPI_COMM_WORLD, &rank);

if (rank == 0) /* Master */
buf[0] = 5; buf[1] = 1; buf[2] = 8; buf[3] = 7; buf[4] = 6;
buf[5] = 5; buf[6] = 4; buf[7] = 2; buf[8] = 3; buf[9] = 1;
printf("n Sending the values 5,1,8,7,6,5,4,2,3,1");
printf("n -----------------------------");
for (slave = 1; slave < size; slave++)
printf("n from master %d to slave %d", rank, slave);
MPI_Send(buf, 10, MPI_INT, slave, 1, MPI_COMM_WORLD);

printf("nn Receiving the results from slaves");
printf("n ---------------------------------");
MPI_Recv(&value, 1, MPI_INT, 1, 11, MPI_COMM_WORLD, &status);
printf("n Minimum %4d from slave 1", value);
MPI_Recv(&value, 1, MPI_INT, 2, 21, MPI_COMM_WORLD, &status);
printf("n Sum %4d from slave 2", value);
MPI_Recv(&value, 1, MPI_INT, 1, 12, MPI_COMM_WORLD, &status);
printf("n Maximum %4d from slave 1", value);
MPI_Recv(&rval, 1, MPI_FLOAT, 2, 22, MPI_COMM_WORLD, &status);
printf("n Average %4.2f from slave 2n", rval);

else
if (rank == 1) /* minmax slave */
MPI_Recv(buf, 10, MPI_INT, 0, 1, MPI_COMM_WORLD, &status);
value = 100;
for (n = 0; n<BUFSIZE; n++)
if (value>buf[n]) value = buf[n];

MPI_Send(&value, 1, MPI_INT, 0, 11, MPI_COMM_WORLD);
value = 0;
for (n = 0; n<BUFSIZE; n++)
if (value<buf[n]) value = buf[n];

MPI_Send(&value, 1, MPI_INT, 0, 12, MPI_COMM_WORLD);

else /* sumave slave */
MPI_Recv(buf, 10, MPI_INT, 0, 1, MPI_COMM_WORLD, &status);
value = 0;
for (n = 0; n<BUFSIZE; n++)
value = value + buf[n];

MPI_Send(&value, 1, MPI_INT, 0, 21, MPI_COMM_WORLD);
rval = (float)value / BUFSIZE;
MPI_Send(&rval, 1, MPI_FLOAT, 0, 22, MPI_COMM_WORLD);



MPI_Finalize();
return(0);
}









share|improve this question

















  • 1




    The #include for stdafx.h must be first.
    – Hans Passant
    yesterday












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I was trying to install and run MS-MPI following this tutorial. I have installed MS-MPI and all my system variables are set correctly, see: vars



I have set all links in VSlib in linkerlib32includes



Having these linked to the project, I would expect MPI to work. In IDE no syntax errors are shown, MPI functions are recognized, just as in next picture. However compiling an c++ source file with MPI functions produces Undeclared identifiers errors. What do I do wrong? recognized



Here is my code if it matters



 /*
* Transmit a message in a 3-process system.
*/
#include <mpi.h>
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>

#define BUFSIZE 10
int main(int argc, char *argv)
int size, rank;
int slave;
int buf[BUFSIZE];
int n, value;
float rval;
MPI_Status status;
/* Initialize MPI */
MPI_Init(&argc, &argv);
/*
* Determine size in the world group.
*/
MPI_Comm_size(MPI_COMM_WORLD, &size);
if (size == 3) /* Correct number of processes *
/*
* Determine my rank in the world group.
* The master will be rank 0 and the slaves, rank 1...size-1
*/

MPI_Comm_rank(MPI_COMM_WORLD, &rank);

if (rank == 0) /* Master */
buf[0] = 5; buf[1] = 1; buf[2] = 8; buf[3] = 7; buf[4] = 6;
buf[5] = 5; buf[6] = 4; buf[7] = 2; buf[8] = 3; buf[9] = 1;
printf("n Sending the values 5,1,8,7,6,5,4,2,3,1");
printf("n -----------------------------");
for (slave = 1; slave < size; slave++)
printf("n from master %d to slave %d", rank, slave);
MPI_Send(buf, 10, MPI_INT, slave, 1, MPI_COMM_WORLD);

printf("nn Receiving the results from slaves");
printf("n ---------------------------------");
MPI_Recv(&value, 1, MPI_INT, 1, 11, MPI_COMM_WORLD, &status);
printf("n Minimum %4d from slave 1", value);
MPI_Recv(&value, 1, MPI_INT, 2, 21, MPI_COMM_WORLD, &status);
printf("n Sum %4d from slave 2", value);
MPI_Recv(&value, 1, MPI_INT, 1, 12, MPI_COMM_WORLD, &status);
printf("n Maximum %4d from slave 1", value);
MPI_Recv(&rval, 1, MPI_FLOAT, 2, 22, MPI_COMM_WORLD, &status);
printf("n Average %4.2f from slave 2n", rval);

else
if (rank == 1) /* minmax slave */
MPI_Recv(buf, 10, MPI_INT, 0, 1, MPI_COMM_WORLD, &status);
value = 100;
for (n = 0; n<BUFSIZE; n++)
if (value>buf[n]) value = buf[n];

MPI_Send(&value, 1, MPI_INT, 0, 11, MPI_COMM_WORLD);
value = 0;
for (n = 0; n<BUFSIZE; n++)
if (value<buf[n]) value = buf[n];

MPI_Send(&value, 1, MPI_INT, 0, 12, MPI_COMM_WORLD);

else /* sumave slave */
MPI_Recv(buf, 10, MPI_INT, 0, 1, MPI_COMM_WORLD, &status);
value = 0;
for (n = 0; n<BUFSIZE; n++)
value = value + buf[n];

MPI_Send(&value, 1, MPI_INT, 0, 21, MPI_COMM_WORLD);
rval = (float)value / BUFSIZE;
MPI_Send(&rval, 1, MPI_FLOAT, 0, 22, MPI_COMM_WORLD);



MPI_Finalize();
return(0);
}









share|improve this question













I was trying to install and run MS-MPI following this tutorial. I have installed MS-MPI and all my system variables are set correctly, see: vars



I have set all links in VSlib in linkerlib32includes



Having these linked to the project, I would expect MPI to work. In IDE no syntax errors are shown, MPI functions are recognized, just as in next picture. However compiling an c++ source file with MPI functions produces Undeclared identifiers errors. What do I do wrong? recognized



Here is my code if it matters



 /*
* Transmit a message in a 3-process system.
*/
#include <mpi.h>
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>

#define BUFSIZE 10
int main(int argc, char *argv)
int size, rank;
int slave;
int buf[BUFSIZE];
int n, value;
float rval;
MPI_Status status;
/* Initialize MPI */
MPI_Init(&argc, &argv);
/*
* Determine size in the world group.
*/
MPI_Comm_size(MPI_COMM_WORLD, &size);
if (size == 3) /* Correct number of processes *
/*
* Determine my rank in the world group.
* The master will be rank 0 and the slaves, rank 1...size-1
*/

MPI_Comm_rank(MPI_COMM_WORLD, &rank);

if (rank == 0) /* Master */
buf[0] = 5; buf[1] = 1; buf[2] = 8; buf[3] = 7; buf[4] = 6;
buf[5] = 5; buf[6] = 4; buf[7] = 2; buf[8] = 3; buf[9] = 1;
printf("n Sending the values 5,1,8,7,6,5,4,2,3,1");
printf("n -----------------------------");
for (slave = 1; slave < size; slave++)
printf("n from master %d to slave %d", rank, slave);
MPI_Send(buf, 10, MPI_INT, slave, 1, MPI_COMM_WORLD);

printf("nn Receiving the results from slaves");
printf("n ---------------------------------");
MPI_Recv(&value, 1, MPI_INT, 1, 11, MPI_COMM_WORLD, &status);
printf("n Minimum %4d from slave 1", value);
MPI_Recv(&value, 1, MPI_INT, 2, 21, MPI_COMM_WORLD, &status);
printf("n Sum %4d from slave 2", value);
MPI_Recv(&value, 1, MPI_INT, 1, 12, MPI_COMM_WORLD, &status);
printf("n Maximum %4d from slave 1", value);
MPI_Recv(&rval, 1, MPI_FLOAT, 2, 22, MPI_COMM_WORLD, &status);
printf("n Average %4.2f from slave 2n", rval);

else
if (rank == 1) /* minmax slave */
MPI_Recv(buf, 10, MPI_INT, 0, 1, MPI_COMM_WORLD, &status);
value = 100;
for (n = 0; n<BUFSIZE; n++)
if (value>buf[n]) value = buf[n];

MPI_Send(&value, 1, MPI_INT, 0, 11, MPI_COMM_WORLD);
value = 0;
for (n = 0; n<BUFSIZE; n++)
if (value<buf[n]) value = buf[n];

MPI_Send(&value, 1, MPI_INT, 0, 12, MPI_COMM_WORLD);

else /* sumave slave */
MPI_Recv(buf, 10, MPI_INT, 0, 1, MPI_COMM_WORLD, &status);
value = 0;
for (n = 0; n<BUFSIZE; n++)
value = value + buf[n];

MPI_Send(&value, 1, MPI_INT, 0, 21, MPI_COMM_WORLD);
rval = (float)value / BUFSIZE;
MPI_Send(&rval, 1, MPI_FLOAT, 0, 22, MPI_COMM_WORLD);



MPI_Finalize();
return(0);
}






c++ visual-studio-2015 mpi






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 13:41









Ruli

867




867







  • 1




    The #include for stdafx.h must be first.
    – Hans Passant
    yesterday












  • 1




    The #include for stdafx.h must be first.
    – Hans Passant
    yesterday







1




1




The #include for stdafx.h must be first.
– Hans Passant
yesterday




The #include for stdafx.h must be first.
– Hans Passant
yesterday












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










After a time I have found where was the bug. Everything is fine with my setting, problem is only with the .cpp extension. Changing it to .c project helped and all works as expected.



If I want to run it as c++, #include stdafx.h bust take place before mpi






share|improve this answer






















    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',
    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%2f53239561%2fmpi-undefined-in-visual-studio-2015%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    After a time I have found where was the bug. Everything is fine with my setting, problem is only with the .cpp extension. Changing it to .c project helped and all works as expected.



    If I want to run it as c++, #include stdafx.h bust take place before mpi






    share|improve this answer


























      up vote
      0
      down vote



      accepted










      After a time I have found where was the bug. Everything is fine with my setting, problem is only with the .cpp extension. Changing it to .c project helped and all works as expected.



      If I want to run it as c++, #include stdafx.h bust take place before mpi






      share|improve this answer
























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        After a time I have found where was the bug. Everything is fine with my setting, problem is only with the .cpp extension. Changing it to .c project helped and all works as expected.



        If I want to run it as c++, #include stdafx.h bust take place before mpi






        share|improve this answer














        After a time I have found where was the bug. Everything is fine with my setting, problem is only with the .cpp extension. Changing it to .c project helped and all works as expected.



        If I want to run it as c++, #include stdafx.h bust take place before mpi







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited yesterday

























        answered yesterday









        Ruli

        867




        867



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239561%2fmpi-undefined-in-visual-studio-2015%23new-answer', 'question_page');

            );

            Post as a guest














































































            Popular posts from this blog

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            政党

            天津地下鉄3号線