nf_partition.f90 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. ! StarPU --- Runtime system for heterogeneous multicore architectures.
  2. !
  3. ! Copyright (C) 2016 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. program nf_partition
  16. use iso_c_binding ! C interfacing module
  17. use fstarpu_mod ! StarPU interfacing module
  18. use nf_partition_cl
  19. implicit none
  20. real(8), dimension(:,:), allocatable, target :: ma
  21. integer, target :: i,j
  22. type(c_ptr) :: cl_partition ! a pointer for the codelet structure
  23. type(c_ptr) :: dh_ma ! a pointer for the 'ma' vector data handle
  24. type(c_ptr) :: dh_sub ! a pointer for the sub-data handle
  25. integer(c_int) :: err ! return status for fstarpu_init
  26. integer(c_int) :: ncpu ! number of cpus workers
  27. type(c_ptr) :: filter_M
  28. type(c_ptr) :: filter_N
  29. integer(c_int), parameter :: ma_M = 64
  30. integer(c_int), parameter :: ma_M_parts = 32
  31. integer(c_int), parameter :: ma_N = 16
  32. integer(c_int), parameter :: ma_N_parts = 4
  33. allocate(ma(ma_M,ma_N))
  34. do i=1,ma_M
  35. do j=1,ma_N
  36. ma(i,j) = (i*100)+j
  37. end do
  38. end do
  39. ! initialize StarPU with default settings
  40. err = fstarpu_init(C_NULL_PTR)
  41. if (err == -19) then
  42. stop 77
  43. end if
  44. ! stop there if no CPU worker available
  45. ncpu = fstarpu_cpu_worker_get_count()
  46. if (ncpu == 0) then
  47. call fstarpu_shutdown()
  48. stop 77
  49. end if
  50. ! allocate an empty codelet structure
  51. cl_partition = fstarpu_codelet_allocate()
  52. ! set the codelet name
  53. call fstarpu_codelet_set_name(cl_partition, C_CHAR_"my_part_codelet"//C_NULL_CHAR)
  54. ! add a CPU implementation function to the codelet
  55. call fstarpu_codelet_add_cpu_func(cl_partition, C_FUNLOC(cl_partition_func))
  56. ! add a Read-Write mode data buffer to the codelet
  57. call fstarpu_codelet_add_buffer(cl_partition, FSTARPU_RW)
  58. ! register 'ma', a vector of real(8) elements
  59. !dh_ma = fstarpu_matrix_data_register(c_loc(ma), ma_M, ma_M, ma_N, c_sizeof(ma(1,1)), 0)
  60. call fstarpu_matrix_data_register(dh_ma, 0, c_loc(ma), ma_M, ma_M, ma_N, c_sizeof(ma(1,1)))
  61. ! allocate partitioning filters
  62. filter_M = fstarpu_df_alloc_matrix_filter_block()
  63. call fstarpu_data_filter_set_nchildren(filter_M, ma_M_parts)
  64. filter_N = fstarpu_df_alloc_matrix_filter_vertical_block()
  65. call fstarpu_data_filter_set_nchildren(filter_N, ma_N_parts)
  66. ! apply partitioning
  67. call fstarpu_data_map_filters(dh_ma, 2, (/ filter_M, filter_N /))
  68. do i=0,ma_M_parts-1
  69. do j=0,ma_N_parts-1
  70. ! get partitioned tile
  71. dh_sub = fstarpu_data_get_sub_data (dh_ma, 2, (/i, j/))
  72. ! Note: The array argument must follow the layout:
  73. ! (/
  74. ! <codelet_ptr>,
  75. ! [<argument_type> [<argument_value(s)],]
  76. ! . . .
  77. ! C_NULL_PTR
  78. ! )/
  79. call fstarpu_insert_task((/ cl_partition, FSTARPU_RW, dh_sub, C_NULL_PTR /))
  80. end do
  81. end do
  82. ! wait for task completion
  83. call fstarpu_task_wait_for_all()
  84. ! unpartition 'ma'
  85. call fstarpu_data_unpartition(dh_ma, 0)
  86. ! unregister 'ma'
  87. call fstarpu_data_unregister(dh_ma)
  88. ! free data filter structures
  89. call fstarpu_data_filter_free(filter_N)
  90. call fstarpu_data_filter_free(filter_M)
  91. ! free codelet structure
  92. call fstarpu_codelet_free(cl_partition)
  93. ! shut StarPU down
  94. call fstarpu_shutdown()
  95. deallocate(ma)
  96. end program nf_partition