• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By jhocking
      My bestselling and highly recommended Unity book has been fully revised! Unity in Action, Second Edition teaches you to write and deploy games with the Unity game development platform. You'll master the Unity toolset from the ground up, adding the skills you need to go from application coder to game developer.

      Foreword by Jesse Schell, author of The Art of Game Design

      Don't take my word for it being good, look at the sky-high ratings on GoodReads.

      You can order the ebook directly from the publisher's site, or order the book on Amazon to get both the physical book and a coupon to download the ebook!
    • By ThunderTwonk
      Hello everyone, I am working on a game idea and since I am still in the process of learning C# and the features available in unity I was hoping some of you might be able to offer me a little insight on things in general for getting started.
      I guess the basic components of what I'm wanting to create would be a Multi-levels management/city builder/rpg.
      The goal is to provide a framework for players to interact with, build in and affect the world both from a 3rd person action RPG as well as a zoomed out 4x style view (This would be something unlocked through gameplay)
      As for my questions go I was wondering if anyone had resources that could help me learn.  I've been on youtube as well as enrolled in an online course for basic unity and C# and will continue those but if anyone has any words of advice, a place that has good information and tutorials etc.
      Thanks for your time.
    • By Cahit Karahan

      Hi, I'm new in this forum. It is honorable to see such communities exist. I would like to share my new game. I did for android with unity. I know the game is a little awkward , but you have to know that this game is from the time when Unity's name is Unity3D  I have made my first game when I was 12. Now I am 22.  I have taken a lot of experience in this process and I can make better games nowadays. I have published this game nowadays but actually this game is very old but also it is very special for me :))
      I have just wanted to retouch and share this game, because it has a very important place for me.

      It's a special free 3D horror adventure action game for the halloween. Fun with scary sound effects and musics, 3D realistic graphics, you will feel the horror in the deep of your heart. Use your reflex. Totally free adventure. Totally scary horror game. 

      Tamarra, she is a beast from our world. She needs to consume souls from innocent people to stay alive. Story begins, the old Elaris tribe had lost their everything because of this beast who lived in the well. Araknas was the most powerful warrior of the tribe. One day, Araknas's mother was killed by the servant beasts of Tamarra. That's how Araknas's journey to the well begins. Tamara's well is guarded by horrible beasts. Araknas has to pass all servant beasts until he reaches Tamarra.

      Even death at the end is worth the revenge. 
      Are you brave enough to jump into Tamarra's well?

      Survive from witch attacks, clown attacks and many scary creature.

      - Realistic 3D graphics.
      - Scary sounds.
      - Scary musics.
      - Best experience with headphones.
      - A demon cage where you can imprison all the demons one by one
      - The witches do not like help, but they love blood stone. Witch store where you can develop your abilities and get new abilities.
      - Countless beasts.
      - At the end of the well there is a hidden surprise for you.

      *We do not recommend this game to people with clown phobia, spider phobia, or panic attacks.*

      **!!!**Note : This game is an early-access game, we are upgrading new features every day, new beasts, new improvements, as an example online 1vs1 fall on the list, so stay on connect and follow Halloween : Horror Well on Google Play.**!!!**

    • By INFRA
      SCAN. DRILL. SURVIVE.   ISOLATED Release in May 1st 2018   https://store.steampowered.com/app/805950/Isolated/   A game by Jérémie Bertrand Music & Sound Design by Pierrick Querolle *** Our solar system has been invaded by strangers. For the purpose of a possible negotiation, a team of astronauts is sent to the moon. Alas, they are shot before even arriving on the scene. Only one astronaut survives the crash and his only goal will be to go home...   GAMEPLAY   Shoot enemy ships to avoid being invaded. Be precise in your movements, because it's better to lose a bit of life at the top than to lose it all at the bottom. Take out your drill to destroy the stones in your path. Validate your identity to cross the different laboratories. Reach the flag before losing your three lives.   And all that... at the same time! Will you be able to go home? If the answer is yes, how long will it take?
    • By BigJiggly
      Hello! So, I've been the leader of BJP for a while now. I'm a bit bored of taking the role I always take, leader. I was hoping someone out there is looking to forge a team maybe and needs a programmer. 
      I have experience mainly in the Unity engine(C# intermediate) and I have a very small amount of knowledge on Shaders, as well as experience on developing games(usually end up stuck in dev hell) and leading experience from my last team which at one point reached 11 people. I personally love the Unity engine and prefer to use it as it's the development environment I'm comfortable with. 
      I have used Unity for over a year and a few months, I'd consider myself an intermediate at the Engine, but to this day Unity still surprises me. 
      I live in the United Kingdom, I find it a bit strange to work with other programmers as the ones I've worked with tend to leave their code heavily unoptimised and I'm a on the go optimise kind of guy, I also like to get things done quickly.
      If you're a new team and need a programmer that has high levels of ambition and strives to maintain the motivation throughout the team, then I'm your guy. I don't care if you're just beginning because I'm all for helping people learn!
      To finish this off: I like to get things done and I like to get them done right the first time, if I fail I will do it again and again, etc, until I loose all motivation. So if you're a modeller or an artist, please don't leave me to do all the modelling/art as well as the programming and sound. I do have experience in all those areas but my main power is in programming and I'd prefer to keep it that way.
      [If this was posted in the wrong forum, sorry, I don't really know the layout of this website yet]
  • Advertisement
  • Advertisement
Sign in to follow this  

Unity Implementing a C# Sorting Network Library

This topic is 505 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

As a game programmer who often prototypes and designs in Unity, I've delved into general C# optimizations for the sake of good practice over the last while. Recently I've been using sorting networks instead of common algorithms for small arrays, and since I coulnd't locate a simple C# library with Bose-Nelson sorts I decided to centralize the logic into one. However, as a beginner programmer I have a few questions regarding it:
Note: I've been generating all networks from http://pages.ripco.net/~jgamble/nw.html
Since the operations are all separated into parallels, is there any more optimal way of structuring the comparisons to make use of multithreading? My understanding is there is a time cost to the hardware switch between threads, and since these are generic low-cost comparisons I figured running the ifs in sequence would be faster anyway. But I'm a multithreading noob so if I'm wrong please correct me.
Sorting Network Optimization:
I've been struggling to find comprehensive information on sorting networks outside of dense university papers, though an old article I encountered seems pretty straightforward and definitive: http://www.drdobbs.com/sorting-networks/184402663
I'm already certain that Bose-Nelson networks are the most optimal option when n <= 8, but wasn't able to locate definitive information on larger sizes (and too lazy to test all the test cases right now). According the article linked above, there still are guaranteed optimal networks for 9 <= n <= 16 using non-BoseNelson algorithms. When Algorithm choice is "Best" on the generator I linked above(http://pages.ripco.net/~jgamble/nw.html) it provides a lighter version of its Bose-Nelson counterpart, which I am assuming is in fact more optimal than traditional algorithms.
I'm a bit less certain in the cases of 17 <= n <= 32. I'm assuming the larger it gets, the less distinct the advantage networks have over traditional algorithms. For that reason, I'm drawing the conclusion that they should only be used when array input order is entirely unknown and thus an appropriate algorithm can't be informedly-chosen. But I'm wondering if they have any use in this case, or if you're generally better off with any sorting algorithm? I'm planning running some test cases, but any expert input to help narrow criterea is welcome.
General Library Structure:
I'm less familiar with building libraries in C# compared to C++, so considering this is a single source file I figured the best method of distribution is just the source. But is it considered good practice to wrap it in a namespace and .dll file etc? It's obviously mostly for personal use, but considering it's an optimal solution for n <= 16 cases and it saves a lot of mindless legwork I figured it may as well be open source.
Apologies for the variety in questions, don't feel obligated to address every single one if you respond.

Share this post

Link to post
Share on other sites

I would think (not know) that, since you would have to synchronise the threads so often - e.g. 4 times in the Sort_8 case, relative to only doing 7 levels of comparison - that the overhead of multithreading would be a net cost more than a benefit. This may change if comparison itself is expensive - e.g. "which of these 2 remote websites has the most images on it?" - and where it's possible to effectively perform comparisons in parallel (which may not be true, even of the previous example, if retrieving the website saturates the single shared network connection).


Probably the simplest way to implement slow operations in parallel that need to synchronise at certain points is to use some sort of 'futures' system (https://msdn.microsoft.com/en-gb/library/ff963556.aspx). You can fire off 4 operations, wait for them all to complete, then move on to the next stage. If the futures are using a thread pool then the threading overheads can be fairly minimal. But again, the overhead of the mere extra code and functions is going to vastly outstrip the benefits if comparisons are cheap (e.g. strings, integers).


I'd be very surprised if this algorithm, multi-threaded or not, outperformed the standard sort algorithms provided by C#. Most standard library sort algorithms are optimised for special cases like small values of N, for example. When they say it's 'optimal' for N<16 that's referring to the number of comparisons, not the actual execution time. In fact I'd expect (again, my personal conjecture) execution on cheap comparisons to be poorer with this system because the code size is larger and there are more conditional statements, both of which are often culprits in high-performance code.


Regarding distribution, I like C# code to be in its own namespace, but beyond that I just like to get the plain source code. A unit test suite is also a good idea if you want to be taken seriously (i.e. executable proof that your sort returns the same results as a standard sort).

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement