0

Working (in terms of the run time) with a small program, for example, a c++ program can be easy even I have a few cores on my computer.

#include <bits/stdc++.h> 
using namespace std; 
  
int main() 
{ 
    vector<int> g1; 
  
    for (int i = 1; i <= 10; i++) 
        g1.push_back(i * 10); 
  
  
    for (int i = 1; i <= 10; i++){
        std::cout << g1[i] <<endl;
    }
    return 0; 
}

But, I'm going to work with a program that has a very big vector size [more than a milions]. There are a lot of other processes as well, which makes it harder to finish the program on my computer(MacBook) with small run time. Is there any way that I can do it parallelly (i mean with multiple threads)? This means I run the same program, but the time gets reduced because of the processing in multiple threads. I'm very new to parallel computing, so let me know if the question is not clear enough.

The memory of my computer(macbook): [8GB 1600 MHz DDR3]

Processor: 1.6 GHz Dual-Core Intel Core i5

zero_field
  • 335
  • 1
  • 11
  • Speed, speed, speed, and yet you allow `#include ` slow down your build times by close to an order of magnitude. – user4581301 Sep 17 '20 at 03:22

1 Answers1

1

If you are using the same resources (the vector g1) then unfortunately there will not be significant time saving.

Threads are good to run separately with separated resources asynchronously.

Here is another question that goes more into depth of accessing the STL vector with threads: C++ Access to vector from multiple threads

Matthew
  • 184
  • 6