r-aa (r_aa) wrote,
r-aa
r_aa

Простой пример MPI_Reduce в C

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

typedef struct
{
    double D;
    int I;
}
DI;

int main(int argc, char **argv)
{
    int e = 0;
    DI di, min = { 0 }, max = { 0 };

    e = MPI_Init(&argc, &argv);
    e = MPI_Comm_rank(MPI_COMM_WORLD, &di.I);
    srand(di.I);
    di.D = rand();
    e = MPI_Reduce((void *)&di, (void *)&min, 1, MPI_DOUBLE_INT, MPI_MINLOC, 0, MPI_COMM_WORLD);
    e = MPI_Reduce((void *)&di, (void *)&max, 1, MPI_DOUBLE_INT, MPI_MAXLOC, 0, MPI_COMM_WORLD);

    if (di.I == 0)
    {
        printf("min = %le (%d), max = %le (%d)\n", min.D, min.I, max.D, max.I);
    }

    e = MPI_Finalize();

    return 0;
}
Tags: c/c++, it, mpi, программирование, шпаргалки
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments