瀏覽代碼

- return starpu_init code to user

Olivier Aumage 9 年之前
父節點
當前提交
49358735d5
共有 4 個文件被更改,包括 34 次插入25 次删除
  1. 13 9
      examples/native_fortran/nf_matrix.f90
  2. 6 2
      examples/native_fortran/nf_vector.f90
  3. 15 5
      include/fstarpu_mod.f90
  4. 0 9
      src/util/fstarpu.c

+ 13 - 9
examples/native_fortran/nf_matrix.f90

@@ -8,9 +8,10 @@ program nf_matrix
         integer, dimension(:,:), allocatable, target :: mb
         integer :: i,j
 
-        type(c_ptr) :: cl_mat      ! a pointer for the codelet structure
-        type(c_ptr) :: dh_va    ! a pointer for the 'ma' vector data handle
-        type(c_ptr) :: dh_vb    ! a pointer for the 'mb' vector data handle
+        type(c_ptr) :: cl_mat   ! a pointer for the codelet structure
+        type(c_ptr) :: dh_ma    ! a pointer for the 'ma' vector data handle
+        type(c_ptr) :: dh_mb    ! a pointer for the 'mb' vector data handle
+        integer(c_int) :: err   ! return status for fstarpu_init
 
         allocate(ma(5,6))
         do i=1,5
@@ -27,7 +28,10 @@ program nf_matrix
         end do
 
         ! initialize StarPU with default settings
-        call fstarpu_init()
+        err = fstarpu_init(C_NULL_PTR)
+        if (err == -19) then
+                stop 77
+        end if
 
         ! allocate an empty codelet structure
         cl_mat = fstarpu_codelet_allocate()
@@ -42,10 +46,10 @@ program nf_matrix
         call fstarpu_codelet_add_buffer(cl_mat, FSTARPU_RW)
 
         ! register 'ma', a vector of real(8) elements
-        dh_va = fstarpu_matrix_data_register(c_loc(ma), 5, 5, 6, c_sizeof(ma(1,1)), 0)
+        dh_ma = fstarpu_matrix_data_register(c_loc(ma), 5, 5, 6, c_sizeof(ma(1,1)), 0)
 
         ! register 'mb', a vector of integer elements
-        dh_vb = fstarpu_matrix_data_register(c_loc(mb), 7, 7, 8, c_sizeof(mb(1,1)), 0)
+        dh_mb = fstarpu_matrix_data_register(c_loc(mb), 7, 7, 8, c_sizeof(mb(1,1)), 0)
 
         ! insert a task with codelet cl_mat, and vectors 'ma' and 'mb'
         !
@@ -59,16 +63,16 @@ program nf_matrix
         !
         ! Note: The argument type for data handles is FSTARPU_DATA, regardless
         ! of the buffer access mode (specified in the codelet)
-        call fstarpu_insert_task((/ cl_mat, FSTARPU_DATA, dh_va, FSTARPU_DATA, dh_vb, C_NULL_PTR /))
+        call fstarpu_insert_task((/ cl_mat, FSTARPU_DATA, dh_ma, FSTARPU_DATA, dh_mb, C_NULL_PTR /))
 
         ! wait for task completion
         call fstarpu_task_wait_for_all()
 
         ! unregister 'ma'
-        call fstarpu_data_unregister(dh_va)
+        call fstarpu_data_unregister(dh_ma)
 
         ! unregister 'mb'
-        call fstarpu_data_unregister(dh_vb)
+        call fstarpu_data_unregister(dh_mb)
 
         ! free codelet structure
         call fstarpu_codelet_free(cl_mat)

+ 6 - 2
examples/native_fortran/nf_vector.f90

@@ -23,9 +23,10 @@ program nf_vector
         integer, dimension(:), allocatable, target :: vb
         integer :: i
 
-        type(c_ptr) :: cl_vec      ! a pointer for the codelet structure
+        type(c_ptr) :: cl_vec   ! a pointer for the codelet structure
         type(c_ptr) :: dh_va    ! a pointer for the 'va' vector data handle
         type(c_ptr) :: dh_vb    ! a pointer for the 'vb' vector data handle
+        integer(c_int) :: err   ! return status for fstarpu_init
 
         allocate(va(5))
         va = (/ (i,i=1,5) /)
@@ -34,7 +35,10 @@ program nf_vector
         vb = (/ (i,i=1,7) /)
 
         ! initialize StarPU with default settings
-        call fstarpu_init()
+        err = fstarpu_init(C_NULL_PTR)
+        if (err == -19) then
+                stop 77
+        end if
 
         ! allocate an empty codelet structure
         cl_vec = fstarpu_codelet_allocate()

+ 15 - 5
include/fstarpu_mod.f90

@@ -141,7 +141,10 @@ module fstarpu_mod
 
         contains
 
-                subroutine fstarpu_init ()
+                function fstarpu_init (conf) bind(C)
+                        use iso_c_binding
+                        integer(c_int) :: fstarpu_init
+                        type(c_ptr), value, intent(in) :: conf
 
                         ! Note: Referencing global C constants from Fortran has
                         ! been found unreliable on some architectures, notably
@@ -162,8 +165,11 @@ module fstarpu_mod
                                         character(kind=c_char) :: s
                                 end function fstarpu_get_pointer_constant
 
-                                subroutine fstarpu_init_internal () bind(C)
-                                end subroutine fstarpu_init_internal
+                                function fstarpu_init_internal (conf) bind(C,name="starpu_init")
+                                        use iso_c_binding
+                                        integer(c_int) :: fstarpu_init_internal
+                                        type(c_ptr), value :: conf
+                                end function fstarpu_init_internal
                         end interface
 
                         ! Initialize Fortran integer constants from C peers
@@ -175,6 +181,10 @@ module fstarpu_mod
                         ! Initialize Fortran 'pointer' constants from C peers
                         FSTARPU_DATA = fstarpu_get_pointer_constant(C_CHAR_"FSTARPU_DATA"//C_NULL_CHAR)
                         ! Initialize StarPU
-                        call fstarpu_init_internal()
-                end subroutine fstarpu_init
+                        if (c_associated(conf)) then 
+                                fstarpu_init = fstarpu_init_internal(conf)
+                        else
+                                fstarpu_init = fstarpu_init_internal(C_NULL_PTR)
+                        end if
+                end function fstarpu_init
 end module fstarpu_mod

+ 0 - 9
src/util/fstarpu.c

@@ -46,15 +46,6 @@ const void *fstarpu_get_pointer_constant(char *s)
 	else { _FSTARPU_ERROR("unknown pointer constant"); }
 }
 
-void fstarpu_init_internal(void)
-{
-	int ret = starpu_init(NULL);
-	if (ret != 0)
-	{
-		_FSTARPU_ERROR("starpu_init failed");
-	}
-}
-
 struct starpu_codelet *fstarpu_codelet_allocate(void)
 {
 	struct starpu_codelet *cl = malloc(sizeof(*cl));