nf_matrix.f90 4.0 KB

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