Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <mpi.h>
- #include <iostream>
- struct Liczba {
- int cal;
- float dzie;
- };
- int main(int argc, char *argv[]) {
- int npes;
- int myrank;
- double start, end;
- MPI_Init(&argc, &argv);
- const int nitems = 2;
- int blocklengths[2] = {1, 1};
- MPI_Datatype types[2] = {MPI_INT, MPI_INT};
- MPI_Datatype mpi_liczba;
- MPI_Aint offsets[2];
- offsets[0] = offsetof(Liczba, cal);
- offsets[1] = offsetof(Liczba, dzie);
- MPI_Type_create_struct(nitems, blocklengths, offsets, types, &mpi_liczba);
- MPI_Type_commit(&mpi_liczba);
- start = MPI_Wtime();
- MPI_Comm_size(MPI_COMM_WORLD, &npes);
- MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
- const int LICZBY_COUNT = 1;
- Liczba liczba;
- liczba.cal = 3;
- liczba.dzie = 4;
- if (myrank == 0) {
- MPI_Ssend(&liczba, LICZBY_COUNT, mpi_liczba, 1, 13, MPI_COMM_WORLD);
- } else if (myrank == 1) {
- MPI_Status status;
- Liczba liczbaRecv;
- MPI_Recv(&liczbaRecv, LICZBY_COUNT, mpi_liczba, 0, 13, MPI_COMM_WORLD, &status);
- // for (int i = 0; i < LICZBY_COUNT; i++) {
- std::cout << liczbaRecv.cal << "." << liczbaRecv.dzie << std::endl;
- // }
- }
- end = MPI_Wtime();
- MPI_Finalize();
- if (myrank == 0) {
- printf("end of process %lf\n", end - start);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement