Created
April 7, 2020 21:53
-
-
Save leopoldcambier/a1023971f6cb3aaad8e30d27ac60bc1a to your computer and use it in GitHub Desktop.
Creation of a contiguous type in MPI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <mpi.h> | |
int main(int argc, char* argv[]) | |
{ | |
MPI_Init(&argc, &argv); | |
int size; | |
MPI_Comm_size(MPI_COMM_WORLD, &size); | |
int my_rank; | |
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); | |
MPI_Datatype MPI_MEGABYTE_TYPE; | |
int mega = 1 << 20; | |
MPI_Type_contiguous(mega, MPI_BYTE, &MPI_MEGABYTE_TYPE); | |
MPI_Type_commit(&MPI_MEGABYTE_TYPE); | |
int count = 4; | |
size_t length = mega * count; | |
char buffer[mega * count]; | |
if(my_rank == 0) { | |
for(size_t i = 0; i < length; i++) { | |
buffer[i] = 'l'; | |
} | |
MPI_Send(&buffer, count, MPI_MEGABYTE_TYPE, 1, 0, MPI_COMM_WORLD); | |
} else { | |
MPI_Recv(&buffer, count, MPI_MEGABYTE_TYPE, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); | |
printf("%c\n", buffer[length-1]); | |
} | |
MPI_Finalize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment