Skip to content

Commit

Permalink
Apply the new indentation to PDI (#466)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbigot authored Aug 28, 2024
1 parent 313c299 commit 441bcea
Show file tree
Hide file tree
Showing 217 changed files with 7,947 additions and 9,164 deletions.
26 changes: 1 addition & 25 deletions .github/workflows/indent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,4 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DoozyX/[email protected]
with:
clangFormatVersion: 17
source: |
example/
pdi/benchmarks
pdi/docs/First_steps
pdi/include
pdi/src
pdi/tests
plugins/decl_hdf5
plugins/decl_netcdf
plugins/decl_sion
plugins/flowvr/plugin/include
plugins/flowvr/plugin/src
plugins/flowvr/tests
plugins/fti
plugins/mpi
plugins/pycall
plugins/serialize
plugins/set_value
plugins/test
plugins/trace
plugins/user_code
tests
- run: exec ./bin/test_indent
12 changes: 10 additions & 2 deletions bin/test_indent
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ else
exit 1
fi

RUN_CLANG_FORMAT='false'

# Look for a docker based version
DOCKER="$(which docker)"
if "${DOCKER}" --version >/dev/null 2>&1
Expand All @@ -54,11 +56,17 @@ fi
for CLANG_FORMAT in clang-format-17 clang-format17 clang-format
do
CLANG_FORMAT="$(which "${CLANG_FORMAT}")"
if [ 17 -le "$("${CLANG_FORMAT}" --version | sed 's/.*version\s\+\([0-9]\+\)\..*/\1/')" ]
if which "${CLANG_FORMAT}" >/dev/null && [ 17 -le "$("${CLANG_FORMAT}" --version | sed 's/.*version\s\+\([0-9]\+\)\..*/\1/')" 2>/dev/null ]
then
RUN_CLANG_FORMAT="python3 vendor/run-clang-format/run-clang-format.py --clang-format-executable ${CLANG_FORMAT}"
break
fi
done

exec ${RUN_CLANG_FORMAT} ${CLANG_FORMAT_ARGS} $(git ls-files --full-name | grep '\.[hHcC]\(\|++\|xx\|pp\)\s*$')
if [ "${RUN_CLANG_FORMAT}" = false ]
then
echo "clang-format version 17 not found and docker not usable"
exit 127
fi

git ls-files -z --full-name | grep -zZv '^vendor/' | grep -zZ '\.[hHcC]\(\|++\|xx\|pp\)\s*$' | xargs -0 ${RUN_CLANG_FORMAT} ${CLANG_FORMAT_ARGS}
228 changes: 139 additions & 89 deletions example/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@
* THE SOFTWARE.
******************************************************************************/

#include <mpi.h>
#include <assert.h>
#include <math.h>
#include <paraconf.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <mpi.h>
#include <yaml.h>
#include <paraconf.h>

#include "pdi.h"

void init(int dsize[2], int pcoord[2], double dat[dsize[0]][dsize[1]])
{
for (int yy=0; yy<dsize[0]; ++yy) {
for (int xx=0; xx<dsize[1]; ++xx) {
for (int yy = 0; yy < dsize[0]; ++yy) {
for (int xx = 0; xx < dsize[1]; ++xx) {
dat[yy][xx] = 0;
}
}
if ( pcoord[1] == 0 ) {
for (int yy=0; yy<dsize[0]; ++yy) {
if (pcoord[1] == 0) {
for (int yy = 0; yy < dsize[0]; ++yy) {
dat[yy][0] = 1000000;
}
}
Expand All @@ -50,23 +50,19 @@ void init(int dsize[2], int pcoord[2], double dat[dsize[0]][dsize[1]])
void iter(int dsize[2], double cur[dsize[0]][dsize[1]], double next[dsize[0]][dsize[1]])
{
int xx, yy;
for (xx=0; xx<dsize[1]; ++xx) {
for (xx = 0; xx < dsize[1]; ++xx) {
next[0][xx] = cur[0][xx];
}
for (yy=1; yy<dsize[0]-1; ++yy) {
for (yy = 1; yy < dsize[0] - 1; ++yy) {
next[yy][0] = cur[yy][0];
for (xx=1; xx<dsize[1]-1; ++xx) {
next[yy][xx] =
(cur[yy][xx] *.5)
+ (cur[yy][xx-1] *.125)
+ (cur[yy][xx+1] *.125)
+ (cur[yy-1][xx] *.125)
+ (cur[yy+1][xx] *.125);
for (xx = 1; xx < dsize[1] - 1; ++xx) {
next[yy][xx]
= (cur[yy][xx] * .5) + (cur[yy][xx - 1] * .125) + (cur[yy][xx + 1] * .125) + (cur[yy - 1][xx] * .125) + (cur[yy + 1][xx] * .125);
}
next[yy][dsize[1]-1] = cur[yy][dsize[1]-1];
next[yy][dsize[1] - 1] = cur[yy][dsize[1] - 1];
}
for (xx=0; xx<dsize[1]; ++xx) {
next[dsize[0]-1][xx] = cur[dsize[0]-1][xx];
for (xx = 0; xx < dsize[1]; ++xx) {
next[dsize[0] - 1][xx] = cur[dsize[0] - 1][xx];
}
}

Expand All @@ -76,132 +72,186 @@ void exchange(MPI_Comm cart_com, int dsize[2], double cur[dsize[0]][dsize[1]])
int rank_source, rank_dest;
static MPI_Datatype column, row;
static int initialized = 0;
if ( !initialized ) {
MPI_Type_vector(dsize[0]-2, 1, dsize[1], MPI_DOUBLE, &column);

if (!initialized) {
MPI_Type_vector(dsize[0] - 2, 1, dsize[1], MPI_DOUBLE, &column);
MPI_Type_commit(&column);
MPI_Type_contiguous(dsize[1]-2, MPI_DOUBLE, &row);
MPI_Type_contiguous(dsize[1] - 2, MPI_DOUBLE, &row);
MPI_Type_commit(&row);
initialized = 1;
}

/* send down */
MPI_Cart_shift(cart_com, 0, 1, &rank_source, &rank_dest);
MPI_Sendrecv(&cur[dsize[0]-2][1], 1, row, rank_dest, 100, /* send row before ghost */
&cur[0][1], 1, row, rank_source, 100, /* receive 1st row (ghost) */
cart_com, &status);

MPI_Sendrecv(
&cur[dsize[0] - 2][1],
1,
row,
rank_dest,
100, /* send row before ghost */
&cur[0][1],
1,
row,
rank_source,
100, /* receive 1st row (ghost) */
cart_com,
&status
);

/* send up */
MPI_Cart_shift(cart_com, 0, -1, &rank_source, &rank_dest);
MPI_Sendrecv(&cur[1][1], 1, row, rank_dest, 100, /* send column after ghost */
&cur[dsize[0]-1][1], 1, row, rank_source, 100, /* receive last column (ghost) */
cart_com, &status);

MPI_Sendrecv(
&cur[1][1],
1,
row,
rank_dest,
100, /* send column after ghost */
&cur[dsize[0] - 1][1],
1,
row,
rank_source,
100, /* receive last column (ghost) */
cart_com,
&status
);

/* send to the right */
MPI_Cart_shift(cart_com, 1, 1, &rank_source, &rank_dest);
MPI_Sendrecv(&cur[1][dsize[1]-2], 1, column, rank_dest, 100, /* send column before ghost */
&cur[1][0], 1, column, rank_source, 100, /* receive 1st column (ghost) */
cart_com, &status);

MPI_Sendrecv(
&cur[1][dsize[1] - 2],
1,
column,
rank_dest,
100, /* send column before ghost */
&cur[1][0],
1,
column,
rank_source,
100, /* receive 1st column (ghost) */
cart_com,
&status
);

/* send to the left */
MPI_Cart_shift(cart_com, 1, -1, &rank_source, &rank_dest);
MPI_Sendrecv(&cur[1][1], 1, column, rank_dest, 100, /* send column after ghost */
&cur[1][dsize[1]-1], 1, column, rank_source, 100, /* receive last column (ghost) */
cart_com, &status);
MPI_Sendrecv(
&cur[1][1],
1,
column,
rank_dest,
100, /* send column after ghost */
&cur[1][dsize[1] - 1],
1,
column,
rank_source,
100, /* receive last column (ghost) */
cart_com,
&status
);
}

int main( int argc, char* argv[] )
int main(int argc, char* argv[])
{
MPI_Init(&argc, &argv);
if ( argc != 2 ) {

if (argc != 2) {
fprintf(stderr, "Usage: %s <config_file>\n", argv[0]);
exit(1);
}

PC_tree_t conf = PC_parse_path(argv[1]);

MPI_Comm main_comm = MPI_COMM_WORLD;
PDI_init(PC_get(conf, ".pdi"));

PDI_expose("mpi_comm", &main_comm, PDI_INOUT);

int psize_1d; MPI_Comm_size(main_comm, &psize_1d);
int pcoord_1d; MPI_Comm_rank(main_comm, &pcoord_1d);

int psize_1d;
MPI_Comm_size(main_comm, &psize_1d);
int pcoord_1d;
MPI_Comm_rank(main_comm, &pcoord_1d);

PDI_expose("mpi_rank", &pcoord_1d, PDI_OUT);
PDI_expose("mpi_size", &psize_1d, PDI_OUT);
PDI_event("init");

long longval;

int dsize[2];
PC_int(PC_get(conf, ".datasize[0]"), &longval); dsize[0] = longval;
PC_int(PC_get(conf, ".datasize[1]"), &longval); dsize[1] = longval;

PC_int(PC_get(conf, ".datasize[0]"), &longval);
dsize[0] = longval;
PC_int(PC_get(conf, ".datasize[1]"), &longval);
dsize[1] = longval;

int psize[2];
PC_int(PC_get(conf, ".parallelism.height"), &longval); psize[0] = longval;
PC_int(PC_get(conf, ".parallelism.width" ), &longval); psize[1] = longval;

double duration; PC_double(PC_get(conf, ".duration"), &duration);

PC_int(PC_get(conf, ".parallelism.height"), &longval);
psize[0] = longval;
PC_int(PC_get(conf, ".parallelism.width"), &longval);
psize[1] = longval;

double duration;
PC_double(PC_get(conf, ".duration"), &duration);

// get local & add ghosts to sizes
assert(dsize[0]%psize[0]==0); dsize[0] = dsize[0]/psize[0] + 2;
assert(dsize[1]%psize[1]==0); dsize[1] = dsize[1]/psize[1] + 2;

assert(psize[1]*psize[0] == psize_1d);

int cart_period[2] = { 0, 0 };
MPI_Comm cart_com; MPI_Cart_create(main_comm, 2, psize, cart_period, 1, &cart_com);
int pcoord[2]; MPI_Cart_coords(cart_com, pcoord_1d, 2, pcoord);

assert(dsize[0] % psize[0] == 0);
dsize[0] = dsize[0] / psize[0] + 2;
assert(dsize[1] % psize[1] == 0);
dsize[1] = dsize[1] / psize[1] + 2;

assert(psize[1] * psize[0] == psize_1d);

int cart_period[2] = {0, 0};
MPI_Comm cart_com;
MPI_Cart_create(main_comm, 2, psize, cart_period, 1, &cart_com);
int pcoord[2];
MPI_Cart_coords(cart_com, pcoord_1d, 2, pcoord);

PDI_expose("dsize", dsize, PDI_OUT);
PDI_expose("psize", psize, PDI_OUT);
PDI_expose("pcoord", pcoord, PDI_OUT);
double(*cur)[dsize[1]] = malloc(sizeof(double)*dsize[1]*dsize[0]);
double(*next)[dsize[1]] = malloc(sizeof(double)*dsize[1]*dsize[0]);

double(*cur)[dsize[1]] = malloc(sizeof(double) * dsize[1] * dsize[0]);
double(*next)[dsize[1]] = malloc(sizeof(double) * dsize[1] * dsize[0]);

init(dsize, pcoord, cur);

PDI_event("main_loop");
double start = MPI_Wtime();
int ii;
int next_reduce = 0;
for (ii=0;; ++ii) {
PDI_multi_expose("newiter",
"iter", &ii, PDI_INOUT,
"main_field", cur, PDI_INOUT,
NULL);

for (ii = 0;; ++ii) {
PDI_multi_expose("newiter", "iter", &ii, PDI_INOUT, "main_field", cur, PDI_INOUT, NULL);

iter(dsize, cur, next);
exchange(cart_com, dsize, next);
double (*tmp)[dsize[1]] = cur; cur = next; next = tmp;

if ( ii >= next_reduce ) {
double(*tmp)[dsize[1]] = cur;
cur = next;
next = tmp;

if (ii >= next_reduce) {
double local_time, global_time;
local_time = MPI_Wtime()-start;
local_time = MPI_Wtime() - start;
MPI_Allreduce(&local_time, &global_time, 1, MPI_DOUBLE, MPI_MAX, main_comm);
if ( global_time >= duration ) {
if ( 0==pcoord_1d ) printf("iter=%7d; time=%7.3f; STOP!!!\n", ii, global_time);
if (global_time >= duration) {
if (0 == pcoord_1d) printf("iter=%7d; time=%7.3f; STOP!!!\n", ii, global_time);
break;
}
int rem_iter = .9 * (duration-global_time) * (ii+1) / (global_time + 0.1);
if ( rem_iter < 1 ) rem_iter = 1;
int rem_iter = .9 * (duration - global_time) * (ii + 1) / (global_time + 0.1);
if (rem_iter < 1) rem_iter = 1;
next_reduce = ii + rem_iter;
if ( 0==pcoord_1d ) printf("iter=%7d; time=%7.3f; next_reduce=%7d\n", ii, global_time, next_reduce);
if (0 == pcoord_1d) printf("iter=%7d; time=%7.3f; next_reduce=%7d\n", ii, global_time, next_reduce);
}
}
PDI_event("finalization");
PDI_expose("iter", &ii, PDI_OUT);
PDI_expose("main_field", cur, PDI_OUT);

PDI_finalize();

PC_tree_destroy(&conf);

free(cur);
free(next);

MPI_Finalize();
}
Loading

0 comments on commit 441bcea

Please sign in to comment.