浏览代码

- add some more tasks to stress the two contexts

Olivier Aumage 8 年之前
父节点
当前提交
b2b952132a
共有 2 个文件被更改,包括 50 次插入26 次删除
  1. 37 25
      examples/native_fortran/nf_sched_ctx.f90
  2. 13 1
      examples/native_fortran/nf_sched_ctx_cl.f90

+ 37 - 25
examples/native_fortran/nf_sched_ctx.f90

@@ -39,8 +39,9 @@ program nf_sched_ctx
         integer(c_int) :: ctx2
 
         ! needed to be able to call c_loc on it, to get a ptr to the string
-        character(kind=c_char,len=6), target :: ctx2_policy = C_CHAR_"prio"//C_NULL_CHAR
+        character(kind=c_char,len=6), target :: ctx2_policy = C_CHAR_"eager"//C_NULL_CHAR
 
+        integer(c_int),parameter :: n = 20
         integer(c_int) :: i
         integer(c_int), target :: arg_id
         integer(c_int), target :: arg_ctx
@@ -99,42 +100,53 @@ program nf_sched_ctx
         ! create sched context 1 with default policy
         ctx1 = fstarpu_sched_ctx_create(procs1, nprocs1,  &
             C_CHAR_"ctx1"//C_NULL_CHAR, &
-            (/ c_null_ptr, FSTARPU_SCHED_CTX_POLICY_STRUCT, c_null_ptr, c_null_ptr /) &
+            (/ FSTARPU_SCHED_CTX_POLICY_STRUCT, c_null_ptr, c_null_ptr /) &
             )
 
         ! create sched context 2 with policy name
         ctx2 = fstarpu_sched_ctx_create(procs2, nprocs2,  &
             C_CHAR_"ctx2"//C_NULL_CHAR, &
-            (/ c_null_ptr, FSTARPU_SCHED_CTX_POLICY_NAME, c_loc(ctx2_policy), c_null_ptr /))
+            (/ FSTARPU_SCHED_CTX_POLICY_NAME, c_loc(ctx2_policy), c_null_ptr /))
 
         ! set inheritor context 
         call fstarpu_sched_ctx_set_inheritor(ctx2, ctx1);
 
-        ! submit a task on context 1
-        arg_id = 1
-        arg_ctx = ctx1
-        call fstarpu_insert_task((/ cl1, &
-                FSTARPU_VALUE, c_loc(arg_id), FSTARPU_SZ_C_INT, &
-                FSTARPU_SCHED_CTX, c_loc(arg_ctx), &
-            C_NULL_PTR /))
-
-        ! now submit a task on context 2
-        arg_id = 2
-        arg_ctx = ctx2
-        call fstarpu_insert_task((/ cl2, &
-                FSTARPU_VALUE, c_loc(arg_id), FSTARPU_SZ_C_INT, &
-                FSTARPU_SCHED_CTX, c_loc(arg_ctx), &
-            C_NULL_PTR /))
+        call fstarpu_sched_ctx_display_workers(ctx1)
+        call fstarpu_sched_ctx_display_workers(ctx2)
+
+        do i = 1, n
+                ! submit a task on context 1
+                arg_id = 1*1000 + i
+                arg_ctx = ctx1
+                call fstarpu_insert_task((/ cl1, &
+                        FSTARPU_VALUE, c_loc(arg_id), FSTARPU_SZ_C_INT, &
+                        FSTARPU_SCHED_CTX, c_loc(arg_ctx), &
+                    C_NULL_PTR /))
+        end do
+
+        do i = 1, n
+                ! now submit a task on context 2
+                arg_id = 2*1000 + i
+                arg_ctx = ctx2
+                call fstarpu_insert_task((/ cl2, &
+                        FSTARPU_VALUE, c_loc(arg_id), FSTARPU_SZ_C_INT, &
+                        FSTARPU_SCHED_CTX, c_loc(arg_ctx), &
+                    C_NULL_PTR /))
+        end do
+
         ! mark submission process as completed on context 2
         call fstarpu_sched_ctx_finished_submit(ctx2)
 
-        ! now submit a task on context 1 again
-        arg_id = 1
-        arg_ctx = ctx1
-        call fstarpu_insert_task((/ cl1, &
-                FSTARPU_VALUE, c_loc(arg_id), FSTARPU_SZ_C_INT, &
-                FSTARPU_SCHED_CTX, c_loc(arg_ctx), &
-            C_NULL_PTR /))
+        do i = 1, n
+                ! now submit a task on context 1 again
+                arg_id = 1*10000 + i
+                arg_ctx = ctx1
+                call fstarpu_insert_task((/ cl1, &
+                        FSTARPU_VALUE, c_loc(arg_id), FSTARPU_SZ_C_INT, &
+                        FSTARPU_SCHED_CTX, c_loc(arg_ctx), &
+                    C_NULL_PTR /))
+        end do
+
         ! mark submission process as completed on context 1
         call fstarpu_sched_ctx_finished_submit(ctx1)
 

+ 13 - 1
examples/native_fortran/nf_sched_ctx_cl.f90

@@ -20,10 +20,22 @@ recursive subroutine cl_cpu_func_sched_ctx (buffers, cl_args) bind(C)
         use fstarpu_mod         ! StarPU interfacing module
         implicit none
 
+        interface
+                function sleep(s) bind(C)
+                        use iso_c_binding
+                        integer(c_int) :: sleep
+                        integer(c_int), value, intent(in) :: s
+                end function
+        end interface
+
         type(c_ptr), value, intent(in) :: buffers, cl_args ! cl_args is unused
         integer(c_int),target :: id
+        integer(c_int) :: worker_id
+        integer(c_int) :: ret
 
         call fstarpu_unpack_arg(cl_args,(/ c_loc(id) /))
-        write(*,*) "task:", id
+        ! ret = sleep(1)
+        worker_id = fstarpu_worker_get_id()
+        write(*,*) "task:", id, ", worker_id:", worker_id
 end subroutine cl_cpu_func_sched_ctx
 end module nf_sched_ctx_cl