{"id":524,"date":"2015-11-10T11:15:10","date_gmt":"2015-11-10T10:15:10","guid":{"rendered":"https:\/\/iww.inria.fr\/sed-sophia\/?p=524"},"modified":"2015-11-30T10:41:17","modified_gmt":"2015-11-30T09:41:17","slug":"using-dtk-within-fortran-code","status":"publish","type":"post","link":"https:\/\/iww.inria.fr\/sed-sophia\/using-dtk-within-fortran-code\/","title":{"rendered":"Using dtk within Fortran code and outlook"},"content":{"rendered":"<p>In the context of the ADT Simon related to the Inria Project Lab (IPL) <a href=\"http:\/\/www-sop.inria.fr\/c2s_at_exa\/\">C2S@Exa<\/a> dealing with High Performance Computations (HPC), a lot of efforts were made by the dtk team to develop both API and efficient back-ends for parallel sparse linear algebra. Simultaneously, Tristan Cabel modified the Fortran code TRACES from the Andra Institute in order to reap the benefit of these developments (see this <a href=\"http:\/\/num3sis.inria.fr\/blog\/integration-of-traces-in-num3sis\/\">post<\/a>).<\/p>\n<p>In order to achieve such integration, Tristan has written Fortran modules using <em>iso_c_binding<\/em> features. These modules declare some interfaces to C++ functions that are in charge of handling C++ concepts from the dtkLinearAlgebraSparse layer.<\/p>\n<p><!--more--><\/p>\n<h2>Code snippet<\/h2>\n<p>Here follows a code snippet of such a module:<\/p>\n<pre>\r\nmodule mod_dtkLinearAlgebraSparse\r\n  use,intrinsic :: iso_c_binding\r\n  implicit none\r\n\r\n  interface\r\n\r\n     function dtkSparseMatrixResize(matrix, nb_row, nb_col) result(error) &\r\n         bind(C, name=\"dtkSparseMatrixResize\")\r\n       use, intrinsic :: iso_c_binding\r\n       type(c_ptr), intent(in), value :: matrix\r\n       integer(c_long_long), intent(in), value :: nb_row\r\n       integer(c_long_long), intent(in), value :: nb_col\r\n       integer(c_int) error \r\n     end function dtkSparseMatrixResize\r\n\r\n     function dtkSparseMatrixSetAt(matrix, row_id, col_id, value) result(error) &\r\n         bind(C, name=\"dtkSparseMatrixSetAt\")\r\n       use, intrinsic :: iso_c_binding\r\n       type(c_ptr), intent(in), value :: matrix\r\n       integer(c_long_long), intent(in), value :: row_id\r\n       integer(c_long_long), intent(in), value :: col_id\r\n       real(c_double) :: val\r\n       integer(c_int) :: error\r\n     end function dtkSparseMatrixSetAt\r\n\r\n     function dtkSparseMatrixAt(matrix, row_id, col_id) result(val) &\r\n         bind(C, name=\"dtkSparseMatrixAt\")\r\n       use, intrinsic :: iso_c_binding\r\n       type(c_ptr), intent(in), value :: matrix\r\n       integer(c_long_long), intent(in), value :: row_id\r\n       integer(c_long_long), intent(in), value :: col_id\r\n       real(c_double) :: val\r\n     end function dtkSparseMatrixAt\r\n\r\n   end interface\r\nend module mod_dtkLinearAlgebraSparse\r\n<\/pre>\n<p>The C++ functions retrieve the pointers, cast them into the right dtk concept (here the pointer is casted into <em>dtkSparseMatrix<\/em>) and then they carry out the required functionality:<\/p>\n<pre>\r\nextern \"C\" int dtkSparseMatrixResize(void *matrix, long long int nb_row, \r\n                                                   long long int nb_col)\r\n{\r\n   dtkSparseMatrix<double> *mat = static_cast < dtkSparseMatrix < double > *>(matrix);\r\n   mat->resize(nb_row, nb_col);\r\n   return 0;\r\n}\r\nextern \"C\" int dtkSparseMatrixSetAt(void *dtk_sparse_matrix, long long int row_id, \r\n                                                             long long int col_id, \r\n                                                                    double value)\r\n{\r\n    dtkSparseMatrix<double> *mat = static_cast < dtkSparseMatrix < double > *>(matrix);\r\n    mat->setAt(row_id, col_id, value);\r\n\r\n    return 0;\r\n}\r\nextern \"C\" double dtkSparseMatrixAt(void *dtk_sparse_matrix, long long int row_id, \r\n                                                             long long int col_id)\r\n{\r\n    dtkSparseMatrix<double> *mat = static_cast < dtkSparseMatrix < double > *>(matrix);\r\n    return mat->at(row_id, col_id);\r\n}\r\n<\/pre>\n<p>Using this module into the Fortran code enables to handle the sparse matrix: resizing it, setting values at some coordinates, getting values at some coordinates.<\/p>\n<h2>Outlook<\/h2>\n<p>Several ADT involving Fortran codes will start by the end of the year. Using dtk in such contexts is not a straightforward task. People from these Teams are not often on the edge as far as the software development is concerned and it would take them too much time and too many efforts to do so.<\/p>\n<p>A likely solution would be to generate in a quasi automatic way, the Fortran interfaces of dtk so that the end-users could embed it directly in their own code. Such a proposition will be submitted to the dtk committee.<\/p>","protected":false},"excerpt":{"rendered":"<p>In the context of the ADT Simon related to the Inria Project Lab (IPL) C2S@Exa dealing with High Performance Computations (HPC), a lot of efforts were made by the dtk team to develop both API and efficient back-ends for parallel sparse linear algebra. Simultaneously, Tristan Cabel modified the Fortran code\u2026<\/p>\n<p> <a class=\"continue-reading-link\" href=\"https:\/\/iww.inria.fr\/sed-sophia\/using-dtk-within-fortran-code\/\"><span>Continue reading<\/span><i class=\"crycon-right-dir\"><\/i><\/a> <\/p>\n","protected":false},"author":848,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_members_access_role":[],"_members_access_error":""},"categories":[29,5],"tags":[59,43,68],"class_list":["post-524","post","type-post","status-publish","format-standard","hentry","category-development-in-the-inria-teams","category-poc","tag-c","tag-dtk","tag-fortran"],"_links":{"self":[{"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/posts\/524","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/users\/848"}],"replies":[{"embeddable":true,"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/comments?post=524"}],"version-history":[{"count":20,"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/posts\/524\/revisions"}],"predecessor-version":[{"id":583,"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/posts\/524\/revisions\/583"}],"wp:attachment":[{"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/media?parent=524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/categories?post=524"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/tags?post=524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}