The caculation is not fast.


ekeen
03-10-2010, 10:39 AM
I write a c++ program for regression with NR3. But it is not fast. I am not family with c++.

Could you please give me some suggestion?

Thanks.

ekeen
03-10-2010, 05:16 PM
It is 3 times fast than python. Not so good.

davekw7x
03-10-2010, 06:45 PM
...please give me some suggestion...

Suggestion number 1:
Tell us what the heck the program is supposed to do:
What are the inputs? What are the expected outputs? What is the program supposed to try to do with the inputs get the outputs?

Suggestion number 2:
Tell us about the inputs that you gave to the program:
Show us exactly what is in the input files. (Attach them to your post so that we can run the program with exactly the same data you are using.) Since you did not give us a program specification of any kind and you chose not to implement an informative help() function, are you somehow thinking that we can guess what it is that your program needs in order to do something useful?

Suggestion number 3: Tell us about your system:
What is your operating system and platform (CPU version, CPU speed, amount of memory, etc.)? What is your compiler? (Vendor and version)

Suggestion number 4: Tell us exactly how you compiled the program:
If it was from a command line, show us the command line that you used to compile the program.

Suggestion number 5: Tell us exactly how you invoked the program:
If it was from a command line, show us the command line that you used.

Suggestion number 6: Tell us exactly what happened when you ran the program:
Did you get the correct outputs? What kind of speed did you expect? What kind of speed did you observe. Attach your output file to your post.

Suggestion number 7: Instead of surrounding your code by and tags, use and so that your source code will be displayed to us with indentation and spacing preserved and so that we can easily copy/paste your exact code into our text editors.

Suggestion number 8:
If your actual input and output files are too large to post (or you don't want to show us the actual data that you are using), then use reduced input files so that at we can at least try to find out some things about the program's actions.


Without asking specific questions and without giving us enough specific information to start to understand your problem, I can't figure out how to offer any meaningful help. (But maybe that's just me. Others may be able to give better suggestions.)


Regards,

Dave

ekeen
03-11-2010, 07:24 AM
Thanks for you reply.
The program purpose is for mutiple linear regression. It need to calculate the Standard Error of the Regression Coefficient, P-value of Regression Coefficient, F-value, F-test pvalue.

CPU information:
-------------------------------------------------
Model Name: MacBook Pro
Model Identifier: MacBookPro5,5
Processor Name: Intel Core 2 Duo
Processor Speed: 2.53 GHz
Number Of Processors: 1
Total Number Of Cores: 2
L2 Cache: 3 MB
Memory: 8 GB
-------------------------------------------------
g++ --version
i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5646) (dot 1)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-------------------------------------------------
g++ -o test test.c
-------------------------------------------------
./test a bi c 38 7 test.out
-------------------------------------------------

The data and the c program is here:
http://210.77.94.211/userfiles/file/test_tar(1).gz
tar -zxvf test_tar.gz

test.c is the program.
test.out is my output. My calculation is right.

The actual data "a" has 1,500,000 lines. "b" has 534,000 lines. Now I think I should put all the "b" into memory. This should make it more faster.

For the example data:

The calculation time is: 2.438666 seconds.
I expect that 0.01 second for the example data.

Thanks.

davekw7x
03-11-2010, 08:02 AM
...
test.c is the program.No it isn't. After untarring test_tar.gz, I see files test.c, a, bi, c and test.out, but test.c is not a source file. It's a tar archive and when I examine it with

tar tvf test.c


I see

$ tar tvf test.c
-rw-r--r-- jhuang/staff 3120 2010-03-11 02:22:43 a
-rw-r--r-- jhuang/staff 456 2010-03-05 11:04:01 bi
-rw-r--r-- jhuang/staff 76000 2010-03-11 02:23:10 c
-rw-r--r-- jhuang/staff 1446666 2010-03-11 05:18:04 test.out


Regards,

Dave

ekeen
03-11-2010, 08:38 AM
I am sorry. I do it again. Thanks.

http://210.77.94.211/userfiles/file/test_tar(1).gz


I put NR3 in the dir clib.

davekw7x
03-11-2010, 09:05 AM
...I expect that 0.01 second for the example data.
What is the basis of your expectation?


Regards,

Dave

ekeen
03-11-2010, 09:25 AM
It need to calculate the Standard Error of the Regression Coefficient, P-value of Regression Coefficient, F-value, F-test pvalue.

What do you mean "basis"?

Because I have big calculation (1,500,000 * 520,000), I hope I can finished in one day for all.

What is the basis of your expectation?


Regards,

Dave

davekw7x
03-11-2010, 11:11 PM
...What do you mean "basis"?You said that you expect the program to process your sample data in 0.01 seconds. I meant to ask what it is that makes you expect that particular performance?


Regards,

Dave

ekeen
03-12-2010, 03:02 AM
I hope it can be finished in 0.01seconds. Because I have a very large caculation. But if it can be improved, it is OK.

Thanks.

You said that you expect the program to process your sample data in 0.01 seconds. I meant to ask what it is that makes you expect that particular performance?


Regards,

Dave

davekw7x
03-12-2010, 07:57 AM
I hope it can be finished in 0.01seconds....

There is a lot of difference between hoping that it will perform and expecting that it will perform, and I was interested in knowing whether you had any reason to expect it to perform.

Speaking in generalities: If you have already explored the optimization levels of g++, then here are ways that I would suggest that you continue. (For example, I kind of doubt that unrolling the loops in your program will make a huge impact, but it's something to try. Same for -O0, -O1, -O2, etc.)

Here's what I might on my Centos 5.4 Linux workstation:

1. Use a profiler program to try to determine where the program is spending most of its time.


g++ -p -Wall -W test.c -o test
./test a bi c 38 7


There should be a file named "gmon.out" in the current directory.

Then

gprof >gprof.txt


The file "gprof.txt" should show the amount of time spent in each function of your program.

If it turns out that most of the time is spent in a particular NR function (such as gaussj, for example), then you might try to find (or write) a more time-efficient implementation. Still using gaussj as an example, if it turns out that it takes up 10% of the total run time, then consider that no implementation can give more than that amount of improvement for this program, no matter how good it is. (It may or may not be worth pursuing, but certainly won't make the difference between two seconds and 0.01 seconds run time.)

If it turns out that most of the time is spent in one of the functions that you wrote, then try to find (or write) a better way of doing it. Small percentages in improved run times may make this worth while (or maybe not).

2. If you can't come up with improved implementations of the functions that your program uses, then maybe you can investigate the overall flow. Is there a way to reformulate the entire process to arrive at the answers?


Regards,

Dave

ekeen
03-12-2010, 08:17 AM
I runed

g++ -p -Wall -W test.c -o test
./test a bi c 38 7


But I can not find file gmon.out. And I cannot run

gprof >gprof.txt


Thanks.

There is a lot of difference between hoping that it will perform and expecting that it will perform, and I was interested in knowing whether you had any reason to expect it to perform.

Speaking in generalities: If you have already explored the optimization levels of g++, then here are ways that I would suggest that you continue. (For example, I kind of doubt that unrolling the loops in your program will make a huge impact, but it's something to try. Same for -O0, -O1, -O2, etc.)

Here's what I might on my Centos 5.4 Linux workstation:

1. Use a profiler program to try to determine where the program is spending most of its time.


g++ -p -Wall -W test.c -o test
./test a bi c 38 7


There should be a file named "gmon.out" in the current directory.

Then

gprof >gprof.txt


The file "gprof.txt" should show the amount of time spent in each function of your program.

If it turns out that most of the time is spent in a particular NR function (such as gaussj, for example), then you might try to find (or write) a more time-efficient implementation. Still using gaussj as an example, if it turns out that it takes up 10% of the total run time, then consider that no implementation can give more than that amount of improvement for this program, no matter how good it is. (It may or may not be worth pursuing, but certainly won't make the difference between two seconds and 0.01 seconds run time.)

If it turns out that most of the time is spent in one of the functions that you wrote, then try to find (or write) a better way of doing it. Small percentages in improved run times may make this worth while (or maybe not).

2. If you can't come up with improved implementations of the functions that your program uses, then maybe you can investigate the overall flow. Is there a way to reformulate the entire process to arrive at the answers?


Regards,

Dave

davekw7x
03-12-2010, 08:49 AM
...But I can not find file gmon.out. And I cannot run

gprof >gprof.txt
...

I have no access to (or interest in) MacBook (or MacAnything), so I can't help. Maybe you can find a forum specifically geared toward users of your platform. Maybe you can use a search engine to find something about profiling programs that are available for your platform.

Regards,

Dave

ekeen
03-12-2010, 09:23 AM
OK.

I have changed to Debian.

g++ --version
g++ (Debian 4.3.2-1.1) 4.3.2
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

After g++ -p -Wall -W test.c -o test
I do find gmon.out.
But

gprof > gprof.txt
a.out: No such file or directory


I have no access to (or interest in) MacBook (or MacAnything), so I can't help. Maybe you can find a forum specifically geared toward users of your platorm. Maybe you can use a search engine to find something about profiling programs that are available for your platform.

Regards,

Dave

davekw7x
03-12-2010, 04:00 PM
OK.

I have changed to Debian
.
.
.
a.out: No such file or directoryIt's looking for the default compiler output file. My previous suggestion for the gprof command line was incorrect unless the executable was named "a.out". See Footnote.

Did you try to find how gprof works?

Or, more specifically, did you try:

gprof test >gprof.txt


Regards,

Dave

Footnote: I am sorry if my previous suggestions were not completely accurate. I always test the code that I post, but if I say something like "Here's what I might try..." it is intended as a suggestion and an invitation to a learning process. I did not mean to mislead you or to confuse you.

In other words: I did not deliberately post something that will not work. Since my system is different from yours I can't duplicate the exact conditions under which you will be testing, and I wasn't very careful with the gprof command for the particular compiler command line that I gave.

In other words: I made a mistake. Sorry.