Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22042

C++ program compiled without problems but doesn't run

$
0
0

There is my code. It does compile without any errors, but it doesn't output anything. When I open program.exe it instantly is closed even if I add "cin.get()" at the end of program. When used in terminal it doesnt cout anything. echo $? returns a false value. I have other similar programs (for testing OpenMP) which are also compiled but works as intended. It must some kind of problem with gcc. Any ideas?

#include <iostream>#include <string>#include <iomanip>#include <omp.h>#include <cstdio> using namespace std;const long num_steps = 300'000'000;int main(int argc, char *argv[]){    cout << setprecision(15) << fixed;    const unsigned num_threads = stoi(argv[1]);    int i, nthreads;    long double pi, sum[num_threads];    long double step = 1.0 / num_steps;    omp_set_num_threads(num_threads);    #pragma omp parallel    {        int i, id, nthrds;        long double x;        id = omp_get_thread_num();        nthrds = omp_get_num_threads();        if (id == 0) nthreads = nthrds;        for (i = id, sum[id] = 0.0; i < num_steps; i += nthrds)        {            x = (i + 0.5) * step;            sum[id] += 4.0 / (1.0 + x * x);        }    }    for (i = 0, pi = 0.0; i < nthreads; ++i) pi += step * sum[i];    cout << "PI = "<< pi << endl;    cout << "PI = "<< "3.14159265358979323846264338327950288419716939937510582097494"<< endl;}

This is my tasks.json:

"version": "2.0.0","tasks": [      {"label": "program01","type": "shell","command": "g++","args": ["-std=c++2a", "-fopenmp", "-Wall", "-o", "program", "main.cpp"],"group": {"kind": "build","isDefault": true        },"problemMatcher": []

Viewing all articles
Browse latest Browse all 22042

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>