Получение тома куба с использованием MPI_type_contiguous - PullRequest
0 голосов
/ 01 мая 2019

Я пишу некоторый код для действительно простой задачи (получение объема куба) с использованием непрерывного MPI_type.Моя проблема в том, что, кроме объявления нового MPI_TYPE, я не знаю, как рассчитать объем куба с помощью MPI (я новичок в параллельных вычислениях).Вот мой код.

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

typedef struct{
    int x;
    int y;
    int z;
}COORD;

// Data on the COORD struct
#define N 3

// Coordinates of the cube
#define C 8

COORD* array(int tam)
{
    COORD* arr;
    COORD = (COORD*)malloc(tam*sizeof(COORD));

    return arr;
}

// Construct a new coordinate
COORD constructor(int a, int b, int c)
{
    COORD cord;

    cord.x = a;
    cord.y = b;
    cord.z = c;

    return cord; 
}

// Main
void main(int argc,char* argv[])
{
    int idProc, numProc;
    COORD a, b, c, d, e, f, g, h;
    COORD* array;
    MPI_Status status;

    MPI_Init(&argc,&argv);
    MPI_Comm_rank(MPI_COMM_WORLD,&idProc);
    MPI_Comm_size(MPI_COMM_WORLD,&numProc);

    MPI_Type_contiguous(N, MPI_INT, &COORD);
    MPI_Type_commit(&COORD);

    if(idProc == 0)
    {   
        int i, x, y, z;     
        array = GeneraArreglo(C);

        for(i = 0; i < 8; i++)
        {
            printf("X %d: \n", i);
            scanf(%d, &x);
            printf("Y %d: \n", i);
            scanf(%d, &y);
            printf("Z %d: \n", i);
            scanf(%d, &z);

            array[i] = constructor(x, y , z); 
        }

        MPI_Send(array, C, COORD, 1, 0, MPI_COMM_WORLD);
    }
    else
    {
        printf("Cube volume: \n");
        MPI_Recv(buffer, 4, COORD, 0, 0, MPI_COMM_WORLD, &status);


    }

    MPI_Finalize();
}

Как вы видите, я почти вижу, что делаю, однако у меня есть сомнения по поводу части программы MPI_Recieve.

...