Skip to content
Snippets Groups Projects
Verified Commit 4305576a authored by baptiste.coudray's avatar baptiste.coudray
Browse files

Added unit tests for get_outer_envelope_3d, fixed bugs, beginning lbm

parent c8558fd6
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GCC_COMPILE_FLAGS}")
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/envelope.h ${CMAKE_CURRENT_SOURCE_DIR}/envelope.c
COMMAND futhark opencl ${CMAKE_CURRENT_SOURCE_DIR}/envelope.fut --library
COMMAND futhark multicore ${CMAKE_CURRENT_SOURCE_DIR}/envelope.fut --library
DEPENDS envelope.fut
)
add_custom_target(futhark_opencl DEPENDS envelope.h envelope.c)
......@@ -25,9 +25,9 @@ add_executable(futhark_mpi_tests tests/main.c chunk_info.h chunk_info.c dispatch
add_dependencies(futhark_mpi_tests futhark_opencl)
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
target_link_libraries(futhark_mpi_tests m ${MPI_C_LIBRARIES} "-framework OpenCL")
target_link_libraries(futhark_mpi_tests m pthread ${MPI_C_LIBRARIES})
endif ()
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
target_link_libraries(futhark_mpi_tests OpenCL m ${MPI_C_LIBRARIES})
target_link_libraries(futhark_mpi_tests m ${MPI_C_LIBRARIES})
endif ()
This diff is collapsed.
......@@ -83,9 +83,9 @@ entry get_envelope_3d [n][m][l] (cube:[n][m][l]u8) (thickness_y: i64) (thickness
let top = {
north_west = cube[0:thickness_y, 0:thickness_x, l-thickness_z:] :> [thickness_y][thickness_x][thickness_z]u8,
west = cube[0:thickness_y, 0:thickness_x, :] :> [thickness_y][thickness_x][l]u8,
south_west = cube[n - thickness_y:, 0:thickness_x, 0:thickness_z] :> [thickness_y][thickness_x][thickness_z]u8,
south_west = cube[0:thickness_y, 0:thickness_x, 0:thickness_z] :> [thickness_y][thickness_x][thickness_z]u8,
south = cube[0:thickness_y, :, 0:thickness_z] :> [thickness_y][m][thickness_z]u8,
south_east = cube[n - thickness_y:n, m - thickness_x:, 0:thickness_z] :> [thickness_y][thickness_x][thickness_z]u8,
south_east = cube[0:thickness_y, m - thickness_x:, 0:thickness_z] :> [thickness_y][thickness_x][thickness_z]u8,
east = cube[0:thickness_y, m-thickness_x:, :] :> [thickness_y][thickness_x][l]u8,
north_east = cube[0:thickness_y, m - thickness_x:, l-thickness_z:] :> [thickness_y][thickness_x][thickness_z]u8,
north = cube[0:thickness_y, :, l-thickness_z:] :> [thickness_y][m][thickness_z]u8,
......@@ -98,7 +98,7 @@ entry get_envelope_3d [n][m][l] (cube:[n][m][l]u8) (thickness_y: i64) (thickness
south = cube[n-thickness_y:, :, 0:thickness_z] :> [thickness_y][m][thickness_z]u8,
south_east = cube[n - thickness_y:n, m - thickness_x:, 0:thickness_z] :> [thickness_y][thickness_x][thickness_z]u8,
east = cube[n-thickness_y:, m-thickness_x:, :] :> [thickness_y][thickness_x][l]u8,
north_east = cube[n - thickness_y:n, m - thickness_x:, l-thickness_z:] :> [thickness_y][thickness_x][thickness_z]u8,
north_east = cube[n - thickness_y:, m - thickness_x:, l-thickness_z:] :> [thickness_y][thickness_x][thickness_z]u8,
north = cube[n-thickness_y:, :, l-thickness_z:] :> [thickness_y][m][thickness_z]u8,
surface = cube[n-thickness_y:, :, :] :> [thickness_y][m][l]u8
}
......
......@@ -6,11 +6,14 @@
#include "../envelope.h"
#define INDEX_2D_TO_1D(y, x, nb_columns) ((y) * (nb_columns) + (x))
#define INDEX_3D_TO_1D(y, x, z, nb_columns, nb_depths) ((x) + (nb_columns) * ((y) + (nb_depths) * (z)))
void init_chunk_data(chunk_info_t *ci) {
for (int y = 0; y < ci->dimensions[0]; ++y) {
for (int x = 0; x < ci->dimensions[1]; ++x) {
((int *) ci->data)[INDEX_2D_TO_1D(y, x, ci->dimensions[1])] = y + x;
for (int z = 0; z < ci->dimensions[2]; ++z) {
((int *) ci->data)[INDEX_3D_TO_1D(y, x, z, ci->dimensions[1], ci->dimensions[2])] = y + x + z;
}
}
}
}
......@@ -175,14 +178,8 @@ void tests_1_process(struct futhark_context *fc) {
int expected_se[] = {23};
int expected_sw[] = {9};
assert(memcmp(expected_north, inner_envelope.front->north->data, sizeof(expected_north)) == 0);
assert(memcmp(expected_east, inner_envelope.front->east->data, sizeof(expected_east)) == 0);
assert(memcmp(expected_south, inner_envelope.front->south->data, sizeof(expected_south)) == 0);
assert(memcmp(expected_west, inner_envelope.front->west->data, sizeof(expected_west)) == 0);
assert(memcmp(expected_nw, inner_envelope.front->north_west->data, sizeof(expected_nw)) == 0);
assert(memcmp(expected_ne, inner_envelope.front->north_east->data, sizeof(expected_ne)) == 0);
assert(memcmp(expected_se, inner_envelope.front->south_east->data, sizeof(expected_se)) == 0);
assert(memcmp(expected_sw, inner_envelope.front->south_west->data, sizeof(expected_sw)) == 0);
envelope_free(&inner_envelope);
}
......@@ -434,6 +431,20 @@ void tests_2_processes(int my_rank, struct futhark_context *fc) {
}
dispatch_context_free(dc);
}
printf("Testing dispatch_context_new with 2 processes. Dimensions = 21x41x3...\n");
{
int dimensions[3] = {21, 41, 3};
struct dispatch_context *dc = dispatch_context_new(dimensions, MPI_INT, 3);
dispatch_context_print(dc);
chunk_info_t ci = get_chunk_info(dc);
chunk_info_print(&ci);
envelope_t outer_envelope = get_outer_envelope(dc, fc, 1);
envelope_free(&outer_envelope);
dispatch_context_free(dc);
}
}
void tests_3_processes(int my_rank, struct futhark_context *fc) {
......@@ -553,6 +564,35 @@ void tests_4_processes(int my_rank, struct futhark_context *fc) {
}
dispatch_context_free(dc);
}
printf("Testing dispatch_context_new with 4 processes. Dimensions = 21x42...\n");
{
int dimensions[2] = {21, 42};
struct dispatch_context *dc = dispatch_context_new(dimensions, MPI_INT, 2);
chunk_info_t ci = get_chunk_info(dc);
if (my_rank == 0) {
assert(ci.dimensions[0] == 11 && ci.dimensions[1] == 21);
assert(ci.data != NULL);
assert(ci.count == 231);
assert(ci.y == 0 && ci.x == 0);
} else if (my_rank == 1) {
assert(ci.dimensions[0] == 11 && ci.dimensions[1] == 21);
assert(ci.data != NULL);
assert(ci.count == 231);
assert(ci.y == 0 && ci.x == 21);
} else if (my_rank == 2) {
assert(ci.dimensions[0] == 10 && ci.dimensions[1] == 21);
assert(ci.data != NULL);
assert(ci.count == 210);
assert(ci.y == 11 && ci.x == 0);
} else {
assert(ci.dimensions[0] == 10 && ci.dimensions[1] == 21);
assert(ci.data != NULL);
assert(ci.count == 210);
assert(ci.y == 11 && ci.x == 21);
}
dispatch_context_free(dc);
}
}
void tests_6_processes(int my_rank, struct futhark_context *fc) {
......@@ -609,69 +649,123 @@ void tests_6_processes(int my_rank, struct futhark_context *fc) {
dispatch_context_free(dc);
}
printf("Testing dispatch_context_new with 6 processes. Dimensions = 21x42...\n");
printf("Testing dispatch_context_new with 6 processes. Dimensions = 21x42x5...\n");
{
int dimensions[2] = {21, 42};
struct dispatch_context *dc = dispatch_context_new(dimensions, MPI_INT, 2);
int dimensions[3] = {24, 24, 6};
struct dispatch_context *dc = dispatch_context_new(dimensions, MPI_UINT8_T, 3);
dispatch_context_print(dc);
chunk_info_t ci = get_chunk_info(dc);
switch (my_rank) {
case 0:
assert(ci.dimensions[0] == 11 && ci.dimensions[1] == 14);
assert(ci.data != NULL);
assert(ci.count == 154);
assert(ci.y == 0 && ci.x == 0);
break;
case 1:
assert(ci.dimensions[0] == 11 && ci.dimensions[1] == 14);
assert(ci.data != NULL);
assert(ci.count == 154);
assert(ci.y == 0 && ci.x == 14);
break;
case 2:
assert(ci.dimensions[0] == 11 && ci.dimensions[1] == 14);
assert(ci.data != NULL);
assert(ci.count == 154);
assert(ci.y == 0 && ci.x == 28);
break;
case 3:
assert(ci.dimensions[0] == 10 && ci.dimensions[1] == 14);
assert(ci.data != NULL);
assert(ci.count == 140);
assert(ci.y == 11 && ci.x == 0);
break;
case 4:
assert(ci.dimensions[0] == 10 && ci.dimensions[1] == 14);
assert(ci.data != NULL);
assert(ci.count == 140);
assert(ci.y == 11 && ci.x == 14);
break;
case 5:
assert(ci.dimensions[0] == 10 && ci.dimensions[1] == 14);
assert(ci.data != NULL);
assert(ci.count == 140);
assert(ci.y == 11 && ci.x == 28);
break;
default:
break;
}
envelope_t inner_envelope = get_inner_envelope(dc, fc, 1);
envelope_free(&inner_envelope);
envelope_t outer_envelope = get_outer_envelope(dc, fc, 1);
envelope_free(&outer_envelope);
dispatch_context_free(dc);
}
}
void tests_12_processes(int my_rank, struct futhark_context *fc) {
printf("Testing dispatch_context_new with 12 processes. Dimensions = 2x2x2...\n");
void tests_8_processes(int my_rank, struct futhark_context *fc) {
printf("Testing dispatch_context_new with 8 processes. Dimensions = 8x8x8...\n");
{
int dimensions[3] = {10, 10, 3};
int dimensions[3] = {8, 8, 8};
struct dispatch_context *dc = dispatch_context_new(dimensions, MPI_INT, 3);
chunk_info_t ci = get_chunk_info(dc);
dispatch_context_print(dc);
chunk_info_t ci = get_chunk_info(dc);
chunk_info_print(&ci);
init_chunk_data(&ci);
envelope_t inner_envelope = get_inner_envelope(dc, fc, 1);
envelope_free(&inner_envelope);
envelope_t outer_envelope = get_outer_envelope(dc, fc, 1);
envelope_init_accessors(&outer_envelope);
if (my_rank == 0) {
int expected_back_surface[] = {0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6};
int expected_front_surface[] = {3, 4, 5, 6, 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8, 9};
int expected_right_surface[] = {0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6};
int expected_left_surface[] = {3, 4, 5, 6, 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8, 9};
int expected_top_surface[] = {3,4,5,6, 4,5,6,7, 5,6,7,8, 6,7,8,9};
int expected_bottom_surface[] = {0,1,2,3, 1,2,3,4, 2,3,4,5, 3,4,5,6};
int expected_back_east[] = {0,1,2,3};
int expected_back_west[] = {3,4,5,6};
int expected_front_east[] = {3,4,5,6};
int expected_front_west[] = {6,7,8,9};
int expected_bottom_ne[] = {0};
int expected_bottom_nw[] = {3};
int expected_bottom_se[] = {3};
int expected_bottom_sw[] = {6};
int expected_bottom_west[] = {3,4,5,6};
int expected_bottom_east[] = {0,1,2,3};
int expected_bottom_north[] = {0,1,2,3};
int expected_bottom_south[] = {3,4,5,6};
int expected_top_ne[] = {3};
int expected_top_nw[] = {6};
int expected_top_se[] = {6};
int expected_top_sw[] = {9};
int expected_top_west[] = {6,7,8,9};
int expected_top_east[] = {3,4,5,6};
int expected_top_north[] = {3,4,5,6};
int expected_top_south[] = {6,7,8,9};
assert(memcmp(outer_envelope.back->surface->data, expected_back_surface, sizeof(expected_back_surface)) ==
0);
assert(memcmp(outer_envelope.back->east->data, expected_back_east, sizeof(expected_back_east)) ==
0);
assert(memcmp(outer_envelope.back->west->data, expected_back_west, sizeof(expected_back_west)) ==
0);
assert(memcmp(outer_envelope.front->surface->data, expected_front_surface, sizeof(expected_front_surface)) ==
0);
assert(memcmp(outer_envelope.front->east->data, expected_front_east, sizeof(expected_front_east)) ==
0);
assert(memcmp(outer_envelope.front->west->data, expected_front_west, sizeof(expected_front_west)) ==
0);
assert(memcmp(outer_envelope.right->surface->data, expected_right_surface, sizeof(expected_right_surface)) ==
0);
assert(memcmp(outer_envelope.left->surface->data, expected_left_surface, sizeof(expected_left_surface)) ==
0);
assert(memcmp(outer_envelope.bottom->surface->data, expected_bottom_surface, sizeof(expected_bottom_surface)) ==
0);
assert(memcmp(outer_envelope.bottom->north_east->data, expected_bottom_ne, sizeof(expected_bottom_ne)) ==
0);
assert(memcmp(outer_envelope.bottom->north_west->data, expected_bottom_nw, sizeof(expected_bottom_nw)) ==
0);
assert(memcmp(outer_envelope.bottom->south_east->data, expected_bottom_se, sizeof(expected_bottom_se)) ==
0);
assert(memcmp(outer_envelope.bottom->north->data, expected_bottom_north, sizeof(expected_bottom_north)) ==
0);
assert(memcmp(outer_envelope.bottom->west->data, expected_bottom_west, sizeof(expected_bottom_west)) ==
0);
assert(memcmp(outer_envelope.bottom->south->data, expected_bottom_south, sizeof(expected_bottom_south)) ==
0);
assert(memcmp(outer_envelope.bottom->east->data, expected_bottom_east, sizeof(expected_bottom_east)) ==
0);
assert(memcmp(outer_envelope.top->surface->data, expected_top_surface, sizeof(expected_top_surface)) ==
0);
assert(memcmp(outer_envelope.top->south_west->data, expected_top_sw, sizeof(expected_top_sw)) ==
0);
assert(memcmp(outer_envelope.top->north_east->data, expected_top_ne, sizeof(expected_top_ne)) ==
0);
assert(memcmp(outer_envelope.top->north_west->data, expected_top_nw, sizeof(expected_top_nw)) ==
0);
assert(memcmp(outer_envelope.top->south_east->data, expected_top_se, sizeof(expected_top_se)) ==
0);
assert(memcmp(outer_envelope.top->south_west->data, expected_top_sw, sizeof(expected_top_sw)) ==
0);
assert(memcmp(outer_envelope.top->north->data, expected_top_north, sizeof(expected_top_north)) ==
0);
assert(memcmp(outer_envelope.top->west->data, expected_top_west, sizeof(expected_top_west)) ==
0);
assert(memcmp(outer_envelope.top->south->data, expected_top_south, sizeof(expected_top_south)) ==
0);
assert(memcmp(outer_envelope.top->east->data, expected_top_east, sizeof(expected_top_east)) ==
0);
}
envelope_free(&outer_envelope);
dispatch_context_free(dc);
}
......@@ -704,8 +798,8 @@ int main(int argc, char *argv[]) {
case 6:
tests_6_processes(my_rank, fc);
break;
case 12:
tests_12_processes(my_rank, fc);
case 8:
tests_8_processes(my_rank, fc);
break;
default:
break;
......
......@@ -92,8 +92,6 @@ let augment_board [n][m] (chunk_board:[n][m]i8) (envelope: envelope_2d_i8) :[][]
else chunk_board[i-1, j-1]
)
entry hello_world (envv: envelope_3d_i32) :i32 = 5
entry next_chunk_board [n][m] (chunk_board :[n][m]i8) (envelope: envelope_2d_i8) :[n][m]i8 =
let augmented_board = augment_board chunk_board envelope
let neighbours = count_neighbours augmented_board
......
cmake_minimum_required(VERSION 3.17)
project(lattice_boltzmann C)
set(CMAKE_C_STANDARD 11)
if (CMAKE_BUILD_TYPE MATCHES Debug)
set(GCC_COMPILE_FLAGS "-Wall -Wextra -Wconversion -pedantic")
elseif (CMAKE_BUILD_TYPE MATCHES Release)
set(GCC_COMPILE_FLAGS "-O3")
endif ()
find_package(MPI REQUIRED)
include_directories(${MPI_C_INCLUDE_PATH})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GCC_COMPILE_FLAGS}")
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/lbm_seq.h ${CMAKE_CURRENT_SOURCE_DIR}/lbm_seq.c
COMMAND futhark c ${CMAKE_CURRENT_SOURCE_DIR}/lbm.fut --library
DEPENDS lbm.fut
)
add_custom_target(futhark_lbm_seq DEPENDS lbm_seq.h lbm_seq.c)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/lbm_cda.h ${CMAKE_CURRENT_SOURCE_DIR}/lbm_cda.c
COMMAND futhark cuda ${CMAKE_CURRENT_SOURCE_DIR}/lbm.fut --library
DEPENDS lbm.fut
)
add_custom_target(futhark_lbm_cuda DEPENDS lbm_cda.h lbm_cda.c)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/lbm_ocl.h ${CMAKE_CURRENT_SOURCE_DIR}/lbm_ocl.c
COMMAND futhark opencl ${CMAKE_CURRENT_SOURCE_DIR}/lbm.fut --library
DEPENDS lbm.fut
)
add_custom_target(futhark_lbm_opencl DEPENDS lbm_ocl.h lbm_ocl.c)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/lbm_mc.h ${CMAKE_CURRENT_SOURCE_DIR}/lbm_mc.c
COMMAND futhark multicore ${CMAKE_CURRENT_SOURCE_DIR}/lbm.fut --library
DEPENDS lbm.fut
)
add_custom_target(futhark_lbm_multicore DEPENDS lbm_mc.h lbm_mc.c)
########## Lattice-Boltzmann ##########
add_executable(lattice_boltzmann_opencl main.c gfx.h gfx.c lbm.h lbm.c ../futhark_mpi/dispatch.h ../futhark_mpi/dispatch.c ../futhark_mpi/chunk_info.c ../futhark_mpi/chunk_info.h)
add_dependencies(lattice_boltzmann_opencl futhark_lbm_opencl)
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
target_link_libraries(lattice_boltzmann_opencl "-framework OpenCL" SDL2 ${MPI_C_LIBRARIES})
endif ()
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
target_link_libraries(lattice_boltzmann_opencl OpenCL SDL2 m ${MPI_C_LIBRARIES})
endif ()
module env = import "../futhark_mpi/envelope"
type envelope_1d_t [n] = env.envelope_1d_t [n]
type envelope_2d_t [n][m][ty][tx] = env.envelope_2d_t [n][m][ty][tx]
type~ side_envelope_3d_t = env.side_envelope_3d_t
type~ envelope_3d_t = env.envelope_3d_t
type~ side_envelope_3d_i32 = {
east: [][][]i32, -- edge
north: [][][]i32, -- edge
north_east: [][][]i32, -- vertice
north_west: [][][]i32, -- vertice
south: [][][]i32, -- edge
south_east: [][][]i32, -- vertice
south_west: [][][]i32, -- vertice
surface: [][][]i32,
west: [][][]i32 -- edge
}
type~ envelope_3d_i32 = {
back: side_envelope_3d_t,
bottom: side_envelope_3d_t,
front: side_envelope_3d_t,
left: side_envelope_3d_t,
right: side_envelope_3d_t,
top: side_envelope_3d_t
}
entry get_envelope_1d [n] (xs: [n]u8) (thickness: i64) : envelope_1d_t [thickness] =
env.get_envelope_1d xs thickness
entry get_envelope_2d [n][m] (matrix: [n][m]u8) (thickness_y: i64) (thickness_x: i64): envelope_2d_t [n][m][thickness_y][thickness_x] =
env.get_envelope_2d matrix thickness_y thickness_x
entry get_envelope_3d [n][m][l] (cube: [n][m][l]u8) (thickness_y: i64) (thickness_x: i64) (thickness_z: i64): envelope_3d_t =
env.get_envelope_3d cube thickness_y thickness_x thickness_z
entry get_subdomain_1d = env.get_subdomain_1d
entry get_subdomain_2d = env.get_subdomain_2d
entry get_subdomain_3d = env.get_subdomain_3d
let augment_lbm [n][m][l] (chunk_lbm:[n][m][l]i32) (envelope: envelope_3d_i32) : [][][]i32 =
let n_aug = n+2
let m_aug = m+2
let l_aug = l+2
tabulate_3d (n_aug) (m_aug) (l_aug) (\i j k ->
-- Top-South-West
if (i == 0 && j == 0 && k == 0) then envelope.top.south_west[i,j,k]
-- Top-West
else if (i == 0 && j == 0 && k >= 1 && k <= l_aug-2) then envelope.top.west[i,j,k-1]
-- Top-North-West
else if (i == 0 && j == 0 && k == l_aug-1) then envelope.top.north_west[i,j,0]
-- Top-South
else if (i == 0 && j >= 1 && j <= m_aug-2 && k == 0) then envelope.top.south[i,j-1,k]
-- Top-Surface
else if (i == 0 && j >= 1 && j <= m_aug-2 && k >= 1 && k <= l_aug-2) then envelope.top.surface[i,j-1,k-1]
-- Top North
else if (i == 0 && j >= 1 && j <= m_aug-2 && k == l_aug-1) then envelope.top.north[i,j-1,0]
-- Top South East
else if (i == 0 && j == m_aug-1 && k == 0) then envelope.top.south_east[i,j-1,0]
-- Top East
else if (i == 0 && j == m_aug-1 && k >= 1 && k <= l_aug-2) then envelope.top.east[i,0,k-1]
-- Top North East
else if (i == 0 && j == m_aug-1 && k == l_aug-1) then envelope.top.north_east[i,0,0]
-- Front-West
else if (i >= 1 && i <= n_aug-2 && j == 0 && k == 0) then envelope.front.west[i-1,0,0]
-- Left
else if (i >= 1 && i <= n_aug-2 && j == 0 && k >= 1 && k <= l_aug-1) then envelope.left.surface[i-1,0,k-1]
-- Back West
else if (i >= 1 && i <= n_aug-2 && j == 0 && k == l_aug-1) then envelope.back.west[i-1,0,0]
-- Front East
else if (i >= 1 && i <= n_aug-2 && j == m_aug-1 && k == 0) then envelope.front.east[i-1,0,0]
-- Right
else if (i >= 1 && i <= n_aug-2 && j == m_aug-1 && k >= 1 && k <= l_aug-1) then envelope.right.surface[i-1,0,k-1]
-- Back East
else if (i >= 1 && i <= n_aug-2 && j == m_aug-1 && k == l_aug-1) then envelope.back.west[i-1,0,0]
-- Bottom-South-West
if (i == n_aug-1 && j == 0 && k == 0) then envelope.bottom.south_west[0,j,k]
-- Bottom-West
else if (i == n_aug-1 && j == 0 && k >= 1 && k <= l_aug-2) then envelope.bottom.west[0,j,k-1]
-- Bottom-North-West
else if (i == n_aug-1 && j == 0 && k == l_aug-1) then envelope.bottom.north_west[0,j,0]
-- Bottom-South
else if (i == n_aug-1 && j >= 1 && j <= m_aug-2 && k == 0) then envelope.bottom.south[0,j-1,k]
-- Bottom-Surface
else if (i == n_aug-1 && j >= 1 && j <= m_aug-2 && k >= 1 && k <= l_aug-2) then envelope.bottom.surface[0,j-1,k-1]
-- Bottom North
else if (i == n_aug-1 && j >= 1 && j <= m_aug-2 && k == l_aug-1) then envelope.bottom.north[0,j-1,0]
-- Bottom South East
else if (i == n_aug-1 && j == m_aug-1 && k == 0) then envelope.bottom.south_east[0,j-1,0]
-- Bottom East
else if (i == n_aug-1 && j == m_aug-1 && k >= 1 && k <= l_aug-2) then envelope.bottom.east[0,0,k-1]
-- Bottom North East
else if (i == n_aug-1 && j == m_aug-1 && k == l_aug-1) then envelope.bottom.north_east[0,0,0]
else chunk_lbm[i-1, j-1, l-1]
)
entry next_lbm [n][m][l] (chunk_lbm :[n][m][l]i32) (envelope: envelope_3d_i32) :[n][m][l]i32 =
let augmented_lbm = augment_lbm chunk_lbm envelope
-- TODO: Here, compute next lbm
in next_lbm[1:n+1, 1:m+1][1:l+1] :> [n][m][l]i32
/**
* Author: Baptiste Coudray
* School: HEPIA
* Class: ITI-3
* Year 2020-2021
*/
#include <stdio.h>
#include <stdint.h>
#include "stdlib.h"
#include <stdbool.h>
#include <mpi.h>
#include <unistd.h>
#include "gol.h"
#include "gfx.h"
#include "../futhark_mpi/dispatch.h"
#define INDEX_3D_TO_1D(y, x, z, nb_columns, nb_depths) ((x) + (nb_columns) * ((y) + (nb_depths) * (z)))
#define N_ITERATIONS 200
void init_chunk_lbm(chunk_info_t *ci) {
int *data32 = ci->data;
for (int i = 0; i < ci->dimensions[0]; ++i) {
for (int j = 0; j < ci->dimensions[1]; ++j) {
for (int k = 0; k < ci->dimensions[2]; ++k) {
int idx = INDEX_3D_TO_1D(i, j, k, ci->dimensions[1], ci->dimensions[2]);
data32[idx] = rand() % 2;
}
}
}
}
void compute_next_lbm(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_3d_i32 *fut_outer_envelope = futhark_outer_envelope_new(dc, fc, &outer_envelope,
futhark_restore_opaque_envelope_3d_i32,
FUTHARK_I32);
struct futhark_i32_3d *fut_chunk_lbm = futhark_new_i32_3d(fc, ci->data, ci->dimensions[0], ci->dimensions[1],
ci->dimensions[2]);
struct futhark_i32_3d *fut_next_chunk_lbm;
futhark_context_sync(fc);
futhark_entry_next_next_chunk_lbm(fc, &fut_next_chunk_lbm, fut_chunk_lbm, fut_outer_envelope);
futhark_context_sync(fc);
futhark_values_i32_3d(fc, fut_next_chunk_lbm, ci->data);
futhark_context_sync(fc);
futhark_free_i32_3d(fc, fut_next_chunk_lbm);
futhark_free_i32_3d(fc, fut_chunk_lbm);
futhark_free_opaque_envelope_3d_i32(fc, fut_outer_envelope);
envelope_free(&outer_envelope);
}
int main(int argc, char *argv[]) {
if (argc < 4) {
printf("usage: mpirun -n <nb_proc> %s <height> <width> <depth>\n", argv[0]);
return EXIT_FAILURE;
}
MPI_Init(&argc, &argv);
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();
struct futhark_context *fut_context = futhark_context_new(fut_config);
int lbm_dimensions[3] = {atoi(argv[1]), atoi(argv[2]), atoi(argv[3])};
struct dispatch_context *disp_context = dispatch_context_new(lbm_dimensions, MPI_INT, 3);
chunk_info_t ci = get_chunk_info(disp_context);
init_chunk_lbm(&ci);
for (int i = 0; i < N_ITERATIONS; ++i) {
compute_next_lbm(dc, fc, ci);
}
dispatch_context_free(disp_context);
futhark_context_config_free(fut_config);
futhark_context_free(fut_context);
return MPI_Finalize();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment