Home:ALL Converter>mpi & number of processor

mpi & number of processor

Ask Time:2021-06-05T19:45:23         Author:Toni Rossi

Json Formatter

hello i'm using windows and i use both codeblock & visual studio 2019 to programm using mpi. but after i use this code

int main(int argc, char *argv[])
{
    int rank, size;

    MPI_Init(&argc, &argv);

    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);

    printf("Hello world! I am %d of %d\n", rank, size);

    MPI_Finalize();

    return 0;
}

it return me 1 processor while if use echo %NUMBER_OF_PROCESSORS% on normal cmd it return me 4 .

i was using MPI_SEND & MPI_Recv and i had a A FATAL ERROR AFTER USING THIS CODE

#include <stdio.h>
#include "mpi.h"

int main(int argc, char* argv[])
{
    int menum, nproc;
    int n, tag, num;
    MPI_Status info;
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &menum);
    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
    printf("menum:%d      nproc :%d", menum, nproc);
    if (menum == 0) {
        printf("\ninsert number: ");
        scanf_s(" %d", &n);
        tag = 10;
        MPI_Send(&n, 1, MPI_INT, 1, tag, MPI_COMM_WORLD);
    }
    else {
        tag = 10;
        MPI_Recv(&n, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &info);
    }
    MPI_Get_count(&info, MPI_INT, &num);
    MPI_Finalize();
    return 0;
}

i searched online and as i could understand it's like mpi cant find another processor to send the value. how can i make it?? is there a way i could use mpi with all my processor with visual studio or codeblock?

job aborted: [ranks] message

[0] fatal error Fatal error in MPI_Send: Invalid rank, error stack: MPI_Send(buf=0x0056F9F0, count=1, MPI_INT, dest=1, tag=10, MPI_COMM_WORLD) failed Invalid rank has value 1 but must be nonnegative and less than 1

Author:Toni Rossi,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/67849223/mpi-number-of-processor
yy