nf_partition.f90 4.2 KB

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