Created
March 30, 2018 10:53
-
-
Save korkmazkadir/7fb4edba5b20c8c3f66b2cf80a0a236c to your computer and use it in GitHub Desktop.
MPI virtual Grid Creation
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
/* | |
* File: broadcast.c | |
* Author: korkmaka | |
* | |
* Created on 20 mars 2018, 09:52 | |
*/ | |
#include <unistd.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <mpi.h> | |
typedef struct meta_data { | |
int rank; | |
int size; | |
int nameLength; | |
char processName[25]; | |
} meta_data; | |
meta_data *getMetaData(MPI_Comm communicator) { | |
meta_data *md = malloc(sizeof (meta_data)); | |
int nameSize = 25; | |
if (communicator == NULL) { | |
MPI_Comm_rank(MPI_COMM_WORLD, &md->rank); | |
MPI_Comm_size(MPI_COMM_WORLD, &md->size); | |
MPI_Get_processor_name(md->processName, &nameSize); | |
} else { | |
MPI_Comm_rank(communicator, &md->rank); | |
MPI_Comm_size(communicator, &md->size); | |
MPI_Get_processor_name(md->processName, &nameSize); | |
} | |
return md; | |
} | |
void initArray(int *array, int size, int value) { | |
for (int i = 0; i < size; i++) { | |
array[i] = value; | |
} | |
} | |
void printArray(int *array, int size) { | |
for (int i = 0; i < size; i++) { | |
printf("%d - ", array[i]); | |
} | |
printf("\n"); | |
} | |
/* | |
* this is doing reduction globally | |
*/ | |
int main(int argc, char** argv) { | |
MPI_Init(NULL, NULL); | |
meta_data *md = getMetaData(NULL); | |
int numberOfNodes = 16; | |
int numberOfdimention = 2; | |
int dims[2] = {4, 4}; | |
int periods[2] = {0, 0}; | |
MPI_Comm new_comm; | |
int result = MPI_Dims_create(numberOfNodes, numberOfdimention, dims); | |
printf("MPI_Dims_create result %d \n", result); | |
result = MPI_Cart_create(MPI_COMM_WORLD, numberOfdimention, dims, periods, 0, &new_comm); | |
printf("MPI_Cart_create result %d \n", result); | |
md = getMetaData(new_comm); | |
for(int i = 0; i < numberOfNodes; i++){ | |
int dim[2]; | |
MPI_Cart_coords(new_comm,i,numberOfdimention,dim); | |
printf("%d --> %d - %d \n", i, dim[0], dim[1] ); | |
} | |
//printf("old Rank %d new rank %d \n", oldRank, md->rank ); | |
MPI_Finalize(); | |
return (EXIT_SUCCESS); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment