16

I have a quad processor. I coded something like that in java;

Some.java;

public class Some extends Thread {
    private SharedData sharedVal;
    private String name;

    public Some(SharedData val, String threadName) {
        sharedVal = val;
        name = threadName;
    }

    public void run() {
        int temp;
        while(true) {
            temp = sharedVal.GetValue() + 1;
            sharedVal.SetValue(temp);
        }
    }
}

SharedData.java;

public class SharedData {
    private int value;

    SharedData() {
        value = 0;
    }

    public void SetValue(int d) {
        value = d;
    }

    public int GetValue() {
        return value;
    }
}

Program.java;

public class Program {
    public static void main(String[] args) {
        SharedData test = new SharedData();

        Some t1 = new Some(test, "thread1");
        Some t2 = new Some(test, "thread2");
        Some t3 = new Some(test, "thread3");
        Some t4 = new Some(test, "thread4");

        t1.start();
        t2.start();
        t3.start();
        t4.start();
    }
}

I run program and check processor graphics, each processor part looks working around %90.

My question is; if i can use system resources like this, what is the parallel programming? Am i getting it wrong? I saw an example on c# using processor count, what is the deal with that?

2
  • 1
    Exact duplicate:stackoverflow.com/questions/2287695/… Commented Nov 25, 2011 at 16:03
  • 1
    Mmmm, it may be worthwhile to keep it open, since he is asking about his particular program and not in general... I dunno. Commented Nov 25, 2011 at 16:09

3 Answers 3

25

Parallel programming means using a set of resources to solve some problem in less time by dividing the work. This is the abstract definition and it relies on this part: solve some problem in less time by dividing the work. What you have shown in your code is not parallel programming in the sense that you are not processing data to solve a problem, you are merely calling some methods on multiple threads. While this is "parallel", it is not globally solving a problem.

The issue with the processor load has a connection with parallel programming in the sense that parallel parallel programming aims to keep all computational elements as busy as possible. But simply keeping the CPU busy does not mean that you are doing parallel programming.

Lastly, parallel programming extends well beyond multithreading and can take place among processes running on the same machine or on different machines.

Sign up to request clarification or add additional context in comments.

2 Comments

So using multithreading approach is a part of Parallell Programming, but Parallel Programming is not just using multithreading?
@Burak Karakuş: Yes, multithreading is one way of achieving parallelism, but not the only one. At the same time, not every use of multithreading is parallelism.
14

Parallel programming is the whole concept and multi-threading is one of the specific way to do parallel programming. For example, you can also do parallel programming by MapReduce where each task can run on separate process on different systems. On the other hand, multi-threaded program does not necessarily mean the program is parallel. It is possible to run multi-threaded program on single core machine, in which case the program is not being executed parallely.

Comments

6

Parallel programming is a super set of multi-threading (i.e. multi-threading is a way to parallel program, but there are other ways to write parallel programs, for example multi-process programs).

The main difference between threads and process:

threads in the same process can share memory resources.

Processes must explicitly communicate any information they wish to share to other processes.

1 Comment

Actually Parallelism is a super set of multi-threading, not Parallel programming...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.