<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Approximatrix Forums — Translate FORTRAN to C++ for CUDA]]></title>
	<link rel="self" href="https://forums.approximatrix.com/extern.php?action=feed&amp;tid=967&amp;type=atom" />
	<updated>2024-11-22T20:12:52Z</updated>
	<generator>PunBB</generator>
	<id>https://forums.approximatrix.com/viewtopic.php?id=967</id>
		<entry>
			<title type="html"><![CDATA[Re: Translate FORTRAN to C++ for CUDA]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=4392#p4392" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>grogley wrote:</cite><blockquote><p>Will SF compile a C++ subroutine (not the brightest bulb in the programing universe)?</p></blockquote></div><p>Yes, Simply Fortran for Windows includes g++, and the development environment should handle it.&nbsp; The only issue you will have is linking.&nbsp; You&#039;ll need to add a flag to <em>Linker</em> under <em>Compiler Flags</em> in <em>Project Options</em>:</p><div class="codebox"><pre><code>-lstdc++</code></pre></div><p>That additional flag is necessary purely because Simply Fortran will use the Fortran compiler frontend for linking, and it won&#039;t automatically include the C++ standard library.</p><div class="quotebox"><cite>grogley wrote:</cite><blockquote><p>In that event I can&#039;t use the SF environment, I have downloaded the latest GNU files for Windows</p></blockquote></div><p>This step was probably unnecessary, but that&#039;s okay.&nbsp; We include the C and C++ compilers as well as most of the Windows-specific libraries.</p><div class="quotebox"><cite>grogley wrote:</cite><blockquote><p>How can I be sure it is using the non-SF path for compile and link?</p></blockquote></div><p>You can execute the commands:</p><div class="codebox"><pre><code>gfortran --version</code></pre></div><div class="codebox"><pre><code>gcc --version</code></pre></div><div class="codebox"><pre><code>g++ --version</code></pre></div><p>The Simply Fortran compilers should include the text <em>GCC for Simply Fortran</em>.</p><div class="quotebox"><cite>grogley wrote:</cite><blockquote><p>Apparently the forum editor will not allow me to cut and paste the code.</p></blockquote></div><p>That should work; I do it regularly.</p>]]></content>
			<author>
				<name><![CDATA[jeff]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=2</uri>
			</author>
			<updated>2024-11-22T20:12:52Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=4392#p4392</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Translate FORTRAN to C++ for CUDA]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=4391#p4391" />
			<content type="html"><![CDATA[<p>Thanks Jeff!</p><p>My starting point for this project is just get FORTRAN to call a C++ subroutine. It looks like I have to work outside the confines of SF compile and link stages... but if not how to do this since I think the C++ file needs to be compiled first to object code then linked to the FORTRAN compile link stage. Will SF compile a C++ subroutine (not the brightest bulb in the programing universe)?</p><p>In that event I can&#039;t use the SF environment, I have downloaded the latest GNU files for Windows but I think given the path for these new files, the compile stage is going to SF path. How can I be sure it is using the non-SF path for compile and link? </p><p>What I am doing specifically, a friend told me about Copilot (This a revelation to me, seems like cheating!) and it gave an example of a mixed FORTRAN calling a C++ subroutine. So I am trying to compile and link this example.</p><p>Apparently the forum editor will not allow me to cut and paste the code.</p><p>Thanks again in advance. Sorry to waste your time if this is not in the SF frameworks. <br />Rod</p>]]></content>
			<author>
				<name><![CDATA[grogley]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=3372</uri>
			</author>
			<updated>2024-11-22T16:01:06Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=4391#p4391</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Translate FORTRAN to C++ for CUDA]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=4390#p4390" />
			<content type="html"><![CDATA[<p>Rod,</p><p>You&#039;ll want to use the <strong>ISO_C_BINDING</strong> intrinsic module for calling C++ routines. You will need to create a C interface to your C++ routines, though, but that issue is common to many C++ libraries that expose their API.&nbsp; Fortran has no concept of C++ classes, so they&#039;ll appear as opaque <em>type(c_ptr)</em> arguments in Fortran.</p><p>You&#039;ll want to look at the <a href="https://simplyfortran.com/docs/compiler/ISO_005fC_005fBINDING.html#ISO_005fC_005fBINDING">ISO_C_BINDING module</a> and the <a href="https://simplyfortran.com/docs/compiler/Interoperability-with-C.html#Interoperability-with-C">section on interoperability with C</a> as a starting point, at least.&nbsp; If you plan on really getting into this, you might consider a book on modern Fortran that would explain using ISO_C_BINDING.</p><p><em>EDIT</em>: You&#039;ll also likely run into linking issues.&nbsp; What your purporting to do isn&#039;t particularly easy or straightforward as you&#039;ll be using an additional compiler for all the CUDA code.</p>]]></content>
			<author>
				<name><![CDATA[jeff]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=2</uri>
			</author>
			<updated>2024-11-20T19:19:31Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=4390#p4390</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Translate FORTRAN to C++ for CUDA]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=4389#p4389" />
			<content type="html"><![CDATA[<p>Hello All,</p><p>Its been a couple of years since last post and I haven&#039;t seen this topic in the the forum and apologize if I missed it.</p><p>I have my OpenMP FORTRAN simulation that I am thinking about converting to use multi-processing capabilities of CUDA cores. I would like to continue to use Windows as my development and runtime platform. I have done a cursory look at this and this seems possible. However, I don&#039;t want to rewrite the entire code into C++. I think SF (never attempted this) supports C++ subroutines called from FORTRAN, would it be possible to create CUDA C++ subroutines called from in my SF FORTRAN compile and link?</p><p>Thanks in advance,<br />Rod</p>]]></content>
			<author>
				<name><![CDATA[grogley]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=3372</uri>
			</author>
			<updated>2024-11-20T14:49:26Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=4389#p4389</id>
		</entry>
</feed>
