Analyzers
Talk to fellow users of Intel Analyzer tools (Intel VTune™ Profiler, Intel Advisor)
5063 Discussions

How to profile a program needs input from stdin

martinyyyy
Beginner
1,334 Views

Hi,

I want to profile the code like below

 

 

#include <iostream>
using namespace std; 
long n, m, k, r, c, rez, i, f [1001];

int main ()
{
cin >> n >> m >> k;
for (i = 1; i <= m; i ++)
f [i] = 1100000;
for (i = 1; i <= n; i ++) {
cin >> r >> c;
if (f [r] > c) f [r] = c;
}
for (i = 1; i <= m; i ++)
rez = rez + f [i];
if (rez <= k) cout << rez;
else cout << k;
return 0;
}

 

 

After I compiled this code. I got an executable file(Let's say it is called test). I can make this program run by reading input from stdin and then get profile results with vTune.

 

Currently, I have some ideas:

  1. write a script and make it executable, and run the command in my shell: 

 

 

#!/usr/bin/env bash
./test < input.txt
> vtune -collect uarch-exploration -knob pmu-collection-mode=summary ./runme.sh

 

 

 2. I find that this works too(no need to write a separate script file). And the results are similar.

 

 

> vtune -collect uarch-exploration -knob pmu-collection-mode=summary -- ./test  < input.txt

 

 

3. Or what tool should I use to automatically combine code and test files to generate executables for test functions

 

My question is: Is my approach correct? Do the above two methods(1 && 2) have the same effect?

 

What's more, the vTune complains that Application execution time is too short. Metrics data may be unreliable Consider reducing the sampling interval or increasing your application execution time...  Although I set sampling-interval to 0.01, it just didn't work. What can I do to solve this problem? I am afraid of that the result may be inaccurate : (

 

And I found that running the same command at different times to analyze the same program, the results are different, is this reasonable?

 

Sorry for asking so many questions at once, I'm just starting to learn to use vTune

 

Any help would be greatly appreciated : )

0 Kudos
8 Replies
JananiC_Intel
Moderator
1,282 Views

Hi,


Thanks for posting in Intel forum.


The methods which you have followed are correct and regarding your "Application execution time is too short" issue, we observed the same and we are looking into this. We will get back to you soon with an update.


Regards,

Janani Chandran


0 Kudos
martinyyyy
Beginner
1,275 Views

Hey, thanks for your reply  :0

 

These days I was struggling with the  "Application execution time is too short" issue. I got some ideas:

1. Write a script to run ./test < input.txt repeatedly, then use vTune to profile this executable script. I haven't tried this yet. the follow-child or no-follow-child make me confused.

 

2. I try to introduce freopen("file", "r", stdin);  to my code(So I can run this program as long as I wish). The structure of code will be 


int _main() {
    ...
}

int main() {
    while (true) {
        freopen("file", "r", stdin);
        _main();
    }
    return 0;
}

However, I don't know if the freopen("file", "r", stdin); will it affect the results collected by vTune   (Since we need to call this function every time before we run the real target _main(). Or should I do some code transformation so that I just need to call freopen("file", "r", stdin); once (much complex :d)

 

 

0 Kudos
JananiC_Intel
Moderator
1,252 Views

Hi,

 

Thanks for the update.

 

You can avoid "Application execution time is too short" issue with "-allow-multiple-runs" parameter. Use the parameter as below.

vtune -collect uarch-exploration -allow-multiple-runs -- ./test < input.txt

 

You can include -knob in the command. In your previous post we could see "-knob pmu-collection-mode=summary" in your command which is used for an overview of the whole profiling run.

 

Regarding running same command repeatedly giving different results issue, we couldn't reproduce that. It would be great if you share some screenshots so that we will work on that.

 

Refer the below links.

https://www.intel.com/content/www/us/en/develop/documentation/vtune-help/top/command-line-interface/command-line-interface-reference/allow-multiple-runs.html

 

https://www.intel.com/content/www/us/en/develop/documentation/vtune-help/top/analyze-performance/hardware-event-based-sampling-collection/allow-multiple-runs-or-multiplex-events.html

 

https://www.intel.com/content/www/us/en/develop/documentation/vtune-help/top/command-line-interface/running-command-line-analysis/run-general-exploration-analysis-command-line.html

 

https://www.intel.com/content/www/us/en/develop/documentation/vtune-help/top/command-line-interface/command-line-interface-reference/knob.html#knob_PMU-COLLECTION-MODE

 

Hope this answers your query.

 

Regards,

Janani Chandran

 

0 Kudos
martinyyyy
Beginner
1,242 Views

Hi,

 

Good day to you. Thank you for replying to me.

 

I tried -allow-multiple-runs before. However, the application execution time is less than 0.01s(the minimal sampling interval), which makes the vTune restart the application so many times. As a result, the sampling procedure is quite longer than the duration I set. What's more, the result is quite weird(100% Back-end bound)

 

Thanks anyway : )

 

Regards,

Martin

0 Kudos
JananiC_Intel
Moderator
1,220 Views

Hi,


Sorry for the delay.


We are working on this. We will get back to you soon.


Regards,

Janani Chandran


0 Kudos
JananiC_Intel
Moderator
1,191 Views

Hi,


Sorry for the delay. We tried from our end and we could see that the reason behind the low execution time is your code. Since your code takes very small time to execute, metrics data might be unreliable. Try some basic samples like matrix in Vtune and observe the difference.


Hope this helps.


Regards,

Janani Chandran


0 Kudos
martinyyyy
Beginner
1,186 Views

Hi,

 

Thanks for your reply : )

 

The matrix sample works fine. It seems that the very small time to execute issue cannot be resolved for the time being.

 

Thanks anyway : )

 

Regards,

Martin

0 Kudos
JananiC_Intel
Moderator
1,178 Views

Hi,


Thanks for the confirmation. If you need any additional information, please post a new question as this thread will no longer be monitored by Intel


Regards,

Janani Chandran


0 Kudos
Reply