Newer
Older
/**
* Author: Baptiste Coudray
* School: HEPIA
* Class: ITI-3
* Year 2020-2021
*/
#include <stdio.h>
#include <stdint.h>
#define INDEX_2D_TO_1D(y, x, nb_columns) ((y) * (nb_columns) + (x))
void init_chunk_board(chunk_info_t *ci) {
for (int i = 0; i < ci->dimensions[0]; ++i) {
for (int j = 0; j < ci->dimensions[1]; ++j) {
size_t k = INDEX_2D_TO_1D((size_t) i, (size_t) j, (size_t) ci->dimensions[1]);
((int8_t *) ci->data)[k] = rand() % 2;
void compute_next_chunk_board(struct dispatch_context *dc, struct futhark_context *fc, chunk_info_t *ci) {
envelope_t outer_envelope = get_outer_envelope(dc, fc, 1);
struct futhark_opaque_envelope_2d_i8 *fut_outer_envelope = futhark_outer_envelope_new(dc, fc, &outer_envelope,
futhark_restore_opaque_envelope_2d_i8,
struct futhark_i8_2d *fut_chunk_board = futhark_new_i8_2d(fc, ci->data, ci->dimensions[0], ci->dimensions[1]);
struct futhark_i8_2d *fut_next_chunk_board;
futhark_entry_next_chunk_board(fc, &fut_next_chunk_board, fut_chunk_board, fut_outer_envelope);
futhark_values_i8_2d(fc, fut_next_chunk_board, ci->data);
futhark_free_i8_2d(fc, fut_next_chunk_board);
futhark_free_opaque_envelope_2d_i8(fc, fut_outer_envelope);
if (argc < 4) {
printf("usage: mpirun -n <nb_proc> %s <nb_devices> <height> <width>\n", argv[0]);
return EXIT_FAILURE;
int my_rank;
int world_size;
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
struct futhark_context_config *fut_config = futhark_context_config_new();
int nb_devices = atoi(argv[1]);
#if defined(FUTHARK_BACKEND_cuda) || defined(FUTHARK_BACKEND_opencl)
futhark_context_config_list_devices(fut_config);
char device[4] = {0};
snprintf(device, sizeof(device), "#%d", my_rank % nb_devices);
futhark_context_config_set_device(fut_config, device);
struct futhark_context *fut_context = futhark_context_new(fut_config);
int board_n = atoi(argv[2]);
int board_m = atoi(argv[3]);
int board_dimensions[2] = {board_n, board_m};
struct dispatch_context *disp_context = dispatch_context_new(board_dimensions, MPI_INT8_T, 2);
chunk_info_t ci = get_chunk_info(disp_context);
init_chunk_board(&ci);
for (int j = 0; j < N_ITERATIONS; ++j) {
compute_next_chunk_board(disp_context, fut_context, &ci);
}
double finish = MPI_Wtime();
if (my_rank == ROOT_RANK) {
printf("%d;%d;%d;%d;%f\n", world_size, nb_devices, board_n, board_m, finish - start);
dispatch_context_free(disp_context);
futhark_context_config_free(fut_config);
futhark_context_free(fut_context);
return MPI_Finalize();