nf_matrix.f90 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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_matrix
  17. use iso_c_binding ! C interfacing module
  18. use fstarpu_mod ! StarPU interfacing module
  19. use nf_codelets
  20. implicit none
  21. real(8), dimension(:,:), allocatable, target :: ma
  22. integer, dimension(:,:), allocatable, target :: mb
  23. integer :: i,j
  24. type(c_ptr) :: cl_mat ! 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_mb ! a pointer for the 'mb' vector data handle
  27. integer(c_int) :: err ! return status for fstarpu_init
  28. integer(c_int) :: ncpu ! number of cpus workers
  29. real(c_double) :: start_time ! start clock in usec
  30. real(c_double) :: end_time ! end clock in usec
  31. allocate(ma(5,6))
  32. do i=1,5
  33. do j=1,6
  34. ma(i,j) = (i*10)+j
  35. end do
  36. end do
  37. allocate(mb(7,8))
  38. do i=1,7
  39. do j=1,8
  40. mb(i,j) = (i*10)+j
  41. end do
  42. end do
  43. ! initialize StarPU with default settings
  44. err = fstarpu_init(C_NULL_PTR)
  45. if (err == -19) then
  46. stop 77
  47. end if
  48. ! stop there if no CPU worker available
  49. ncpu = fstarpu_cpu_worker_get_count()
  50. if (ncpu == 0) then
  51. call fstarpu_shutdown()
  52. stop 77
  53. end if
  54. ! collect the start clock time
  55. start_time = fstarpu_timing_now()
  56. ! allocate an empty codelet structure
  57. cl_mat = fstarpu_codelet_allocate()
  58. ! set the codelet name
  59. call fstarpu_codelet_set_name(cl_mat, C_CHAR_"my_mat_codelet"//C_NULL_CHAR)
  60. ! add a CPU implementation function to the codelet
  61. call fstarpu_codelet_add_cpu_func(cl_mat, C_FUNLOC(cl_cpu_func_mat))
  62. ! add a Read-only mode data buffer to the codelet
  63. call fstarpu_codelet_add_buffer(cl_mat, FSTARPU_R)
  64. ! add a Read-Write mode data buffer to the codelet
  65. call fstarpu_codelet_add_buffer(cl_mat, FSTARPU_RW)
  66. ! register 'ma', a vector of real(8) elements
  67. !dh_ma = fstarpu_matrix_data_register(c_loc(ma), 5, 5, 6, c_sizeof(ma(1,1)), 0)
  68. call fstarpu_matrix_data_register(dh_ma, 0, c_loc(ma), 5, 5, 6, c_sizeof(ma(1,1)))
  69. ! register 'mb', a vector of integer elements
  70. call fstarpu_matrix_data_register(dh_mb, 0, c_loc(mb), 7, 7, 8, c_sizeof(mb(1,1)))
  71. ! insert a task with codelet cl_mat, and vectors 'ma' and 'mb'
  72. !
  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_mat, FSTARPU_R, dh_ma, FSTARPU_RW, dh_mb, C_NULL_PTR /))
  81. ! wait for task completion
  82. call fstarpu_task_wait_for_all()
  83. ! unregister 'ma'
  84. call fstarpu_data_unregister(dh_ma)
  85. ! unregister 'mb'
  86. call fstarpu_data_unregister(dh_mb)
  87. ! free codelet structure
  88. call fstarpu_codelet_free(cl_mat)
  89. ! collect the start clock time
  90. end_time = fstarpu_timing_now()
  91. ! shut StarPU down
  92. call fstarpu_shutdown()
  93. deallocate(mb)
  94. deallocate(ma)
  95. print "(es 10.3)", end_time - start_time
  96. end program nf_matrix