Browse Source

- add missing native Fortran routines for partitioning support
- add an example using bi-dimensional partitioning

Olivier Aumage 8 years ago
parent
commit
22f64d7d8c

+ 14 - 1
examples/Makefile.am

@@ -251,7 +251,8 @@ STARPU_EXAMPLES +=				\
 	native_fortran/nf_matrix		\
 	native_fortran/nf_example		\
 	native_fortran/nf_dynbuf		\
-	native_fortran/nf_varbuf
+	native_fortran/nf_varbuf		\
+	native_fortran/nf_partition
 endif
 endif
 endif
@@ -409,6 +410,11 @@ native_fortran_nf_varbuf_SOURCES =	\
 	native_fortran/nf_varbuf_cl.f90		\
 	$(top_srcdir)/include/fstarpu_mod.f90	\
 	native_fortran/nf_varbuf.f90
+
+native_fortran_nf_partition_SOURCES =	\
+	native_fortran/nf_partition_cl.f90		\
+	$(top_srcdir)/include/fstarpu_mod.f90	\
+	native_fortran/nf_partition.f90
 endif
 
 #######################
@@ -1044,6 +1050,7 @@ fstarpu_mod.mod: fstarpu_mod.o
 nf_codelets.mod: nf_codelets.o
 nf_dynbuf_cl.mod: nf_dynbuf_cl.o
 nf_varbuf_cl.mod: nf_varbuf_cl.o
+nf_partition_cl.mod: nf_partition_cl.o
 
 fstarpu_mod.o: $(top_srcdir)/include/fstarpu_mod.f90
 	$(AM_V_FC)$(FC) $(native_fortran_nf_vector_FCFLAGS) $(FCFLAGS) -c -o $@ '$(top_srcdir)/'include/fstarpu_mod.f90
@@ -1075,4 +1082,10 @@ nf_varbuf_cl.o: $(top_srcdir)/examples/native_fortran/nf_varbuf_cl.f90 nf_types.
 nf_varbuf.o: $(top_srcdir)/examples/native_fortran/nf_varbuf.f90 nf_types.mod nf_varbuf_cl.mod fstarpu_mod.mod
 	$(AM_V_FC)$(FC) $(native_fortran_nf_varbuf_FCFLAGS) $(FCFLAGS) -c -o $@ `test -f 'native_fortran/nf_varbuf.f90' || echo '$(srcdir)/'`native_fortran/nf_varbuf.f90
 
+nf_partition_cl.o: $(top_srcdir)/examples/native_fortran/nf_partition_cl.f90 nf_types.mod fstarpu_mod.mod
+	$(AM_V_FC)$(FC) $(native_fortran_nf_partition_FCFLAGS) $(FCFLAGS) -c -o $@ `test -f 'native_fortran/nf_partition_cl.f90' || echo '$(srcdir)/'`native_fortran/nf_partition_cl.f90
+
+nf_partition.o: $(top_srcdir)/examples/native_fortran/nf_partition.f90 nf_types.mod nf_partition_cl.mod fstarpu_mod.mod
+	$(AM_V_FC)$(FC) $(native_fortran_nf_partition_FCFLAGS) $(FCFLAGS) -c -o $@ `test -f 'native_fortran/nf_partition.f90' || echo '$(srcdir)/'`native_fortran/nf_partition.f90
+
 endif

+ 51 - 0
examples/native_fortran/Makefile.nf_partition

@@ -0,0 +1,51 @@
+# StarPU --- Runtime system for heterogeneous multicore architectures.
+#
+# Copyright (C) 2016  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.
+
+PROG = nf_partition
+
+FSTARPU_MOD = $(shell pkg-config --cflags-only-I starpu-1.3|sed -e 's/^\([^ ]*starpu\/1.3\).*$$/\1/;s/^.* //;s/^-I//')/fstarpu_mod.f90
+
+SRCSF = nf_partition_cl.f90		\
+	nf_partition.f90
+
+FC = gfortran
+CC = gcc
+
+CFLAGS = -g $(shell pkg-config --cflags starpu-1.3)
+FCFLAGS = -fdefault-real-8 -J. -g
+LDLIBS =  $(shell pkg-config --libs starpu-1.3)
+
+OBJS = $(SRCSC:%.c=%.o) fstarpu_mod.o $(SRCSF:%.f90=%.o)
+
+.phony: all clean
+all: $(PROG)
+
+$(PROG): $(OBJS)
+	$(FC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
+
+%.o: %.c
+	$(CC) $(CFLAGS) -c -o $@ $<
+
+fstarpu_mod.o: $(FSTARPU_MOD)
+	$(FC) $(FCFLAGS) -c -o $@ $<
+
+%.o: %.f90
+	$(FC) $(FCFLAGS) -c -o $@ $<
+
+clean:
+	rm -fv *.o *.mod $(PROG)
+
+nf_parition_cl.o: nf_partition_cl.f90 fstarpu_mod.o
+nf_partition.o: nf_partition.f90 nf_parition_cl.o fstarpu_mod.o

+ 121 - 0
examples/native_fortran/nf_partition.f90

@@ -0,0 +1,121 @@
+! StarPU --- Runtime system for heterogeneous multicore architectures.
+!
+! Copyright (C) 2016  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.
+
+program nf_partition
+        use iso_c_binding       ! C interfacing module
+        use fstarpu_mod         ! StarPU interfacing module
+        use nf_partition_cl
+        implicit none
+
+        real(8), dimension(:,:), allocatable, target :: ma
+        integer, target :: i,j
+
+        type(c_ptr) :: cl_partition   ! a pointer for the codelet structure
+        type(c_ptr) :: dh_ma    ! a pointer for the 'ma' vector data handle
+        type(c_ptr) :: dh_sub   ! a pointer for the sub-data handle
+        integer(c_int) :: err   ! return status for fstarpu_init
+        integer(c_int) :: ncpu  ! number of cpus workers
+        type(c_ptr) :: filter_M
+        type(c_ptr) :: filter_N
+
+        integer(c_int), parameter :: ma_M = 64
+        integer(c_int), parameter :: ma_M_parts = 32
+        integer(c_int), parameter :: ma_N = 16
+        integer(c_int), parameter :: ma_N_parts = 4
+
+        allocate(ma(ma_M,ma_N))
+        do i=1,ma_M
+        do j=1,ma_N
+        ma(i,j) = (i*100)+j
+        end do
+        end do
+
+        ! initialize StarPU with default settings
+        err = fstarpu_init(C_NULL_PTR)
+        if (err == -19) then
+                stop 77
+        end if
+
+        ! stop there if no CPU worker available
+        ncpu = fstarpu_cpu_worker_get_count()
+        if (ncpu == 0) then
+                call fstarpu_shutdown()
+                stop 77
+        end if
+
+        ! allocate an empty codelet structure
+        cl_partition = fstarpu_codelet_allocate()
+
+        ! set the codelet name
+        call fstarpu_codelet_set_name(cl_partition, C_CHAR_"my_part_codelet"//C_NULL_CHAR)
+
+        ! add a CPU implementation function to the codelet
+        call fstarpu_codelet_add_cpu_func(cl_partition, C_FUNLOC(cl_partition_func))
+
+        ! add a Read-Write mode data buffer to the codelet
+        call fstarpu_codelet_add_buffer(cl_partition, FSTARPU_RW)
+
+        ! register 'ma', a vector of real(8) elements
+        !dh_ma = fstarpu_matrix_data_register(c_loc(ma), ma_M, ma_M, ma_N, c_sizeof(ma(1,1)), 0)
+        call fstarpu_matrix_data_register(dh_ma, 0, c_loc(ma), ma_M, ma_M, ma_N, c_sizeof(ma(1,1)))
+
+        ! allocate partitioning filters
+        filter_M = fstarpu_df_alloc_matrix_filter_block()
+        call fstarpu_data_filter_set_nchildren(filter_M, ma_M_parts)
+
+        filter_N = fstarpu_df_alloc_matrix_filter_vertical_block()
+        call fstarpu_data_filter_set_nchildren(filter_N, ma_N_parts)
+
+        ! apply partitioning
+        call fstarpu_data_map_filters(dh_ma, 2, (/ filter_M, filter_N /))
+
+        do i=0,ma_M_parts-1
+        do j=0,ma_N_parts-1
+                ! get partitioned tile
+                dh_sub = fstarpu_data_get_sub_data (dh_ma, 2, (/i, j/))
+
+                ! Note: The array argument must follow the layout:
+                !   (/
+                !     <codelet_ptr>,
+                !     [<argument_type> [<argument_value(s)],]
+                !     . . .
+                !     C_NULL_PTR
+                !   )/
+                call fstarpu_insert_task((/ cl_partition, FSTARPU_RW, dh_sub, C_NULL_PTR /))
+        end do
+        end do
+
+        ! wait for task completion
+        call fstarpu_task_wait_for_all()
+
+        ! unpartition 'ma'
+        call fstarpu_data_unpartition(dh_ma, 0)
+
+        ! unregister 'ma'
+        call fstarpu_data_unregister(dh_ma)
+
+        ! free data filter structures
+        call fstarpu_data_filter_free(filter_N)
+        call fstarpu_data_filter_free(filter_M)
+
+        ! free codelet structure
+        call fstarpu_codelet_free(cl_partition)
+
+        ! shut StarPU down
+        call fstarpu_shutdown()
+
+        deallocate(ma)
+
+end program nf_partition

+ 44 - 0
examples/native_fortran/nf_partition_cl.f90

@@ -0,0 +1,44 @@
+! StarPU --- Runtime system for heterogeneous multicore architectures.
+!
+! Copyright (C) 2016  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.
+
+module nf_partition_cl
+contains
+        ! 'cl_partition' codelet routine
+recursive subroutine cl_partition_func (buffers, cl_args) bind(C)
+        use iso_c_binding       ! C interfacing module
+        use fstarpu_mod         ! StarPU interfacing module
+        implicit none
+
+        type(c_ptr), value, intent(in) :: buffers, cl_args ! cl_args is unused
+        real(8), dimension(:,:), pointer :: ma
+        integer :: ld_ma,nx_ma,ny_ma
+        integer :: i,j
+
+        ld_ma = fstarpu_matrix_get_ld(buffers, 0)
+        nx_ma = fstarpu_matrix_get_nx(buffers, 0)
+        ny_ma = fstarpu_matrix_get_ny(buffers, 0)
+        write(*,*) "ld_ma = ", ld_ma, ", nx_ma = ", nx_ma, ", ny_ma = ", ny_ma
+
+        call c_f_pointer(fstarpu_matrix_get_ptr(buffers, 0), ma, shape=[ld_ma,ny_ma])
+        write(*,*) "ma"
+        do i=1,nx_ma
+        do j=1,ny_ma
+                write(*,*) i,j,ma(i,j)
+        end do
+        write(*,*) '-'
+        end do
+
+end subroutine cl_partition_func
+end module nf_partition_cl

+ 144 - 3
include/fstarpu_mod.f90

@@ -941,6 +941,124 @@ module fstarpu_mod
 
                 ! == starpu_data_filter.h ==
 
+                function fstarpu_data_filter_allocate () bind(C)
+                        use iso_c_binding, only: c_ptr
+                        type(c_ptr) :: fstarpu_data_filter_allocate
+                end function fstarpu_data_filter_allocate
+
+                subroutine fstarpu_data_filter_free (filter) bind(C)
+                        use iso_c_binding, only: c_ptr
+                        type(c_ptr), value, intent(in) :: filter
+                end subroutine fstarpu_data_filter_free
+
+                ! Note: use fstarpu_df_alloc_ prefix instead of fstarpu_data_filter_allocate_
+                ! to fit within the Fortran id length limit */
+                function fstarpu_df_alloc_bcsr_filter_canonical_block () bind(C)
+                        use iso_c_binding, only: c_ptr
+                        type(c_ptr) :: fstarpu_df_alloc_bcsr_filter_canonical_block
+                end function fstarpu_df_alloc_bcsr_filter_canonical_block
+
+                function fstarpu_df_alloc_csr_filter_vertical_block () bind(C)
+                        use iso_c_binding, only: c_ptr
+                        type(c_ptr) :: fstarpu_df_alloc_csr_filter_vertical_block
+                end function fstarpu_df_alloc_csr_filter_vertical_block
+
+                function fstarpu_df_alloc_matrix_filter_block () bind(C)
+                        use iso_c_binding, only: c_ptr
+                        type(c_ptr) :: fstarpu_df_alloc_matrix_filter_block
+                end function fstarpu_df_alloc_matrix_filter_block
+
+                function fstarpu_df_alloc_matrix_filter_block_shadow () bind(C)
+                        use iso_c_binding, only: c_ptr
+                        type(c_ptr) :: fstarpu_df_alloc_matrix_filter_block_shadow
+                end function fstarpu_df_alloc_matrix_filter_block_shadow
+
+                function fstarpu_df_alloc_matrix_filter_vertical_block () bind(C)
+                        use iso_c_binding, only: c_ptr
+                        type(c_ptr) :: fstarpu_df_alloc_matrix_filter_vertical_block
+                end function fstarpu_df_alloc_matrix_filter_vertical_block
+
+                function fstarpu_df_alloc_matrix_filter_vertical_block_shadow () bind(C)
+                        use iso_c_binding, only: c_ptr
+                        type(c_ptr) :: fstarpu_df_alloc_matrix_filter_vertical_block_shadow
+                end function fstarpu_df_alloc_matrix_filter_vertical_block_shadow
+
+                function fstarpu_df_alloc_vector_filter_block () bind(C)
+                        use iso_c_binding, only: c_ptr
+                        type(c_ptr) :: fstarpu_df_alloc_vector_filter_block
+                end function fstarpu_df_alloc_vector_filter_block
+
+                function fstarpu_df_alloc_vector_filter_block_shadow () bind(C)
+                        use iso_c_binding, only: c_ptr
+                        type(c_ptr) :: fstarpu_df_alloc_vector_filter_block_shadow
+                end function fstarpu_df_alloc_vector_filter_block_shadow
+
+                function fstarpu_df_alloc_vector_filter_list () bind(C)
+                        use iso_c_binding, only: c_ptr
+                        type(c_ptr) :: fstarpu_df_alloc_vector_filter_list
+                end function fstarpu_df_alloc_vector_filter_list
+
+                function fstarpu_df_alloc_vector_filter_divide_in_2 () bind(C)
+                        use iso_c_binding, only: c_ptr
+                        type(c_ptr) :: fstarpu_df_alloc_vector_filter_divide_in_2
+                end function fstarpu_df_alloc_vector_filter_divide_in_2
+
+                function fstarpu_df_alloc_block_filter_block () bind(C)
+                        use iso_c_binding, only: c_ptr
+                        type(c_ptr) :: fstarpu_df_alloc_block_filter_block
+                end function fstarpu_df_alloc_block_filter_block
+
+                function fstarpu_df_alloc_block_filter_block_shadow () bind(C)
+                        use iso_c_binding, only: c_ptr
+                        type(c_ptr) :: fstarpu_df_alloc_block_filter_block_shadow
+                end function fstarpu_df_alloc_block_filter_block_shadow
+
+                function fstarpu_df_alloc_block_filter_vertical_block () bind(C)
+                        use iso_c_binding, only: c_ptr
+                        type(c_ptr) :: fstarpu_df_alloc_block_filter_vertical_block
+                end function fstarpu_df_alloc_block_filter_vertical_block
+
+                function fstarpu_df_alloc_block_filter_vertical_block_shadow () bind(C)
+                        use iso_c_binding, only: c_ptr
+                        type(c_ptr) :: fstarpu_df_alloc_block_filter_vertical_block_shadow
+                end function fstarpu_df_alloc_block_filter_vertical_block_shadow
+
+                subroutine fstarpu_data_filter_set_filter_func (filter, f_ptr) bind(C)
+                        use iso_c_binding, only: c_ptr, c_funptr
+                        type(c_ptr), value, intent(in) :: filter
+                        type(c_funptr), value, intent(in) :: f_ptr
+                end subroutine fstarpu_data_filter_set_filter_func
+
+                subroutine fstarpu_data_filter_set_nchildren (filter, nchildren) bind(C)
+                        use iso_c_binding, only: c_ptr, c_int
+                        type(c_ptr), value, intent(in) :: filter
+                        integer(c_int), value, intent(in) :: nchildren
+                end subroutine fstarpu_data_filter_set_nchildren
+
+                subroutine fstarpu_data_filter_set_get_nchildren_func (filter, f_ptr) bind(C)
+                        use iso_c_binding, only: c_ptr, c_funptr
+                        type(c_ptr), value, intent(in) :: filter
+                        type(c_funptr), value, intent(in) :: f_ptr
+                end subroutine fstarpu_data_filter_set_get_nchildren_func
+
+                subroutine fstarpu_data_filter_set_get_child_ops_func (filter, f_ptr) bind(C)
+                        use iso_c_binding, only: c_ptr, c_funptr
+                        type(c_ptr), value, intent(in) :: filter
+                        type(c_funptr), value, intent(in) :: f_ptr
+                end subroutine fstarpu_data_filter_set_get_child_ops_func
+
+                subroutine fstarpu_data_filter_set_filter_arg (filter, filter_arg) bind(C)
+                        use iso_c_binding, only: c_ptr, c_int
+                        type(c_ptr), value, intent(in) :: filter
+                        integer(c_int), value, intent(in) :: filter_arg
+                end subroutine fstarpu_data_filter_set_filter_arg
+
+                subroutine fstarpu_data_filter_set_filter_arg_ptr (filter, filter_arg_ptr) bind(C)
+                        use iso_c_binding, only: c_ptr
+                        type(c_ptr), value, intent(in) :: filter
+                        type(c_ptr), value, intent(in) :: filter_arg_ptr
+                end subroutine fstarpu_data_filter_set_filter_arg_ptr
+
                 ! void starpu_data_partition(starpu_data_handle_t initial_handle, struct starpu_data_filter *f);
                 subroutine fstarpu_data_partition (dh,filter) bind(C,name="starpu_data_partition")
                         use iso_c_binding, only: c_ptr
@@ -949,11 +1067,11 @@ module fstarpu_mod
                 end subroutine fstarpu_data_partition
 
                 ! void starpu_data_unpartition(starpu_data_handle_t root_data, unsigned gathering_node);
-                subroutine fstarpug_data_data_unpartition (root_dh,gathering_node) bind(C,name="starpu_data_data_unpartition")
+                subroutine fstarpu_data_unpartition (root_dh,gathering_node) bind(C,name="starpu_data_unpartition")
                         use iso_c_binding, only: c_ptr, c_int
                         type(c_ptr), value, intent(in) :: root_dh
                         integer(c_int), value, intent(in) :: gathering_node
-                end subroutine fstarpug_data_data_unpartition
+                end subroutine fstarpu_data_unpartition
 
                 ! void starpu_data_partition_plan(starpu_data_handle_t initial_handle, struct starpu_data_filter *f, starpu_data_handle_t *children);
                 subroutine fstarpu_data_partition_plan (dh,filter,children) & 
@@ -1036,7 +1154,31 @@ module fstarpu_mod
                 end function fstarpu_data_get_child
 
                 ! starpu_data_handle_t starpu_data_get_sub_data(starpu_data_handle_t root_data, unsigned depth, ... );
+                ! . see: fstarpu_data_get_sub_data
                 ! starpu_data_handle_t starpu_data_vget_sub_data(starpu_data_handle_t root_data, unsigned depth, va_list pa);
+                ! . see: fstarpu_data_get_sub_data
+
+                ! note: defined in filters.c
+                function fstarpu_data_get_sub_data (root_dh,depth,indices) bind(C)
+                        use iso_c_binding, only: c_ptr, c_int
+                        type(c_ptr)              :: fstarpu_data_get_sub_data
+                        type(c_ptr), value, intent(in) :: root_dh
+                        integer(c_int), value, intent(in) :: depth
+                        integer(c_int), intent(in) :: indices(*)
+                end function fstarpu_data_get_sub_data
+
+                ! void starpu_data_map_filters(starpu_data_handle_t root_data, unsigned nfilters, ...);
+                ! . see fstarpu_data_map_filters
+                ! void starpu_data_vmap_filters(starpu_data_handle_t root_data, unsigned nfilters, va_list pa);
+                ! . see fstarpu_data_map_filters
+
+                ! note: defined in filters.c
+                subroutine fstarpu_data_map_filters (root_dh,nfilters,filters) bind(C)
+                        use iso_c_binding, only: c_ptr, c_int
+                        type(c_ptr), value, intent(in) :: root_dh
+                        integer(c_int), value, intent(in) :: nfilters
+                        type(c_ptr), intent(in) :: filters(*)
+                end subroutine fstarpu_data_map_filters
 
                 ! void starpu_matrix_filter_block(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);
                 subroutine fstarpu_matrix_filter_block (father_interface,child_interface,filter,id,nparts) &
@@ -1116,7 +1258,6 @@ module fstarpu_mod
                 end subroutine fstarpu_vector_filter_list
 
                 ! void starpu_vector_filter_divide_in_2(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);
-                ! void starpu_vector_filter_list(void *father_interface, void *child_interface, struct starpu_data_filter *f, unsigned id, unsigned nparts);
                 subroutine fstarpu_vector_divide_in_2 (father_interface,child_interface,filter,id,nparts) &
                                 bind(C,name="starpu_vector_divide_in_2")
                         use iso_c_binding, only: c_ptr

+ 35 - 0
src/datawizard/filters.c

@@ -66,6 +66,18 @@ void starpu_data_map_filters(starpu_data_handle_t root_handle, unsigned nfilters
 	va_end(pa);
 }
 
+void fstarpu_data_map_filters(starpu_data_handle_t root_handle, int nfilters, struct starpu_data_filter **filters)
+{
+	int i;
+	assert(nfilters >= 0);
+	for (i = 0; i < nfilters; i++)
+	{
+		struct starpu_data_filter *next_filter = filters[i];
+		STARPU_ASSERT(next_filter);
+		map_filter(root_handle, next_filter);
+	}
+}
+
 int starpu_data_get_nb_children(starpu_data_handle_t handle)
 {
         return handle->nchildren;
@@ -112,6 +124,29 @@ starpu_data_handle_t starpu_data_vget_sub_data(starpu_data_handle_t root_handle,
 	return current_handle;
 }
 
+starpu_data_handle_t fstarpu_data_get_sub_data(starpu_data_handle_t root_handle, int depth, int *indices)
+{
+	STARPU_ASSERT(root_handle);
+	starpu_data_handle_t current_handle = root_handle;
+
+	STARPU_ASSERT(depth >= 0);
+	/* the variable number of argument must correlate the depth in the tree */
+	int i;
+	for (i = 0; i < depth; i++)
+	{
+		int next_child;
+		next_child = indices[i];
+		STARPU_ASSERT(next_child >= 0);
+
+		STARPU_ASSERT_MSG(current_handle->nchildren != 0, "Data %p has to be partitioned before accessing children", current_handle);
+		STARPU_ASSERT_MSG(next_child < current_handle->nchildren, "Bogus child number %u, data %p only has %u children", next_child, current_handle, current_handle->nchildren);
+
+		current_handle = &current_handle->children[next_child];
+	}
+
+	return current_handle;
+}
+
 static unsigned _starpu_data_partition_nparts(starpu_data_handle_t initial_handle, struct starpu_data_filter *f)
 {
 	/* how many parts ? */

+ 72 - 0
src/util/fstarpu.c

@@ -506,3 +506,75 @@ void fstarpu_data_descr_set(struct starpu_data_descr *descr, starpu_data_handle_
 {
 	fstarpu_data_descr_array_set(descr, 1, handle, mode);
 }
+
+struct starpu_data_filter *fstarpu_data_filter_allocate(void)
+{
+	struct starpu_data_filter *filter = calloc(1, sizeof(*filter));
+	return filter;
+}
+
+/* Note: use fstarpu_df_alloc_ prefix instead of fstarpu_data_filter_allocate_ to fit within the
+ * Fortran id length limit */
+#define _FSTARPU_DATA_FILTER_ALLOCATOR(name) \
+struct starpu_data_filter *fstarpu_df_alloc_##name(void) \
+{ \
+	struct starpu_data_filter *filter = fstarpu_data_filter_allocate(); \
+	filter->filter_func = starpu_##name; \
+	return filter; \
+}
+
+_FSTARPU_DATA_FILTER_ALLOCATOR(bcsr_filter_canonical_block);
+_FSTARPU_DATA_FILTER_ALLOCATOR(csr_filter_vertical_block);
+_FSTARPU_DATA_FILTER_ALLOCATOR(matrix_filter_block);
+_FSTARPU_DATA_FILTER_ALLOCATOR(matrix_filter_block_shadow);
+_FSTARPU_DATA_FILTER_ALLOCATOR(matrix_filter_vertical_block);
+_FSTARPU_DATA_FILTER_ALLOCATOR(matrix_filter_vertical_block_shadow);
+_FSTARPU_DATA_FILTER_ALLOCATOR(vector_filter_block);
+_FSTARPU_DATA_FILTER_ALLOCATOR(vector_filter_block_shadow);
+_FSTARPU_DATA_FILTER_ALLOCATOR(vector_filter_list);
+_FSTARPU_DATA_FILTER_ALLOCATOR(vector_filter_divide_in_2);
+_FSTARPU_DATA_FILTER_ALLOCATOR(block_filter_block);
+_FSTARPU_DATA_FILTER_ALLOCATOR(block_filter_block_shadow);
+_FSTARPU_DATA_FILTER_ALLOCATOR(block_filter_vertical_block);
+_FSTARPU_DATA_FILTER_ALLOCATOR(block_filter_vertical_block_shadow);
+
+#undef _FSTARPU_DATA_FILTER_ALLOCATOR
+
+void fstarpu_data_filter_free(struct starpu_data_filter *filter) {
+	memset(filter, 0, sizeof(*filter));
+	free(filter);
+}
+
+void fstarpu_data_filter_set_filter_func(struct starpu_data_filter *filter, void *f_ptr)
+{
+	STARPU_ASSERT(f_ptr != NULL);
+	filter->filter_func = f_ptr;
+}
+
+void fstarpu_data_filter_set_nchildren(struct starpu_data_filter *filter, int nchildren)
+{
+	STARPU_ASSERT(nchildren >= 0);
+	filter->nchildren = nchildren;
+}
+
+void fstarpu_data_filter_set_get_nchildren_func(struct starpu_data_filter *filter, void *f_ptr)
+{
+	filter->get_nchildren = f_ptr;
+}
+
+void fstarpu_data_filter_set_get_child_ops_func(struct starpu_data_filter *filter, void *f_ptr)
+{
+	filter->get_child_ops = f_ptr;
+}
+
+void fstarpu_data_filter_set_filter_arg(struct starpu_data_filter *filter, int filter_arg)
+{
+	STARPU_ASSERT(filter_arg >= 0); /* starpu_data_filter.filter_arg is unsigned, but
+					 * Fortran does not support unsigned types */
+	filter->filter_arg = (unsigned)filter_arg;
+}
+
+void fstarpu_data_filter_set_filter_arg_ptr(struct starpu_data_filter *filter, void *filter_arg_ptr)
+{
+	filter->filter_arg_ptr = filter_arg_ptr;
+}