Counting number of threads in clojure - multithreading

I am new to clojure and am performing multi-threading over a large dataset. I need to look at the number of threads running by the program so that I may control the processing of the file. Is there a way to get a graphical representation of the threads and sub-threads that a clojure program is running? If not a graphical representation at least the number of threads being run by the program ?

nevermind i used Thread/activeCount

Related

How can I determine the number of threads Matlab is using?

When I run simply "matlab", maxNumCompThreads returns 4.
When I run "matlab -singleCompThread", maxNumCompThreads returns 1.
However in both instances, ps uH p <PID> | wc -l (which I picked up from another question on SO to determine the number of threads a process is using) returns 35.
What gives? Can somebody explain to me what the 35 represents, and whether or not I can trust maxNumCompThreads as indicating that Matlab is only using one thread?
The number of threads used by MATLAB for computation (maxNumCompThreads) is different from the number of threads MATLAB.exe uses to manage its internal functions: the interpreter, memory manager, command line, who knows what else. If you were writing MATLAB, imagine the number of threads required to manage the various ongoing, independent tasks. Perhaps have a look at the Octave or FreeMat code to get an idea.
Many of the threads you see are used by the JVM that MATLAB launches. You could try the flag "-nojvm" to cut things down further. Obviously, without the JVM, functionality is very limited. "-singleCompThread" limits only the threads used by numeric computation such as MATLAB's intrinsic multithreading as well as threads used by external libraries such as MKL and FFTW.

MultiProgramming , multi-threading, and parallel processing?

I was wondering if there are any slight difference between the definitions of :
multiprogramming
Multithreading
Parallel processing
As I understand that we are using multithreading to achieve multiprogramming . Should the parallel processing the same as multiprogramming ,or it's related to hardware ?
Thanks
Multiprogramming describes that you are able to run multiple programms on a computer at the same time (compared to an old eg DOS system where only one program at a time could run) (also sometimes refered as mutlitasking) -> multiprogramming
Multithreading has to be seen differently on description: -> multithreading
Hardware Multithreading or Architecture: a Processor is able to run multiple Threads in parallel (for real, counterexample: Multiprogramming)
Software Mutlithreading: is when one Process consists of multiple threads those threads are not independent to each other, like processes, especially those threads can have race conditions while working on the same data (-> difference between thread & process )
Parallel processing desribes that there are some ( > 1) CPU's working togehter in any kind. This includes one PC with a multi-core, one server with multiple processors (eg on cards) or even a network of computers -> Parallel processing
The way I've usually seen your 2nd and 3rd terms used:
Parallel processing refers to two or more threads running at the same time, each working with their own data. That is, beyond starting and stopping, there are few, if anym synchronization problems. Multithreading refers to much the same thing, except that the threads share data and must be very careful about this. That is, synchronization is everything.
Proper parallel processing is not much harder than running a single thread. (Most platforms provide all kinds of support to help keep it simple.) Multithreading is a lot of very hard work.

Is it possible to change number of threads during program execution

I'm running few openMP programs. Is it possible to change the number of threads during the program execution. For example, if a program takes 70sec to execute using default number of threads, can I change that number say after 30 sec.
Yes, you can certainly use omp_set_num_threads() to dynamically change the number of threads each time through your (say) iteration loop, and use that plus timing measurements to adaptively choose the number of cores you're using.
You can always create a new thread. A better question you should ask yourself is if multi-threading will benefit you. Remember, just creating new threads will not speed your program up and in many cases, can actually cause more harm than good (race-conditions, deadlocks etc). Make sure you have an understanding of how threading works before jumping into it, which judging by your question, you do not. Threading is a manly task, it puts the hair in your chest, but takes it off of your head!
http://www.inf.uni-konstanz.de/dbis/teaching/ss06/os/ch4.pdf

OpenMP : Is there a way for a thread to terminate all other parallel threads?

I am experimenting with openMP for large data processing and relatively new to it. My input data set is huge and so I divided it into multiple subsets and each thread working on the subset of data. Each data item in the subset is acted up on by the thread. If one of the threads fails during its operation on any dataitem, i would like to terminate other threads and return a failure. Using shared variable is an option, but is there a better way to do the same ?
What do you want to happen if one of your threads chokes on its input ? Do you want to bring the program to a sudden halt ? Or do you want to stop the parallel execution and have a serial part of the program tidy up ?
OpenMP is not really designed for either kind of operation, so you're going to be struggling against it, rather than struggling with it as most beginners do. You certainly could, as you suggest, use shared variables and write your own logic to stop the program or jump to the end of the parallel region if one of the threads fails. But there are no OpenMP intrinsic mechanisms for these operations.
You might want to investigate the new task capabilities of OpenMP 3.0. Using these you can certainly implement a system whereby tasks are dispatched to threads which return either success or failure, and have other tasks which deal with failures.
Finally, one might argue that bad input should not cause a program to crash, but that's another topic.

Parallel coding Vs Multithreading (on single cpu)

can we use interchangeably "Parallel coding" and "Multithreading coding " on single cpu?
i am not much experience in both,
but i want to shift my coding style to any one of the above.
As i found now a days many single thred application are obsolete, which would be better for future software industy as a career prospect?
There is definitely overlap between multithreading and parallel coding/computing, with the main differences in the target processing architecture.
Multithreading has been used to exploit the benefits of concurrency within a single process on a single CPU with shared memory. Running the same programs on a machine with multiple CPUs may result in significant speedup, but is often a bonus rather than intended (until recently). Many OSes have threading models (e.g. pthreads), which benefit from but do not require multiple CPUs.
Multiprocessing is the standard model for parallel programming targeting multiple CPUs, from early SMP machines with many CPUs on a big machine, then to cluster computing across many machines, and now back to many CPUs/cores on a single computer. MPI is a standard that can work across many different architectures.
Of course, one can program a parallel design using threads with language frameworks like OpenMP. I've heard of multicomponent GUIs/applications that rely on separate processing that could theoretically run anywhere. Practically, there's more of the former than the latter.
Probably the main distinction is when the program runs across multiple machines, where it's not practical to use multithreading, and existing applications that share memory will not work.
Parallel coding is the concept of executing multiple actions in parallel(Same time).
Multi-threaded Programming on a Single Processor
Multi-threading on a single processor gives the illusion of running in parallel. Behind the scenes, the processor is switching between threads depending on how threads have been prioritized.
Multi-threaded Programming on Multiple Processors
Multi-threading on multiple processor cores is truly parallel. Each microprocessor is running a single thread. Consequently, there are multiple parallel, concurrent tasks happening at once.
The question is a bit confusing as you can perform parallel operations in multiple threads, but all multi-thread applications are not using parallel computing.
In parallel code, you typically have many "workers" that consume a set of data to return results asynchronously. But multithread is used in a broader scope, like GUI, blocking I/O and networking.
Being on a single or many CPU does not change much, as the management depends on how your OS can handle threads and processes.
Multithreading will be useful everywhere, parallel is not everyday computing paradigm, so it might be a "niche" in a career prospect.
Some demos I saw in .NET 4.0, the Parallel code changes seem easier then doing threads. There is new syntax for "For Loops" and other things to support parallel processing. So there is a difference.
I think in the future you will do both, but I think the Parallel support will be better and easier. You still need threads for background operations and other things.
The fact is that you cannot achieve "real" parallelism on a single CPU. There are several libraries (such as C's MPI) that help a little bit on this area. But the concept of paralellism it's not that used among developers working on popular solutions.
Multithreading is common these days thanks to the introduction of multiple cores on a single CPU, it's easy and almost transparent to implement in every language thanks to thread libs and threadsafe types, methods, classes and so on. This way you can simulate paralellism.
Anyway, if you're starting with this, start by reading about concurrency and threading topics. And of course, threads + parallelism work good together.
I'm not sure about what do you think "Parallel coding" is but Parallel coding as I understand it refers to producing code which is executed in parallel by the CPU, and therefore Multithreaded code falls inside that description.
In that way, obviously you can use them interchangeably (as one falls inside the other).
Nonetheless I'll suggest you take it slowly and start learning from the basics. Understand WHY multithreading is becoming important, what's the difference between processes, threads and fibers, how do you synchronize either of them and so on.
Keep in mind that parallel coding, as you call it, is quite complex, specially compared to sequential coding so be prepared. Also don't just rush into it. Just because you use 3 threads instead of one won't make your program faster, it can even make it slower. You need to understand the hows and the whys. Not every thing can be made parallel and not everthing that can, should.
in simple Language
multithreading is available in the CPu by itself and
parallel programming is an explicit task either done by the compiler or my constructs written by programmers "#pragma"

Resources