nf_partition.f90 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. ! StarPU --- Runtime system for heterogeneous multicore architectures.
  2. !
  3. ! Copyright (C) 2017 CNRS
  4. ! Copyright (C) 2016 Inria
  5. !
  6. ! StarPU is free software; you can redistribute it and/or modify
  7. ! it under the terms of the GNU Lesser General Public License as published by
  8. ! the Free Software Foundation; either version 2.1 of the License, or (at
  9. ! your option) any later version.
  10. !
  11. ! StarPU is distributed in the hope that it will be useful, but
  12. ! WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. !
  15. ! See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. !
  17. program nf_partition
  18. use iso_c_binding ! C interfacing module
  19. use fstarpu_mod ! StarPU interfacing module
  20. use nf_partition_cl
  21. implicit none
  22. real(8), dimension(:,:), allocatable, target :: ma
  23. integer, target :: i,j
  24. type(c_ptr) :: cl_partition ! a pointer for the codelet structure
  25. type(c_ptr) :: dh_ma ! a pointer for the 'ma' vector data handle
  26. type(c_ptr) :: dh_sub ! a pointer for the sub-data handle
  27. integer(c_int) :: err ! return status for fstarpu_init
  28. integer(c_int) :: ncpu ! number of cpus workers
  29. type(c_ptr) :: filter_M
  30. type(c_ptr) :: filter_N
  31. integer(c_int), parameter :: ma_M = 64
  32. integer(c_int), parameter :: ma_M_parts = 32
  33. integer(c_int), parameter :: ma_N = 16
  34. integer(c_int), parameter :: ma_N_parts = 4
  35. allocate(ma(ma_M,ma_N))
  36. do i=1,ma_M
  37. do j=1,ma_N
  38. ma(i,j) = (i*100)+j
  39. end do
  40. end do
  41. ! initialize StarPU with default settings
  42. err = fstarpu_init(C_NULL_PTR)
  43. if (err == -19) then
  44. stop 77
  45. end if
  46. ! stop there if no CPU worker available
  47. ncpu = fstarpu_cpu_worker_get_count()
  48. if (ncpu == 0) then
  49. call fstarpu_shutdown()
  50. stop 77
  51. end if
  52. ! allocate an empty codelet structure
  53. cl_partition = fstarpu_codelet_allocate()
  54. ! set the codelet name
  55. call fstarpu_codelet_set_name(cl_partition, C_CHAR_"my_part_codelet"//C_NULL_CHAR)
  56. ! add a CPU implementation function to the codelet
  57. call fstarpu_codelet_add_cpu_func(cl_partition, C_FUNLOC(cl_partition_func))
  58. ! add a Read-Write mode data buffer to the codelet
  59. call fstarpu_codelet_add_buffer(cl_partition, FSTARPU_RW)
  60. ! register 'ma', a vector of real(8) elements
  61. !dh_ma = fstarpu_matrix_data_register(c_loc(ma), ma_M, ma_M, ma_N, c_sizeof(ma(1,1)), 0)
  62. call fstarpu_matrix_data_register(dh_ma, 0, c_loc(ma), ma_M, ma_M, ma_N, c_sizeof(ma(1,1)))
  63. ! allocate partitioning filters
  64. filter_M = fstarpu_df_alloc_matrix_filter_block()
  65. call fstarpu_data_filter_set_nchildren(filter_M, ma_M_parts)
  66. filter_N = fstarpu_df_alloc_matrix_filter_vertical_block()
  67. call fstarpu_data_filter_set_nchildren(filter_N, ma_N_parts)
  68. ! apply partitioning
  69. call fstarpu_data_map_filters(dh_ma, 2, (/ filter_M, filter_N /))
  70. do i=0,ma_M_parts-1
  71. do j=0,ma_N_parts-1
  72. ! get partitioned tile
  73. dh_sub = fstarpu_data_get_sub_data (dh_ma, 2, (/i, j/))
  74. ! Note: The array argument must follow the layout:
  75. ! (/
  76. ! <codelet_ptr>,
  77. ! [<argument_type> [<argument_value(s)],]
  78. ! . . .
  79. ! C_NULL_PTR
  80. ! )/
  81. call fstarpu_insert_task((/ cl_partition, FSTARPU_RW, dh_sub, C_NULL_PTR /))
  82. end do
  83. end do
  84. ! wait for task completion
  85. call fstarpu_task_wait_for_all()
  86. ! unpartition 'ma'
  87. call fstarpu_data_unpartition(dh_ma, 0)
  88. ! unregister 'ma'
  89. call fstarpu_data_unregister(dh_ma)
  90. ! free data filter structures
  91. call fstarpu_data_filter_free(filter_N)
  92. call fstarpu_data_filter_free(filter_M)
  93. ! free codelet structure
  94. call fstarpu_codelet_free(cl_partition)
  95. ! shut StarPU down
  96. call fstarpu_shutdown()
  97. deallocate(ma)
  98. end program nf_partition