Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I'm a industrial engeneering student and I have in mind a pretty cool application using ROS. I know that this is not an specific forum about ROS, but as I am programming in C++ and the question is more related to C++ than ROS, I believe that this is a very good place to ask my question.
My problem is that I have a ROS node that must do three different task. These three tasks are equally important so it must be run at the same time. I'm not newer in C++ programming but I've never worked with this kind of problems. I've made a little researh through the internet about
multi-threading and parallel programming and I still don't know the difference between each other.
Which are the differences between multi-threading and parallel programming?
Which might be the best option for the C++ program?
How can I implement these methods on a C++ program?
Is there any guide for people who are getting started with this topic?
Thanks in advance for any help!
Multi-threading describes the concept of having multiple tasks running in parallel for one single program.
Parallel programming is using one parallel concept (might be multi-threading) in your code.
Your questions 2 can not be answered since one uses the other.
A good guide on how to use parallel programming to improve the performance of your code can be found here
"Parallelism" or "parallel computing" refers to any technique that exploits the resources of computing hardware that is capable of doing more things at the same time than a traditional, single-CPU computer can do. It's a broad topic, that covers everything from modern multi-CPU desktop, server, and mobile platforms to GPU programming to esoteric things like systolic array processors and connection machines that have not yet escaped from their university laboratories.
"Multi-threading" is one of several popular techniques that extend the capabilities of a conventional procedural programming language to let us have multiple different activities to happen concurrently within a single process. Parallelism is a subset of concurrency. Any activities that are able to happen concurrently within a single process potentially can happen in parallel if you have the right hardware and operating system.
How can I implement these methods on a C++ program?
Use the threading features in the standard C++ library.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have two functions performing same process but with different techniques and I need to know on a large scale which technique is faster than the other of maybe in the future will be more techniques available. So my question is, how can I do that in c++ specially? Is there a specific method and header to be used to perform this task?
More details:
For example the isLargest() uses three parameters and it has two versions, one uses a nested if technique and the other uses initializers and less if statements. So if I need to know which one is faster, how can I do that?
Try your code in the real world and measure
There is a tool called a profiler that is meant to solve this problem. Broadly speaking, there are two kinds (note: some are a mix between the two):
Sampling profilers.
Instrumenting profilers.
It's worth learning about what each does and their pros/cons, but if you don't know what to use go with a sampling profiler.
There are many sampling profilers, but support depends on your platform. If you're on Windows, Visual Studio comes with a really nice sampling profiler and I recommend you start there!
If you go down this route, it's important to make sure you use your functions as you would "for real" when you're profiling them, as there are many subtle factors that can affect the result.
An alternative
If you don't want to try your code running in a real program, perhaps if you're just trying to understand general characteristics of the function, there are libraries to help you do this such as Google Benchmark.
Benchmarking code can be surprisingly difficult to get right, so I would strongly recommend using existing benchmarking tools where like Google Benchmark wherever possible.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I want to learn how to use Arduino, but it needs some code and there are 2 different options are c and c++. I am confusing that which one to learn "c or c++" at first (I mean for beginner)? are those both same? Actually, it's really really my first time to learn code for Arduino. also, can you tell me where can I learn from? Thank you :)
You mentioned two key words, Beginner and Arduino.
Decision on learning C++ first versus learning C first might
be a matter of opinion for the key word Beginner since many
who start with one can easily adopt for the other.
learning C++ first however has some advantages versus learning C first
for the key word Arduino which I explain.
Arduino programing is mainly targeted toward bare-metal programming, which includes dealing with many environmental options/variables which are usually known at the compiling time.
Programming methodologies which exists in C++ that address processing known factors at compiling time outnumber those of which exist in C by a large number!
Although I must add that these features rarely appear in user programming interface, if any! But still these features would be available for one to implement individually regardless of using Arduino or other bare-metal programming toolkits.
Further more multiplicity of the environmental options/variables demands a well established hierarchical ordering and management which is also more addressed in C++.
You can always try the Arduino website itself as an easy source either for learning or for tutorials/examples!
But to learn the language correctly and completely always keep an eye on authentic sources like cppreference.com and/or cplusplus.com.
Finally you can always ask/lookup your questions and seek guidance here!
Good luck!
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I don't understand why erlang itself is great with concurrency
Is there anyway other language such as C# could be as great as erlang if we do some trick?
Or it is the very specific language feature of erlang that most language don't have?
Could we write C to be like erlang?
One Major property of Erlang is that it was built from the ground up to be a concurrent language. Erlang supports hundreds of thousands of lightweight processes in a single virtual machine. Because Erlang's processes are completely independent of OS processes they are very lightweight, with low overhead per-process. Thus when using Erlang for concurrent oriented programming you get alot of advantages out of the box.
Fast process creation/destruction
Ability to support millions of concurrent processes with largely unchanged characteristics.
Fast asynchronous message passing.
Copying message-passing semantics (share-nothing concurrency).
Process monitoring.
Selective message reception.
This Erlang style concurrency is not impossible to do in C, but it would be hard to do it. Read this blog for more information on Erlang style concurrency
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Dear software engineers:
I am currently teaching a procedural programming unit (using the C language) to a group of Level 3 students in the UK. Here is the Unit 16 Procedural Programming specification document.
For a Distinction (higher level) task, the students must "evaluate the suitability of procedural programs for graphical applications".
It is possible to implement graphical applications using GTK and Qt, but it's also possible to create blinking text on a webpage (just because you can, it doesn't mean you should).
Many games and desktop applications are written in C++, so I suspect that object-oriented code is better for building graphical applications.
To reiterate, I need to "evaluate the suitability of procedural programs for graphical applications".
As a software engineer, how would you answer this question?
[Edit] For what it's worth, I received an excellent response to this question on Quora.
I don't think that object-oriented or procedural programs are "better", any more than writing algorithms in recursive or iterative style are "better".
Lots of wonderful code was written before object-orientation came along.
I think the styles have more to do with managing complexity. Objects are state and behavior together in a single software component. When you system maps well to objects, that style can be a good way to manage complexity. It's worked well for GUI components like windows, buttons, etc.
But it need not be the only way.
I took an intro programming class in C at Stanford University in 1996, when C++ was just starting to take hold and neither Java nor C# existed. They had students doing graphical programming using a very disciplined style that used well designed libraries and rigorous decomposition. I would defy you to find better code.
Even with object oriented programming, normally functions will eventually get called to perform some operations, and the code in those functions would be considered procedural. The main difference is how the code ended up calling those functions along with the parameters used by those functions.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I'm completely new to the Algorithmic Trading domain. I've just completed a course that was Ocaml based, and read about Jane Street. Obviously they are a huge company with a large amount of resources, but is it feasible to use Ocaml for small time algorithmic trading?
I know that probably seems like a stupid question, but (from what i've found) there aren't any trading APIs for Ocaml. This would mean one would have to written from scratch correct?
Any insight would be greatly appreciated guys, like I said I am a complete noob to this domain.
Thanks!
I've recently noticed this package in Opam that could provide a starting point for a trading API:
"IBX is a pure OCaml implementation of the Interactive Brokers Trader Workstation API (TWS API) built on top of Jane Street's Core and Async library."
As for open source trading algorithms in general this project started recently:
http://scarcecapital.com/hft/
I think this question is probably too open-ended for the Stack Overflow environment to be useful to you. Stack Overflow is for when you have a specific problem you're trying to solve.
But being opinionated, I can't help but say that OCaml might be pretty good for algorithmic trading. The strong typing system and immutable data tend to help avoid errors while allowing you to code quickly. This, at least, is what I've found. But you'd need to plug OCaml in to your data sources and your trade execution channel, which would be extra work. Knowing nothing about this area, I don't know if there are libraries for other languages.
Most likely the folks who are actually doing this have an incentive to keep their secrets to themselves. But that would be true regardless of the language.