<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jim Kring on Medium]]></title>
        <description><![CDATA[Stories by Jim Kring on Medium]]></description>
        <link>https://medium.com/@jim.kring?source=rss-6148e70800b1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qWlj-O25Dc3YBaR1vBbFFw.jpeg</url>
            <title>Stories by Jim Kring on Medium</title>
            <link>https://medium.com/@jim.kring?source=rss-6148e70800b1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 13:31:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jim.kring/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Enhancing LabVIEW through Collaboration]]></title>
            <link>https://medium.com/@jim.kring/enhancing-labview-through-collaboration-3b180a77ecd1?source=rss-6148e70800b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b180a77ecd1</guid>
            <category><![CDATA[community]]></category>
            <category><![CDATA[labview]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[national-instruments]]></category>
            <dc:creator><![CDATA[Jim Kring]]></dc:creator>
            <pubDate>Mon, 25 Mar 2024 22:24:51 GMT</pubDate>
            <atom:updated>2026-07-27T14:46:30.476Z</atom:updated>
            <content:encoded><![CDATA[<h4>Open Sourcing More Parts of LabVIEW (Like the Icon Editor)</h4><p>Recently, I posted an idea to<strong> </strong><a href="https://forums.ni.com/t5/LabVIEW-Idea-Exchange/Move-the-LabVIEW-Icon-Editor-to-GitHub-and-Facilitate-Community/idi-p/4362832">host the LabVIEW Icon Editor on NI’s GitHub page to facilitate community contributions</a>.</p><p><strong>Today, at the </strong><a href="https://www.glasummit.org/"><strong>GLA Summit 2024</strong></a><strong> keynote, NI announced that it’s working on steps toward making that happen!</strong></p><p>And, while that’s not yet a 100% commitment, I still think it is great news that NI is publicly discussing it. In fact, <em>Open Sourcing More Parts of LabVIEW</em> is #7 on my list of <a href="https://medium.com/@jim.kring/7-ways-ni-can-increase-labview-adoption-in-2023-and-beyond-3d8273b60c19">7 Ways NI Can Increase LabVIEW Adoption</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DJJ-588oQO_t_fNfMqYH9A.png" /><figcaption>The Icon Editor is where users edit their VI’s icons — it’s where graphical programs become graphical.</figcaption></figure><p>I believe that <strong>NI working collaboratively together with the community on core parts of LabVIEW will have a lot of positive outcomes for everyone</strong>.</p><p>Here are just a few:</p><ol><li><strong>Make LabVIEW Better</strong> — We (the community) can work directly with NI to <strong>improve the LabVIEW Icon Editor by addressing bugs and usability issues</strong>. For example, I recently had to <a href="https://medium.com/@jim.kring/fixing-the-labview-icon-editor-on-linux-42e920743dc7">fix some issues with the Icon Editor on Linux</a>.</li><li><strong>Strengthen the Relationship with Users </strong>— There’s nothing like working together on something we all care about to bring people together. By working together with the community on more parts of LabVIEW, we can strengthen the relationship between NI and LabVIEW users, while also making progress towards things we all care about (i.e. <em>#1 Making LabVIEW Better</em>).</li><li><strong>Develop Better Dev Automation Tooling — </strong>This process will naturally cause NI R&amp;D to learn more about software engineering in LabVIEW. An outcome of this is that we’ll start to see more and better support for dev tooling in LabVIEW (since those with more direct power to fix the process will be forced to experience the problems). As we work on things like automated CI/CD (e.g. in docker containers), NI will get to work with the community to experience the pain points of trying to use modern text-based programming tools with a visual language. Many community members have developed tools to make this process easier, but we still have a long way to go and we need NI to prioritize this. If NI’s engineers get to “feel the pain” and “participate in the solutions” we are much more likely to see better support in LabVIEW for software engineering tooling.</li></ol><h4>Final Thoughts</h4><p>I think moving the LabVIEW Icon Editor to an open source project on GitHub could be a model for nurturing a vibrant, collaborative LabVIEW community that actively contributes to the growth in capabilities of LabVIEW (and the G programming language).</p><p>I am eager to see NI move this forward so we can all work together to make LabVIEW even better!</p><p>What do you think? Are you ready to help?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b180a77ecd1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why we need an “Enumerated Variant” Datatype in LabVIEW]]></title>
            <link>https://medium.com/@jim.kring/why-we-need-an-enumerated-variant-datatype-in-labview-c984906d2d49?source=rss-6148e70800b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/c984906d2d49</guid>
            <category><![CDATA[national-instruments]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[labview]]></category>
            <category><![CDATA[program-language-design]]></category>
            <category><![CDATA[type-safety]]></category>
            <dc:creator><![CDATA[Jim Kring]]></dc:creator>
            <pubDate>Mon, 25 Mar 2024 21:44:01 GMT</pubDate>
            <atom:updated>2024-03-25T21:44:01.836Z</atom:updated>
            <content:encoded><![CDATA[<h4>Enhancing the G Language with “Rust-like” enums</h4><p><em>Note: If you like this idea and would like to explore the code or vote on the idea to get NI to implement it, there are links at the bottom of this article.</em></p><h3>What is an Enumerated Variant?</h3><p>The idea is fairly simple, for each item in an Enum, we can associate a specific data type. This allows us to create a new data type that can be one of a few different types where there is a name associated with each type.</p><blockquote><em>Note: This is similar to a “tagged union” or “sum type” in other languages. Check out </em><a href="https://ziglang.org/documentation/master/#Tagged-union"><em>zig tagged unions</em></a><em> and </em><a href="https://doc.rust-lang.org/reference/items/enumerations.html"><em>rust enums</em></a><em> for some examples.</em></blockquote><p>Here’s what it would look like:</p><h3>1) Allow adding a specific datatype to each item of an Enum</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/0*mPfxfL6Z21nQWYmA.png" /><figcaption>Here is an Equipment Variant that defines three subtypes (named Robot, Pump, and Instrument). Each element of the Enum has a datatype associated with it.</figcaption></figure><h3>2) Allow coercing specific subtypes of the Enumerated Variant to the more general type</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/0*KfGOtHFwK7HbChar.png" /><figcaption>We can coerce our subtypes to the more general Enumerated Variant. Here we see that we can create an array of these different types.</figcaption></figure><h3>3) Allow using Enumerated Variants in a Case Structure, such that conversion to the specific data type to more general type is done automatically.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/929/0*GaUNWJrcaBQxVC_s.png" /><figcaption>We can wire an Enumerated Variant to the Case Select Terminal of a Case Structure and (like a regular enum) the Frames of the Case Structure will correspond to the elements of the Enum. LabVIEW will require there to be a frame to handle all possible subtypes.</figcaption></figure><h3>4) Consider Organizing in an LVLib or LVClass (or maybe even create a new LVType?)</h3><p>We might consider organizing Enumerated Variants in a Library, like an .lvclass or .lvlib -- that part is up for debate.</p><p>We will show a proof of concept example (below in the next sections) that uses a LabVIEW class (and Malleable VIs), and it works quite well.</p><h3>Motivation (Why not just use classes and dynamic dispatch?)</h3><p>The first question you might be asking is “Why not just use classes and dynamic dispatch?”</p><p>That’s a fair question. In LabVIEW, we can use classes and dynamic dispatch to achieve similar functionality. However, Dynamic Dispatch has some some limitations/challenges.</p><p>Dynamic Dispatch Limitations:</p><ul><li>Requires creating a new base class for the group of types you want to consider as a single type (which isn’t horrible, since it’s just one class).</li><li>Requires creating a new class for each specific type (this adds a lot of boilerplate code to maintain).</li><li>Run-time overhead of dynamic dispatch is greater than direct calls (which can be a problem in performance-critical applications)</li><li>Dynamic indirection of method calls (makes it harder to reason about and debug/follow the code execution paths).</li></ul><p>Simply put, the dynamic dispatch approach requires more boilerplate code and is less efficient than a native language feature that could do the same thing. Unless your application really needs a plug-in architecture or you are creating a library for others to use, the dynamic dispatch approach is probably more work than the benefit it provides. I have an expression I like to use: “Early abstraction is obstruction.” In other words, don’t abstract until you need to.</p><p>As mentioned above, the power of (1) combining an Enum with a set of data types for each value and adding native support for (2) coercion and (3) Case Structure type assertion and data conversion would allow us to create a more robust and type-safe LabVIEW code that is easier to maintain and understand (especially in situations where we do not gain much benefit from the expense of building an maintaining a plug-in architecture).</p><h3>Proof of Concept: Cluster of Enum and Variant</h3><p>In LabVIEW today, we can get close to such a feature by bundling an enum and each sub-type “variant” into a cluster. Notice how even though these clusters are different types, will all coerce to a cluster of Enum and Variant.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/0*VXE2v1FJgGkupeWF.png" /><figcaption>One way we can implement our Enumerated Variant is by bundling an Enum with a Variant. This allows any datatype (used for the 2nd element of the cluster) to coerce.</figcaption></figure><p>This allows us to do things like build arrays of these clusters and iterate over them in a For Loop. We can then unbundle the Enum to get the type and then unbundle the Variant and convert it to the correct type of data at runtime.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/0*VEmo0HjEr5erICd4.png" /><figcaption>An example showing the “Cluster or Enum and Variant” used to iterate over three different subtypes of equipment in a For Loop, with a Case Structure to handle each subtype.</figcaption></figure><p>This is nice, but it could be even better. Right now ANYTHING can be put into the Variant, and we have to do a runtime check to see if the data is of the correct type. And, one can accidentally associate the enum value with the wrong data type when an instance is created.</p><p>So, what we need is some template code that will allow us to associate a specific data type with each item in an Enum in a way that doesn’t require duplicate code and can be checked at compile time rather than runtime. Let’s see how close we can get.</p><p>We’ll use Malleable VIs and a LabVIEW classes to achieve this. It won’t get us all the way to native support, but it will get us to something that’s easy to use and maintain.</p><h3>Proof of Concept: Malleable VIs and LabVIEW Classes</h3><p>Now, let’s move from our cluster example to a LabVIEW class and Malleable VIs, which will give us even more useful features.</p><h4>EnumeratedVariant.lvclass (Base Class for Boilerplate Code)</h4><p>In this approach, we’re going to start out by creating a general-purpose base class called EnumeratedVariant.lvclass. We can see its private data contains two Variants: one for the Type Enum and one for the specific Data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/0*MFM85wbbKnrndORx.png" /><figcaption>EnumeratedVariant.lvcass is a reusable base class that stores an instance’s actual type and data and also includes some boilerplate code for instance creation and accessing data.</figcaption></figure><blockquote><em>Note that we could have created a very specific class with the actual Enum for Equipment types, but we’re going to keep it general for now so we can reuse this class for other types of Enumerated Variants.</em></blockquote><p>EnumeratedVariant.lvclass has the following features:</p><ul><li>Property Accessor methods for the Enum and Data Variants</li><li>A constructor for initializing the Enum and Data Variants.</li><li>Malleable VIs for converting to the specific Type Enum and Specific Data.</li></ul><p>These were boilerplate code, so we put them in the base class to avoid having to recreate them for each specific type of Enumerated Variant we might create in our application.</p><h3>EquipmentVariant.lvclass (our specific example)</h3><p>Now, let’s look at EquipmentVariant.lvclass.</p><ul><li>It inherits from EnumeratedVariant.lvclass)</li><li>It has an Enum type definition that defines the names of types that are considered EquipmentVariants.</li><li>It has ab Assert Type Malleable VI that can be used for asserting (at edit time) whether a specific data type is a valid EquipmentVariant subtype.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/0*zqq6o3yJuBoa8VbQ.png" /><figcaption>EquipmentVariant.lvclass is our specific Enumerated Variant. It doesn’t have any private data, since the enum and data are stored by the base class.</figcaption></figure><p>We can see that EquipmentVariant.lvclass does not have any private data -- it doesn&#39;t need it, because the base class will store both Enum and Data values.</p><p>We can see how these methods are used in the block diagram of this example, showing how we can create an array of different Equipment Variants and iterate over them in a For Loop, handling each type of Equipment Variant in a different frame of the Case Structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/0*ApWdgkhREATbpSqZ.png" /><figcaption>A practical example showing creation, type checking+conversion, and handling of specific subtypes.</figcaption></figure><p>Unlike our feature proposal where a Case Structure’s Case Select terminal/tunnels could automatically coerce to the specific data type inside of the frame for each specific type, we have to do this type conversion manually in the code.</p><h3>Error Handling and Type Safety</h3><p>In our implementation with classes and malleable VIs, we will need tocheck for type errors, since we cannot guarantee the code will convert to the correct, more-specific subtype in the associated Case Structure frame for handling that type.</p><blockquote>Note: if the Case Structure could convert the data automatically (based on wiring the actual Enumerated Variant into the Case Selector terminal), we would have type safety (through edit time static type checking) and avoid that problem altogether. That’s part of our feature proposal for native support of this new Enumerated Variant type.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/0*i3FoMihpqKmCW-BF.png" /><figcaption>Error handling is needed for our class-based implementation, because we cannot use the Case Structure to do our subtype conversion directly at the boundary of the Case Select Terminal (which would be nice).</figcaption></figure><h3>Type Checking using Malleable VIs</h3><p>Even though we may still have some runtime errors we need to handle, we can get some static type checking using a Malleable VI that asserts a type is one of the possible types for an EquipmentVariant. We will name this VIM Assert Type.vim and is used in both To Enumerated Variant.vim and To Specific Variant.vim.</p><p>We can see how this VIM is called in the block diagram of To Enumerated Variant.vim and To Specific Variant.vim below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Di6__EjEqrJ4S_nl.png" /><figcaption>The `Assert Type.vim` Malleable VI can be see in the type conversion utility vims. It is used to assert that data is a valid EquipmentVariant subtype</figcaption></figure><h3>Assert Type.vim — Malleable VI that Maps Enum to Data Type</h3><p>Looking under the hood of EquipmentVariant.lvclass:Assert Type.vim we see that it has a Type Specialization Structure with a frame that asserts each possible type and outputs the associated Enum value. <strong>This is the only location in our code that defines this association</strong>, so it is easy to maintain and understand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/0*FiRQIogng2QDndWL.png" /><figcaption>We can see how `EquipmentVariant.lvclass:Assert Type.vim` is implemented — it maps each type to the associated Enum value.</figcaption></figure><p>Let’s say that again…</p><p><strong>The </strong><strong>Assert Type VIM is the only location in our code that defines the association between the Enum values and its Data Type variants</strong>. That makes for highly maintainable code! We simply call this VI anywhere we need to assert that a data type is a valid EquipmentVariant subtype.</p><h3>Conclusion</h3><p>Hopefully we’ve shown the usefulness of an Enumerated Variant type in LabVIEW and how we can get close to this feature using Malleable VIs and LabVIEW classes.</p><ul><li>First, we looked at a simple feature proposal in LabVIEW that would allow us to associate a specific data type with each item in an Enum and how adding support for data coercion and integration with the Case Structure would be a huge benefit to LabVIEW developers.</li><li>Next, we looked at how we might achieve this with a cluster of Enum and Variant.</li><li>Then, we added some boilerplate code to a base class that would allow us to create a specific type of Enumerated Variant with minimal code duplication.</li><li>Finally, we implemented as much static type checking as is possible today using Malleable VIs and Type Specialization Structures.</li></ul><p>We hope this example has been helpful and that you can see the benefits of this design pattern and feature proposal. We’d love to hear your feedback and ideas for how this could be improved or implemented in LabVIEW.</p><h4>Next Steps</h4><p>You can download all the code shown in this post here: <a href="https://github.com/JKISoftware/enumerated-variant-labview-idea">github.com/JKISoftware/enumerated-variant-labview-idea</a></p><p>Please let me know what you think and if you have any questions.</p><blockquote>Note: This idea has been <a href="https://forums.ni.com/t5/LabVIEW-Idea-Exchange/quot-Enumerated-Variant-quot-Data-Type-like-Rust-and-Zig-have/idi-p/4362485">posted to the LabVIEW Idea Exchange</a>. If you think NI should implement this as a native feature, be sure it give it a star.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c984906d2d49" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LabVIEW Anywhere (Watch GDevCon Presentation Video)]]></title>
            <link>https://medium.com/@jim.kring/labview-anywhere-watch-gdevcon-presentation-video-3e137e9b252f?source=rss-6148e70800b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e137e9b252f</guid>
            <category><![CDATA[national-instruments]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[compilers]]></category>
            <category><![CDATA[labview]]></category>
            <category><![CDATA[emerson]]></category>
            <dc:creator><![CDATA[Jim Kring]]></dc:creator>
            <pubDate>Wed, 08 Nov 2023 17:23:02 GMT</pubDate>
            <atom:updated>2023-11-08T17:28:56.855Z</atom:updated>
            <content:encoded><![CDATA[<h4>A LabVIEW community G compiler stack</h4><p>TL;DR — video at bottom of article 👇</p><p>Last month at <a href="http://www.gdevcon.com/">GDevCon#4</a>, JKI team member <a href="https://medium.com/u/2a974804ab2d">Tom Mcquillan</a> shared updates and an overview about the possibilities for a LabVIEW community project to develop a G compiler using LabVIEW, that can run your G code on a target a variety of platforms and run your LabVIEW code on the web, embedded targets, and… well… <strong><em>anywhere</em></strong>.</p><h4>Tom talks about where LabVIEW is today,</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*4FPXYKZkq5DUn6l1yBzP_g.png" /></figure><h4>and where LabVIEW could be in the future.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*EV1npoGgkvCRFgWYJV29Wg.png" /></figure><p>In this presentation, Tom talks about how a key part of this future would be enabled by…</p><h4>A community-based compiler stack written in LabVIEW!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*_VXwcSGwsLT89pk7Q46piQ.png" /></figure><p>Such a compiler stack could even make it possible to target Emerson (the new owner of NI LabVIEW) hardware!</p><p>So, without further ado…</p><h4>Here is the presentation video:</h4><p>Watch as Tom teaches us a little bit about compiler technologies, and then explores how the LabVIEW community could build a G compiler that would allow us to run our G code anywhere!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FLabTabdCtHo%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DLabTabdCtHo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FLabTabdCtHo%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e3013d879556ee1bf7707d6724971e5/href">https://medium.com/media/2e3013d879556ee1bf7707d6724971e5/href</a></iframe><p>And, if you have any questions, feel free to reach out to me on LinkedIn <a href="http://linkedin.com/in/jimkring">jim.kring</a> or here in the comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e137e9b252f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Programming in “Abstract G”]]></title>
            <link>https://medium.com/@jim.kring/programming-in-abstract-g-7e970f123f3c?source=rss-6148e70800b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e970f123f3c</guid>
            <category><![CDATA[compilers]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[visual-programming]]></category>
            <dc:creator><![CDATA[Jim Kring]]></dc:creator>
            <pubDate>Fri, 03 Nov 2023 02:38:41 GMT</pubDate>
            <atom:updated>2023-11-03T02:54:27.694Z</atom:updated>
            <content:encoded><![CDATA[<h4>It looks just like regular G, but *generates a data-flow graph* instead of executing it…</h4><h3>Abstract G?</h3><p>You are probably thinking to yourself what does “Abstract G” mean?</p><p>I mean that the code isn’t the code you think it is, but code that generates the code you think it is.</p><p>Now, you’re probably thinking… “huh?”</p><p>It’s OK, we’re going to take a little journey and step into a new world where ANYTHING is possible in G: creating a G compiler in G, creating a G editor in G, or even creating a G compiler in G that can compiler the G compiler and editor, or how about a G editor that can edit the code for the G compiler that compiles itself and the editor that was used to create it. Yes, all of this, and more.</p><p>Follow me.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*JRxnSQW73mvxyLXU1YzCGA.jpeg" /></figure><h3>Abstract G</h3><p>To answer the big question “What is Abstract G”, let’s look at some code. Here is a LabVIEW VI that is written in Abstract G.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*LB6EwwHlmb8NUembDaShtA.png" /></figure><p>Of course, you are probably thinking to yourself, <strong><em>“This looks like normal G code. What’s different?”</em></strong></p><p>The difference is:</p><p><strong>In Abstract G…</strong></p><ul><li><strong>The nodes do not actually execute the G code that the nodes represent — there is no string concatenation or printing occurring.</strong></li><li><strong>Instead, the nodes, when executed, are building a dataflow graph (think of it like “script a block diagram”) behind the scenes.</strong></li></ul><p><strong>And…</strong></p><ul><li><strong>The wires do not contain the *data* from the described computations</strong></li><li><strong>Instead, the data that flows through the wires are actually *references to the upstream data source terminals* in the dynamically created graph</strong>.</li></ul><p>To really understand Abstract G, let’s watch this quick demonstration video of these concepts in action.</p><h4>Video Demo of “Abstract G” (Code that generates the code it represents)</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.loom.com%2Fembed%2Fe40f34a7c9954851a90aed80fa4afc31&amp;display_name=Loom&amp;url=https%3A%2F%2Fwww.loom.com%2Fshare%2Fe40f34a7c9954851a90aed80fa4afc31&amp;image=https%3A%2F%2Fcdn.loom.com%2Fsessions%2Fthumbnails%2Fe40f34a7c9954851a90aed80fa4afc31-1698966693567.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=loom" width="2560" height="1920" frameborder="0" scrolling="no"><a href="https://medium.com/media/166cb3cdfc00775b42b60ddbade6cc02/href">https://medium.com/media/166cb3cdfc00775b42b60ddbade6cc02/href</a></iframe><h3>Why program in Abstract G?</h3><p>You might be wondering why would we want to defer execution of our code. The reason is that there are some very powerful cababilities enabled by this approach.</p><p>When we have an abstract form of our G code, we can do a variety of useful things:</p><p>We can…</p><ul><li>interpret and execute the code in different ways</li><li>transform and modify the code — <a href="https://en.wikipedia.org/wiki/Macro_(computer_science)">macros</a> are a great example of this</li><li>compile it to run on different execution systems — compilers generally require an abstract syntax tree (AST) to work with</li><li>translate (transpile) it to other languages like C, Python, JavaScript, Rust, etc.</li><li>serialize it to/from JSON</li><li>and much more!</li></ul><p>This is just the tip of the iceberg, in terms of where Abstract G can take graphical programming. Now that the code actually generates the code to create the code, we’ve unlocked a lot of new possibilities. More on that, soon…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e970f123f3c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jim’s List of LabVIEW Longings]]></title>
            <link>https://medium.com/@jim.kring/jims-list-of-labview-longings-3d6aa0d0cdd9?source=rss-6148e70800b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d6aa0d0cdd9</guid>
            <category><![CDATA[developer-experience]]></category>
            <category><![CDATA[labview]]></category>
            <category><![CDATA[national-instruments]]></category>
            <dc:creator><![CDATA[Jim Kring]]></dc:creator>
            <pubDate>Thu, 12 Oct 2023 20:09:37 GMT</pubDate>
            <atom:updated>2024-02-14T19:30:54.293Z</atom:updated>
            <content:encoded><![CDATA[<h4>An evolving collection of stuff that I see as needing fixed or improved in LabVIEW</h4><p>I’ve decided to create a log of little thing that I would like to see fixed in or added to LabVIEW. This is aimed at making LabVIEW better — I’ve got a much longer list of things I love about LabVIEW and I’ll try to post those often, too :)</p><h4>Need a way to get TDMS File Size from a TDMS File Reference</h4><p>Currently, the LabVIEW api for <a href="https://www.ni.com/en/support/documentation/supplemental/06/the-ni-tdms-file-format.html">TDMS File</a> does not offer a way to get the TDMS file size.</p><figure><a href="https://forums.ni.com/t5/LabVIEW-Idea-Exchange/Need-a-way-to-get-TDMS-File-Size-from-a-TDMS-File-Reference/idi-p/4354685"><img alt="" src="https://cdn-images-1.medium.com/max/43/1*Ek8IT6o3W45cenzRuXvAyQ.png" /></a><figcaption>Click the star to give this ☝️ LabVIEW Idea your vote</figcaption></figure><p>My use case is that I’d like to be able to limit the size of the TDMS files and span them across multiple individual files. To do this, we need to be able to monitor the TDMS file size, so that we can save/close the current file and then create the next file in the span for continued use (until we hit the size limit again).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*kX-uyBwh2ok2PJ9X" /><figcaption>There’s no functionality for reading the current file size!?!?</figcaption></figure><h4>Broken wires when “Inserting” functions into Map and Set wires (LV2023.3)</h4><p>I’ve been using Maps and Sets a LOT lately. I’ve even been working on <a href="https://www.vipm.io/package/vipm_lib_labview_collection_extensions/">a great little library of additional tools/functions for Maps and Sets</a> to share with others.</p><p>Yet, one pain point I’m finding is that, when I want to quickly insert one of the operations into an existing wire, it doesn’t works as I expect. Both the <em>Insert </em>right-click shortcut on a set/map wire and the <em>Ctrl+Space → Ctrl+I</em> QuickDrop Shortcut doesn’t wire it up correctly, as shown in the screenshot below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nG1NoSGB-YyfDZ6qSFWr4A.png" /><figcaption><em>This is what happens if you try to insert an operator into a Map or Set wire.</em></figcaption></figure><p>If we could fix that, it would really improve the developer experience.</p><h4>Log of Additions and Updates</h4><ul><li>2024–02–14: <em>Need a way to get TDMS File Size from a TDMS File Reference</em></li><li>2023–10–12: <em>Broken wires when “Inserting” functions into Map and Set wires (LV2023.3)</em></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d6aa0d0cdd9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fixing the LabVIEW Icon Editor on Linux]]></title>
            <link>https://medium.com/@jim.kring/fixing-the-labview-icon-editor-on-linux-42e920743dc7?source=rss-6148e70800b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/42e920743dc7</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[national-instruments]]></category>
            <category><![CDATA[labview]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Jim Kring]]></dc:creator>
            <pubDate>Mon, 25 Sep 2023 23:03:44 GMT</pubDate>
            <atom:updated>2023-09-25T23:03:44.482Z</atom:updated>
            <content:encoded><![CDATA[<h4>(Editing icons on Linux feels broken due to missing “small fonts”)</h4><p><em>Disclaimer: This post is pretty specific to LabVIEW and use on Linux — I’m mostly posting it as a TIL and/or reference for others that have and want to fix this issue. If this doesn’t apply to or interest you, this might be one to skip :)</em></p><p>Still interested? Great!</p><h4><strong>Problem: Editing VI Icons feels broken on Linux an Mac.</strong></h4><p>If you’ve tried to use LabVIEW for Linux or Mac, then you’ve probably created some VI icons that look like the screenshot below— big, anti-aliased, and impractical for LabVIEW’s 32x32 pixel icon area.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*eBUZnfpo7_A8UMf1GDmLEQ.png" /><figcaption>This is usually what LabVIEW icons look like when working on Linux.</figcaption></figure><p>The issue, as I’ve dug into it, stems from the fact that “small fonts” (which is everyone’s goto font for editing icons in LabVIEW) is a Microsoft Windows font. This font in size 8 works great for LabVIEW icons as you can see in the screenshot below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*7iiyrRzp_1IqTx7IeswM5A.png" /><figcaption>This is usually what LabVIEW icons look like when working on Windows.</figcaption></figure><h4>Attempts at Finding “Small Fonts” on Linux</h4><p>After some LabVIEW discussion forums spelunking, I was able to figure some things out…</p><p>I found out that “small fonts” is a Microsoft Windows font.</p><p>I’ve been able to successfully convert/export “small fonts” to Linux (as an OpenType format file using <a href="https://fontforge.org/en-US/">FontForge</a>) and have been able to get it to show up as “small fonts” in LabVIEW. (Message me if you want a copy to test)</p><p>That’s great, actually!</p><p>However, there’s still an issue in that it only looks right if the size is set to 6 point, whereas on Windows it needs to be set to 8 point.</p><p>The problem is that LabVIEW stores the font names and sizes of the icon elements in the VI’s property data. And, it uses these when regenerating the icon — this can happen when editing a VI’s owning library/class or using the QuickDrop text icon shortcut (Ctrl+Space -&gt; Ctrl+K).</p><p>And, it happens if you open the VI in the icon editor and change anything — so, if you open a VI’s icon for editing on Linux, it’ll look wrong and you’ll have to change the font size (which will then mess up someone editing the code on Windows).</p><p>Since (1) nearly every LabVIEW developer uses Small Fonts 8 (or 9) on Windows and (2) opening VIs on Linux and editing the icon causes it to get garbled up if LV can’t find the font on the system, we need to solve this issue before anyone can actually use Linux as their development machine and co-exist with nearly everyone else on Windows.</p><p>This is super important for increasing LabVIEW for Linux adoption, which I believe is great for increasing LabVIEW adoption.</p><h4><strong>Ideal Future Solution</strong></h4><p>I think LabVIEW should drop OS fonts/rendering for icon text and just use a new built-in small pixel font. OpenGDS has this for its icon editor and it works great — it’s even better than “small fonts” IMO, because it’s more compact for some characters.</p><h4><strong>A More Backwards Compatible Future Solution</strong></h4><p>LabVIEW could use a new built-in small pixel font (as described above), but give it a name like “LabVIEW Icon” and don’t use the OS to render it — just do it in LabVIEW. This could be made the default icon editor font, in cases where specified font cannot be found registered in the OS.</p><p>It would be nice to also have an easy way to migrate all VIs icons over to use this new “LabVIEW Icon” font (instead of “small fonts”).</p><h4><strong>A Present-Day Solution (that will make things better in the long run)</strong></h4><p>I think a few things need to happen…</p><p>1) <strong>See if we can make a “small fonts” font file that “just works”</strong> for LabVIEW on Linux.</p><p>I’d like to figure out whether it’s possible to get the small fonts working in the icon editor on Linux — maybe I missed some critical step in the process of converting it.</p><ul><li>I tried installing the Microsoft TrueType fonts on my Ubuntu system with the following command `apt install ttf-mscorefonts-installer`</li><li>I used FontForge (a desktop/gui app you can get via `apt install fontforge`) to export the small fonts `smalle.fon` file to an OpenType formatted file with the human-friendly name “small fonts” — there are a bunch of settings that I don’t understand.</li></ul><p><strong>2) Let’s create an official LabVIEW font/package</strong>— Assuming it is possible to create a “small fonts” icon that works in LabVIEW (without the size difference issue on Windows vs Linux), let’s create a (semi-)official “small fonts” font file for LabVIEW. We could even package it up as rpm/deb that can be easily installed on Linux by users, however dropping it into the fonts folder isn’t too hard, but who’s got time for that…</p><p><strong>3) Make the LabVIEW Icon Editor open source</strong> (on <a href="http://github.com/ni">github.com/ni</a>)</p><p>I would love it for NI to officially open source LabVIEW’s Icon Editor. It would be great the LabVIEW community could find and fix the bugs and make some improvements.</p><p>In fact, <strong><em>it would be great if more parts (or all) of the LabVIEW editor were open source</em></strong>, but that’s a topic for another post.</p><h4>Next Steps</h4><p>I’m going to keep digging into a solution and will post updates as I learn more. Stay tuned…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42e920743dc7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TIL: Disable the “Fast File Format” setting on LabVIEW for Linux builds in order for app icons to…]]></title>
            <link>https://medium.com/@jim.kring/til-disable-the-fast-file-format-setting-on-labview-for-linux-builds-in-order-for-app-icons-to-71a3bf20156a?source=rss-6148e70800b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/71a3bf20156a</guid>
            <category><![CDATA[labview]]></category>
            <category><![CDATA[jki]]></category>
            <category><![CDATA[national-instruments]]></category>
            <category><![CDATA[vipm]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Jim Kring]]></dc:creator>
            <pubDate>Thu, 14 Sep 2023 00:14:12 GMT</pubDate>
            <atom:updated>2023-09-14T00:18:18.577Z</atom:updated>
            <content:encoded><![CDATA[<h3>TIL: Disable the “Fast File Format” setting on LabVIEW for Linux builds in order for app icons to work</h3><p>Today, while working on <a href="http://vipm.io/desktop">VIPM</a> for Linux, I discovered a bug in LabVIEW that causes your built app’s desktop icon to not show properly* if your application was built using the <strong>Fast File Format</strong> feature in the build spec settings.</p><p><em>*Instead of showing your application’s icon, it shows the LabVIEW default icon.</em></p><p>Here’s a screenshot of my “help!” message I sent to NI asking what was going wrong.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fE18C8x4hHfBtrbBKRuDVQ.png" /></figure><p>To work around this, turn OFF the use fast file format feature on Linux, as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rF7NnqnYspdwA50VAaxtuw.png" /></figure><p><em>Note: On Linux the file system is pretty fast (more so than on Window) so this change probably won’t matter much.</em></p><blockquote>Update: This bug has been filed with NI as Issue #2521298</blockquote><p>Also, if you’re interested in building stand-alone LabVIEW applications on Linux and want to use the new desktop icon feature, you can find out more in the <a href="https://www.ni.com/docs/en-US/bundle/upgrading-labview/page/labview-2023q1-changes.html">LabVIEW 2023 Q1 changes</a> doc.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71a3bf20156a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to call Rust code from LabVIEW]]></title>
            <link>https://medium.com/@jim.kring/how-to-call-rust-code-from-labview-18a70702546a?source=rss-6148e70800b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/18a70702546a</guid>
            <category><![CDATA[rust-programming-language]]></category>
            <category><![CDATA[labview]]></category>
            <category><![CDATA[national-instruments]]></category>
            <dc:creator><![CDATA[Jim Kring]]></dc:creator>
            <pubDate>Tue, 18 Jul 2023 18:48:00 GMT</pubDate>
            <atom:updated>2025-10-19T20:44:51.901Z</atom:updated>
            <content:encoded><![CDATA[<h4>Using a popular rust crate as a cross-platform LabVIEW library</h4><p>I’ve been talking a lot about <a href="https://www.medium.com/@jim.kring/transforming-labviews-rusty-wires-7e3f2d954a6f">the Rust programming language, lately, and some of its similarities to LabVIEW</a>.</p><p>Now, I wanted to talk about how we can actually call rust code from LabVIEW and package it all up as a cross-platform library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*HT7in9FFInmWPXtqKQrLfw.png" /><figcaption>LabVIEW can call rust libraries via the Call Library Function (if built into shared libraries)</figcaption></figure><p><strong><em>TL;DR </em></strong><em>Check out the </em><a href="https://github.com/JKISoftware/toml-edit-labview"><em>toml_edit_labview</em></a><em> library by JKI, to see a real-world example of this approach in action!</em></p><h4>The Basic Approach — shared library built for each supported platform</h4><ol><li><strong>Build the rust library into a “shared library”</strong> (.dll, .so, or .framework files on Windows, Linux, and Mac respectively).</li></ol><ul><li><strong>Create a set of exported functions and types in Rust</strong> that LabVIEW can handle.</li><li><strong>Build the shared library on all the desired platforms</strong> (e.g. via github actions that run on github’s public runners: windows-latest, ubuntu-latest, macos-latest) including 32-bit and 64-bit on Windows.</li></ul><p>2. <strong>Create a LabVIEW library that calls the shared library</strong>.</p><ul><li>Make sure you call into the shared library (rust) functions that clean up and close references that were opened in rust.</li></ul><p>The devil is always in the details; In future articles, I’ll share more on each of these areas.</p><h4>A Real Example —LabVIEW bindings for rust’s toml library</h4><p>If you’d like to explore a working example of this approach in action, check out the <a href="https://github.com/JKISoftware/toml-edit-labview">toml_edit_labview</a> library that was recently published by JKI — it even has a working github action that builds and tests the shared library on all platforms.</p><p><em>Side note: you might also want to check out the </em><a href="https://github.com/WiresmithTech/Rust-LabVIEW-Interop"><em>Rust-LabVIEW-Interop</em></a><em> project on github that </em><a href="https://github.com/WiresmithTech"><em>WiresmithTech</em></a><em> is working on. It’s still very experimental.</em></p><p>Let me know if you have any questions and/or what you’d like to learn more about as you explore Rust and LabVIEW interoperability!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18a70702546a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NI Connect 2023]]></title>
            <link>https://medium.com/@jim.kring/ni-connect-2023-c13f2428e497?source=rss-6148e70800b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/c13f2428e497</guid>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[labview]]></category>
            <category><![CDATA[national-instruments]]></category>
            <dc:creator><![CDATA[Jim Kring]]></dc:creator>
            <pubDate>Mon, 22 May 2023 18:27:16 GMT</pubDate>
            <atom:updated>2023-06-11T17:07:29.809Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/428/1*ItTq-gx2rpzfB3Bl1mqcGw.png" /></figure><p>I’m at NI Connect in Austin, TX this week, speaking on several topics. I’ll post notes and resources here…</p><h4>Presentation: XOR Encryption in LabVIEW</h4><p>At my presentation on XOR Encryption, I referenced the following example code:</p><ul><li><a href="https://github.com/JKISoftware/jki-xor-cypher-encryption-labview">XOR Cypher Encryption (LabVIEW Examples created by Jim Kring / JKI)</a></li><li><a href="https://forums.ni.com/t5/Example-Code/Advanced-Encryption-Standard-AES-for-LabVIEW-FPGA/ta-p/3996118">AES Encryption (LabVIEW FPGA Example created by NI)</a></li></ul><h4>Presentation: G Anywhere</h4><p>I gave a presentation on the compelling case for building a G compiler in G, and how we could undertake such a task. There were also some demos of parts of this process in action (trans-compiling G to Rust for running console applications in Windows and bare-metal embedded apps on the Raspberry Pi Pico, RP2040 micro-controller).</p><p>I’ll be sharing more updates in the weeks and months ahead as this project progresses.</p><p><a href="https://www.linkedin.com/posts/jimkring_my-ni-connect-presentation-on-compiling-graphical-activity-7067146066499964929-k95P">View the Presentation Slides</a></p><figure><a href="https://www.linkedin.com/posts/jimkring_my-ni-connect-presentation-on-compiling-graphical-activity-7067146066499964929-k95P"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CbjQkMTCgTY8X7c2BxJBwQ.png" /></a><figcaption><a href="https://www.linkedin.com/posts/jimkring_my-ni-connect-presentation-on-compiling-graphical-activity-7067146066499964929-k95P">Presentation Slides on LinkedIn</a></figcaption></figure><p><a href="https://youtu.be/7vHngGgZshU">Watch the presentation video on YouTube here</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F7vHngGgZshU%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D7vHngGgZshU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F7vHngGgZshU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3f22c0a5359537ae7405af2befd5f06/href">https://medium.com/media/b3f22c0a5359537ae7405af2befd5f06/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c13f2428e497" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Parallel Node to Rust Code]]></title>
            <link>https://medium.com/@jim.kring/from-parallel-node-to-rust-code-6d3735e6e197?source=rss-6148e70800b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d3735e6e197</guid>
            <category><![CDATA[labview]]></category>
            <category><![CDATA[compilers]]></category>
            <category><![CDATA[national-instruments]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[programming-languages]]></category>
            <dc:creator><![CDATA[Jim Kring]]></dc:creator>
            <pubDate>Sat, 29 Apr 2023 23:01:21 GMT</pubDate>
            <atom:updated>2023-05-23T17:06:42.755Z</atom:updated>
            <content:encoded><![CDATA[<h4>G Compiler in G — Part 4</h4><h4>Translating LabVIEW Graphical Dataflow to Text-based Concurrency</h4><p>In <a href="https://medium.com/@jim.kring/transforming-labviews-rusty-wires-7e3f2d954a6f">our last article</a> on the topic of building a graphical dataflow (G) programming language compiler in G, we explored the intriguing similarities between LabVIEW’s graphical dataflow and the Rust programming language, illustrating how Rust’s core values and features make it a great choice for translating and transpiling G programs.</p><p>Today, we’re taking the journey further by diving into the world of parallelism and concurrency, examining how a translation compiler can be used to unleash the full potential of graphical dataflow programming languages.</p><h3>The Challenge: Translating Graphical Dataflow Parallelism to Sequential Processor Instructions</h3><p>The crux of the matter lies in translating an inherently parallel graphical dataflow program into a set of sequential processor instructions while maintaining its original parallelism and concurrency.</p><p>For example, let’s look at the following LabVIEW example program, which has two waits in parallel — one that waits 1000ms and the other that wait’s 2000ms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*GrvGE1j9npv4v6zzuLfPoA.png" /><figcaption>a LabVIEW graphical dataflow (G) program with two waits in parallel</figcaption></figure><p>According to the rules of G,</p><ul><li>the two wait nodes will start approximately simultaneously (once the program is run); and</li><li>once both nodes complete execution, the program will terminate (since there is no more code to execute).</li></ul><p>Based on those rules, <strong>the total execution time of the program should ideally be equal to the longest individual wait time, which is 2000ms</strong>.</p><p>However, if we translate our G program into sequentially executed text-based code, the execution times stack up and becomes the sum of the two individual wait times, which is 3000ms — that’s significantly off the mark.</p><pre>// run the first wait<br>wait_ms(1000, &quot;Wait 1&quot;);<br><br>// run the second wait<br>wait_ms(2000);<br><br>// total wait time = 3000 milliseconds</pre><p>Since translating parallel G nodes to sequential instructions results in completely different runtime behavior, we can’t stop there and will need to explore ways to achieve the parallelism and concurrency described by our G program.</p><h3>Starting Point: Translating to Sequential Waits</h3><p>To begin this exploration, let’s now expand on our previous snippet of Rust code so we can run it and print useful information about the order and timing of execution.</p><p><strong><em>Run the Code</em></strong><em>: </em><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2021&amp;gist=b4730c13105c1112ad6bf54336e566e4"><em>Click here</em></a><em> to to run (and experiment with) this example code in the Rust Playground.</em></p><pre>// import standard libraries for wait timing<br>use std::thread;<br>use std::time::{Duration, Instant};<br><br>// a reusable wait function that will also print a label for debugging<br>fn wait_ms(ms: u64, label: &amp;str) {<br>    println!(&quot;{} started&quot;, label);<br>    thread::sleep(Duration::from_millis(ms));<br>    println!(&quot;{} finished&quot;, label);<br>}<br><br>// the main entry point of our program<br>fn main() {<br><br>    // let&#39;s start our stopwatch<br>    let start_time = Instant::now();<br><br>    // run the first wait in the current thread<br>    wait_ms(1000, &quot;Wait 1&quot;);<br><br>    // run the second wait in the current thread<br>    wait_ms(2000, &quot;Wait 2&quot;);<br><br>    // get the total ellapsed time of our program<br>    let total_duration = start_time.elapsed();<br><br>    // display the results<br>    println!(<br>        &quot;Total execution time: {}.{:03} seconds&quot;,<br>        total_duration.as_secs(),<br>        total_duration.subsec_millis()<br>    );</pre><p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2021&amp;gist=b4730c13105c1112ad6bf54336e566e4">When this code runs</a>, we see that the first wait (1000ms) starts and finishes execution before the second wait (2000ms) even begins — the two waits run sequentially. And, we see that the total run time is the sum of the two waits, or 3000ms total.</p><pre>Wait 1 started<br>Wait 1 finished<br>Wait 2 started<br>Wait 2 finished<br>Total execution time: 3.000 seconds</pre><p>As stated previously, this sequential execution of the wait functions is not the behavior we want for our parallel G program. Let’s look at how can we fix that…</p><h3>Tapping into the Power of Modern Text-Based Languages for Concurrency</h3><p>The good news is <strong>most modern programming languages, like Rust, come equipped with great features for concurrency and parallelism</strong> (e.g. threads, async &amp; await, and many more). By translating our graphical dataflow program to Rust, we then now can tap into the immense power of its parallelism and concurrency libraries in our compiled G code.</p><p>Let’s take a look at how we can achieve the desired parallelism in the Rust translation of our G code…</p><h3>An Example: Translating to Parallel Waits in Rust</h3><p>Let’s take a look at how to evolve the Rust translation of our G code to leverage one of Rust’s core concurrency features — threads.</p><p>In <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2021&amp;gist=5e1c06b9cd6d9638b312c170613e84b9">the example below</a>, rather than calling the wait functions sequentially, we wrap them in a thread::spawn() function, which returns immediately (rather than waiting for the code inside it to finish). At some later point in the code, we can call the join() method (on the thread reference that was returned by spawn()) to wait on the thread’s completion and get any data the code in the thread returns.</p><p><strong><em>Run this Code</em></strong><em>: </em><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2021&amp;gist=5e1c06b9cd6d9638b312c170613e84b9"><em>Click here</em></a><em> to to run (and experiment with) this example code in the Rust Playground</em></p><pre>// import standard libraries for threading and wait timing<br>use std::thread;<br>use std::time::{Duration, Instant};<br><br>// a reusable wait function that will also print a label for debugging<br>fn wait_ms(ms: u64, label: &amp;str) {<br>    println!(&quot;{} started&quot;, label);<br>    thread::sleep(Duration::from_millis(ms));<br>    println!(&quot;{} finished&quot;, label);<br>}<br><br>// the main entry point of our program<br>fn main() {<br><br>    // let&#39;s start our stopwatch<br>    let start_time = Instant::now();<br><br>    // run the first wait in its own thread<br>    let thread_1 = thread::spawn(move || {<br>        wait_ms(1000, &quot;Wait 1&quot;);<br>    });<br><br>    // run the second wait in its own thread<br>    let thread_2 = thread::spawn(move || {<br>        wait_ms(2000, &quot;Wait 2&quot;);<br>    });<br><br>    // wait until both threads are finished<br>    thread_1.join().unwrap();<br>    thread_2.join().unwrap();<br><br>    // get the total ellapsed time of our program<br>    let total_duration = start_time.elapsed();<br><br>    // display the results<br>    println!(<br>        &quot;Total execution time: {}.{:03} seconds&quot;,<br>        total_duration.as_secs(),<br>        total_duration.subsec_millis()<br>    );<br>}</pre><p>When we <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2021&amp;gist=5e1c06b9cd6d9638b312c170613e84b9">run our program</a>, we see that the two waits are running in parallel (both waits start before either finishes) and take a total of ~2 seconds to complete execution.</p><pre>Wait 1 started<br>Wait 2 started<br>Wait 1 finished<br>Wait 2 finished<br>Total execution time: 2.000 seconds</pre><p>By putting each of the calls to wait_ms inside of separate threads, we were able to execute those two waits concurrently and the resulting runtime behavior is exactly as described by our graphical dataflow program.</p><p>Success!</p><h3>An Example: Complex Parallel Dataflow</h3><p>Our previous example was a very simple parallel G program, and the resulting Rust translation was similarly simple.</p><p>However, things can get tricky as the dataflow of our programs get more complicated. In the example below, we have two wait_ms in parallel and another wait_ms downstream of it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*RQQJVbiX1Db9q4x81Xfg_A.png" /></figure><p>If we run this G code in LabVIEW, we will see that it takes ~60ms to execute. The first two waits take 50ms and 40ms (50ms-10ms) to execute in parallel (in parallel for a max of 50ms). Then, after they are both finished, we calculate the difference of the timestamps when they finished (i.e. 10ms) and wait for that long. Finally, our program finishes after a total of 60ms from when it started.</p><p>Translating this logic to Rust (using threads), might look like <a href="https://play.integer32.com/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=775dfa2a69104d155a7973f8d4593350">the following example code</a>:</p><pre>use std::thread;<br>use std::time::{Duration, Instant};<br><br>// wait_ms<br>fn wait_ms ( ms_to_sleep: u64 ) -&gt; u64 {<br>    let start = std::time::SystemTime::now();<br>    let since_the_epoch = start<br>        .duration_since(std::time::UNIX_EPOCH)<br>        .expect(&quot;Time went backwards&quot;);<br>    let ms_timer = since_the_epoch.as_secs() * 1000 + since_the_epoch.subsec_nanos() as u64 / 1_000_000;<br>    std::thread::sleep(Duration::from_millis(ms_to_sleep));<br>    ms_timer + ms_to_sleep<br>}<br><br>// wait_in_parallel.vi<br>fn main() {<br><br>    // start the timer for calculating total run time<br>    let start_time = Instant::now();<br><br>    // integer_constant<br>    const WAIT_1: i64 = 50;<br><br>    // integer_constant<br>    const WAIT_2: i64 = 10;<br><br>    // calculate the difference in our wait times<br>    let delta_wait_time: i64 = WAIT_1 - WAIT_2;<br><br>    // start the first wait in a parallel thread<br>    let thread_for_wait_1 = thread::spawn( move || {<br>        wait_ms(WAIT_1 as u64) as i64<br>    });<br><br>    // start the second wait in a parallel thread<br>    let thread_for_wait_2 = thread::spawn( move || {<br>        wait_ms(delta_wait_time as u64) as i64<br>    });<br><br>    // join the two threads, get resulting timestamps, and calculate the difference in execution time<br>    let thread_1_finish_time = thread_for_wait_2.join().expect(&quot;thread failure&quot;);<br>    let thread_2_finish_time = thread_for_wait_1.join().expect(&quot;thread failure&quot;);<br>    let actual_delta_wait_time: i64 = thread_2_finish_time - thread_1_finish_time;<br><br>    // execute the final wait, synchronously (since nothing needs to run in parallel)<br>    wait_ms(actual_delta_wait_time as u64);<br>    <br>    // display the total run time of our program<br>    println!(<br>        &quot;Total execution time: {} milliseconds&quot;,<br>        start_time.elapsed().as_millis()<br>    );<br>    <br>}</pre><p>You can skim the comments in the code (<a href="https://play.integer32.com/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=775dfa2a69104d155a7973f8d4593350">and run it</a>) to see how it works.</p><p>The output should look like the following:</p><pre>Total execution time: 60 milliseconds</pre><p>What’s interesting about this example is that we spawn threads for the two wait_ms nodes that are running in parallel, but we do not use a thread for the last wait_ms, since nothing needs to run in parallel with it.</p><h3>Considerations around Threading</h3><p>This is just one example of the complexity associated with translation compilation of G code to Rust, around</p><ul><li>identifying which nodes should be run in parallel (and which should not) and</li><li>identifying when to join the threads for those nodes</li></ul><p>These identifications and decisions get even more complicated when the code:</p><ul><li>forks the outputs (wires) of the parallel code,</li><li>performs parallel operations on forked outputs of parallel code (requiring us to spawn threads inside of threads), and/or</li><li>passes multiple outputs from parallel sections of code.</li></ul><p>Additionally, we will want to avoid using more threads than we need, since there is overhead associated with spawning and joining threads (based on both the code running in the thread and the data it needs to access or return).</p><p>In fact, we don’t need to spawn a thread for every node. Even nodes that are wired in parallel (in our G program), may not require parallel execution if they take a negligible amount of time to execute (relative to the overhead of spawning and joining a parallel thread).</p><p>And, as we tackle threading for parallel code execution, we’ll also need ways to access shared data in parallel parts of our code (e.g. queues, data value references, etc.).</p><p>Fortunately, threads aren’t the only tool in our toolbox — Rust has many different concurrency mechanisms, such as async/await, channels, mutexes, and much more that can be used in different ways to solve these challenges.</p><p>And, many powerful graph analysis and traversal algorithms exist in the computer science world that can be used to identify attributes of nodes and sub-graphs that can be run in parallel, which will help us (among other things) to determine where we should to spawn and join our threads.</p><p>There are even Graph Neural Networks that can be used to help us classify graphs, nodes, subgraphs, and connections; as well as predict performance challenges and recommend ways of solving them!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*-pCIWG0hd5Yt7arXOg-MOw.jpeg" /><figcaption>Image created with Stable Diffusion</figcaption></figure><p>Rest assured, we’ve got a whole lot more to explore (and we’ll continue to make great progress) next time, as we continue our journey to build a G compiler in G!</p><p>Stay tuned…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d3735e6e197" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>