Skip to content

Commit

Permalink
doc: new part on how to write a StarPU application from an existing a…
Browse files Browse the repository at this point in the history
…pplication
  • Loading branch information
nfurmento committed Dec 6, 2022
1 parent ee35c81 commit 1f84d9a
Show file tree
Hide file tree
Showing 37 changed files with 2,545 additions and 106 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ starpu.log
/doc/doxygen/chapters/version.html
/doc/doxygen_dev/chapters/version.sty
/doc/doxygen_dev/chapters/version.html
/doc/doxygen_web_applications/chapters/
/doc/doxygen_web_basics/chapters/
/doc/doxygen_web_extensions/chapters/
/doc/doxygen_web_faq/chapters/
Expand Down
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -4321,6 +4321,8 @@ AC_OUTPUT([
doc/doxygen_web_installation/doxygen-config.cfg
doc/doxygen_web_basics/Makefile
doc/doxygen_web_basics/doxygen-config.cfg
doc/doxygen_web_applications/Makefile
doc/doxygen_web_applications/doxygen-config.cfg
doc/doxygen_web_performances/Makefile
doc/doxygen_web_performances/doxygen-config.cfg
doc/doxygen_web_faq/Makefile
Expand Down
2 changes: 2 additions & 0 deletions doc/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ SUBDIRS += doxygen_dev
SUBDIRS += doxygen_web_introduction
SUBDIRS += doxygen_web_installation
SUBDIRS += doxygen_web_basics
SUBDIRS += doxygen_web_applications
SUBDIRS += doxygen_web_performances
SUBDIRS += doxygen_web_faq
SUBDIRS += doxygen_web_languages
Expand All @@ -30,6 +31,7 @@ DIST_SUBDIRS += doxygen_dev
DIST_SUBDIRS += doxygen_web_introduction
DIST_SUBDIRS += doxygen_web_installation
DIST_SUBDIRS += doxygen_web_basics
DIST_SUBDIRS += doxygen_web_applications
DIST_SUBDIRS += doxygen_web_performances
DIST_SUBDIRS += doxygen_web_faq
DIST_SUBDIRS += doxygen_web_languages
Expand Down
6 changes: 5 additions & 1 deletion doc/doxygen/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ chapters = \
chapters/starpu_basics/basics_intro.doxy \
chapters/starpu_basics/starpu_applications.doxy \
chapters/starpu_basics/basic_examples.doxy \
chapters/starpu_basics/advanced_examples.doxy \
chapters/starpu_basics/scaling_vector_example.doxy \
chapters/starpu_basics/tasks.doxy \
chapters/starpu_basics/data_management.doxy \
chapters/starpu_basics/scheduling.doxy \
chapters/starpu_basics/examples_sources.doxy \
chapters/starpu_applications/applications_intro.doxy \
chapters/starpu_applications/stencil.doxy \
chapters/starpu_performances/performances_intro.doxy \
chapters/starpu_performances/benchmarking_starpu.doxy \
chapters/starpu_performances/online_performance_tools.doxy \
Expand Down Expand Up @@ -90,6 +91,9 @@ chapters = \
chapters/code/disk_copy.c \
chapters/code/disk_compute.c \
chapters/code/nf_initexit.f90 \
chapters/code/stencil5.c \
chapters/code/stencil5_starpu.c \
chapters/code/stencil5_starpu_mpi.c \
chapters/api/fortran_support.doxy \
chapters/api/bubble_support.doxy \
chapters/api/fft_support.doxy \
Expand Down
55 changes: 55 additions & 0 deletions doc/doxygen/chapters/code/stencil5.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* StarPU --- Runtime system for heterogeneous multicore architectures.
*
* Copyright (C) 2011-2022 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
*
* StarPU is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at
* your option) any later version.
*
* StarPU is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU Lesser General Public License in COPYING.LGPL for more details.
*/

#include <math.h>
#include "stencil5.h"

//! [To be included. You should update doxygen if you see this text.]
void stencil5_cpu(double *xy, double *xm1y, double *xp1y, double *xym1, double *xyp1)
{
*xy = (*xy + *xm1y + *xp1y + *xym1 + *xyp1) / 5;
}

int main(int argc, char **argv)
{
int niter, n;
int x, y, loop;

read_params(argc, argv, &n, &niter);

double *A = calloc(n*n, sizeof(*A));
fill(A, n, n);

for(loop=0 ; loop<niter; loop++)
{
for (x = 0; x < n; x++)
{
for (y = 0; y < n; y++)
{
int xm1 = (x==0) ? n-1 : x-1;
int xp1 = (x==n-1) ? 0 : x+1;
int ym1 = (y==0) ? n-1 : y-1;
int yp1 = (y==n-1) ? 0 : y+1;
stencil5_cpu(&A[_(x,y,n)],
&A[_(xm1,y,n)], &A[_(xp1,y,n)],
&A[_(x,ym1,n)], &A[_(x,yp1,n)]);
}
}
}

return 0;
}
//! [To be included. You should update doxygen if you see this text.]
109 changes: 109 additions & 0 deletions doc/doxygen/chapters/code/stencil5_starpu.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/* StarPU --- Runtime system for heterogeneous multicore architectures.
*
* Copyright (C) 2011-2022 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
*
* StarPU is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at
* your option) any later version.
*
* StarPU is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU Lesser General Public License in COPYING.LGPL for more details.
*/

#include <starpu.h>
#include <math.h>
#include "stencil5.h"

//! [To be included. You should update doxygen if you see this text.]
//! [starpu_codelet. You should update doxygen if you see this text.]
void stencil5_cpu(void *descr[], void *_args)
{
(void)_args;
double *xy = (double *)STARPU_VARIABLE_GET_PTR(descr[0]);
double *xm1y = (double *)STARPU_VARIABLE_GET_PTR(descr[1]);
double *xp1y = (double *)STARPU_VARIABLE_GET_PTR(descr[2]);
double *xym1 = (double *)STARPU_VARIABLE_GET_PTR(descr[3]);
double *xyp1 = (double *)STARPU_VARIABLE_GET_PTR(descr[4]);

*xy = (*xy + *xm1y + *xp1y + *xym1 + *xyp1) / 5;
}

struct starpu_codelet stencil5_cl =
{
.cpu_funcs = {stencil5_cpu},
.nbuffers = 5,
.modes = {STARPU_RW, STARPU_R, STARPU_R, STARPU_R, STARPU_R},
.model = &starpu_perfmodel_nop,
};
//! [starpu_codelet. You should update doxygen if you see this text.]

int main(int argc, char **argv)
{
starpu_data_handle_t *data_handles;
int ret;
int niter, n;
int x, y, loop;

ret = starpu_init(NULL);
STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");

read_params(argc, argv, &verbose, &n, &niter);

double *A = calloc(n*n, sizeof(*A));
fill(A, n, n);

//! [starpu_register. You should update doxygen if you see this text.]
data_handles = malloc(n*n*sizeof(*data_handles));
for(x = 0; x < n; x++)
{
for (y = 0; y < n; y++)
{
starpu_variable_data_register(&data_handles[_(x,y,n)],
STARPU_MAIN_RAM,
(uintptr_t)&(A[_(x,y,n)]), sizeof(double));
}
}
//! [starpu_register. You should update doxygen if you see this text.]

for(loop=0 ; loop<niter; loop++)
{
for (x = 0; x < n; x++)
{
for (y = 0; y < n; y++)
{
//! [starpu_task. You should update doxygen if you see this text.]
int xm1 = (x==0) ? n-1 : x-1;
int xp1 = (x==n-1) ? 0 : x+1;
int ym1 = (y==0) ? n-1 : y-1;
int yp1 = (y==n-1) ? 0 : y+1;
starpu_task_insert(&stencil5_cl,
STARPU_RW, data_handles[_(x,y,n)],
STARPU_R, data_handles[_(xm1,y,n)],
STARPU_R, data_handles[_(xp1,y,n)],
STARPU_R, data_handles[_(x,ym1,n)],
STARPU_R, data_handles[_(x,yp1,n)],
0);
//! [starpu_task. You should update doxygen if you see this text.]
}
}
}
starpu_task_wait_for_all();

//! [starpu_unregister. You should update doxygen if you see this text.]
for(x = 0; x < n; x++)
{
for (y = 0; y < n; y++)
{
starpu_data_unregister(data_handles[_(x,y,n)]);
}
}
//! [starpu_unregister. You should update doxygen if you see this text.]

starpu_shutdown();
return 0;
}
//! [To be included. You should update doxygen if you see this text.]
102 changes: 102 additions & 0 deletions doc/doxygen/chapters/code/stencil5_starpu_mpi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/* StarPU --- Runtime system for heterogeneous multicore architectures.
*
* Copyright (C) 2011-2022 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
*
* StarPU is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at
* your option) any later version.
*
* StarPU is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU Lesser General Public License in COPYING.LGPL for more details.
*/

#include <starpu_mpi.h>
#include <math.h>
#include "stencil5.h"

//! [To be included. You should update doxygen if you see this text.]
void stencil5_cpu(void *descr[], void *_args); // Same as in sequential StarPU
struct starpu_codelet stencil5_cl; // Same as in sequential StarPU

/* Returns the MPI node number where data indexes index is */
int my_distrib(int x, int y, int nb_nodes)
{
return ((int)(x / sqrt(nb_nodes) + (y / sqrt(nb_nodes)) * sqrt(nb_nodes))) % nb_nodes;
}

int main(int argc, char **argv)
{
starpu_data_handle_t *data_handles;
int niter, n;
int my_rank, size, x, y, loop;

//! [mpi_init. You should update doxygen if you see this text.]
int ret = starpu_mpi_init_conf(&argc, &argv, 1, MPI_COMM_WORLD, NULL);
STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init_conf");
starpu_mpi_comm_rank(MPI_COMM_WORLD, &my_rank);
starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
//! [mpi_init. You should update doxygen if you see this text.]

read_params(argc, argv, &n, &niter);

double *A = calloc(n*n, sizeof(*A));
fill(A, n, n);

data_handles = malloc(n*n*sizeof(*data_handles));
for(x = 0; x < n; x++)
{
for (y = 0; y < n; y++)
{
//! [mpi_register. You should update doxygen if you see this text.]
starpu_variable_data_register(&data_handles[_(x,y,n)],
STARPU_MAIN_RAM,
(uintptr_t)&(A[_(x,y,n)]), sizeof(double));
int mpi_rank = my_distrib(x, y, size);
starpu_mpi_data_register(data_handles[_(x,y,n)], (y*n)+x, mpi_rank);
//! [mpi_register. You should update doxygen if you see this text.]
}
}

for(loop=0 ; loop<niter; loop++)
{
for (x = 0; x < n; x++)
{
for (y = 0; y < n; y++)
{
int xm1 = (x==0) ? n-1 : x-1;
int xp1 = (x==n-1) ? 0 : x+1;
int ym1 = (y==0) ? n-1 : y-1;
int yp1 = (y==n-1) ? 0 : y+1;
//! [mpi_insert. You should update doxygen if you see this text.]
starpu_mpi_task_insert(MPI_COMM_WORLD, &stencil5_cl,
STARPU_RW, data_handles[_(x,y,n)],
STARPU_R, data_handles[_(xm1,y,n)],
STARPU_R, data_handles[_(xp1,y,n)],
STARPU_R, data_handles[_(x,ym1,n)],
STARPU_R, data_handles[_(x,yp1,n)],
0);
//! [mpi_insert. You should update doxygen if you see this text.]
}
}
}
starpu_task_wait_for_all();

/* bring data back to node 0 and unregister it */
for(x = 0; x < n; x++)
{
for (y = 0; y < n; y++)
{
starpu_mpi_data_migrate(MPI_COMM_WORLD, data_handles[_(x,y,n)], 0);
starpu_data_unregister(data_handles[_(x,y,n)]);
}
}

starpu_mpi_shutdown();

return 0;
}
//! [To be included. You should update doxygen if you see this text.]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* StarPU --- Runtime system for heterogeneous multicore architectures.
*
* Copyright (C) 2009-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
* Copyright (C) 2022-2022 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
*
* StarPU is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand All @@ -14,8 +14,9 @@
* See the GNU Lesser General Public License in COPYING.LGPL for more details.
*/

/*! \page AdvancedExamples Advanced Examples
/*! \intropage{IntroApplications, --------- StarPU Applications ---------}

This part presents how to write a StarPU application from an existing application.

TODO

*/
Loading

0 comments on commit 1f84d9a

Please sign in to comment.