[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: trying to optimize my octave program
From: |
Jaroslav Hajek |
Subject: |
Re: trying to optimize my octave program |
Date: |
Fri, 19 Mar 2010 12:14:33 +0100 |
2010/3/18 Tim Rueth <address@hidden>:
> You guys crack me up. I didn't know programmers had such a good sense of
> humor ;-) I said this was my first *Octave* program (I know 750 lines isn't
> really that much, and I did "hello world" a long time ago in Fortran on
> punched cards).
>
> Okay, here's the essence of my top-level script:
>
> global sig long short c_thd r_thd t_thd b_thd; # these are the loop
> iteration vars
> short_min = 5; short_max = 10; short_st = 1;
> long_min = 20; long_max = 40; long_st = 1;
> sig_min = 5; sig_max = 12; sig_st = 1;
> c_thd_min = -3; c_thd_max = -5; c_thd_st = -1;
> r_thd_min = 1; r_thd_max = 3; r_thd_st = 1;
> t_thd_min = 1; t_thd_max = 3; t_thd_st = 1;
> b_thd_min = 0; b_thd_max = -2; b_thd_st = -1;
>
> # Schmoo variables, calling function "analyze" for each data point
> for sig = sig_min : sig_st : sig_max
> for long = long_min : long_st : long_max
> for short = short_min : short_st : short_max
> if short <= long # which it should be, but just checking
> for c_thd = c_thd_min : c_thd_st : c_thd_max
> for r_thd = r_thd_min : r_thd_st : r_thd_max
> for t_thd = t_thd_min : t_thd_st : t_thd_max
> for b_thd = b_thd_min : b_thd_st : b_thd_max
> # Call function analyze, which uses global iteration vars to
> operate on several global vectors
> [c_cntr b_cntr s_cntr avg val actg ddown pk_ddown] =
> analyze(outfile);
> if actg > mx_actg
> mx_short = short;
> mx_long = long;
> mx_sig = sig;
> mx_c_thd = c_thd;
> mx_r_thd = r_thd;
> mx_t_thd = t_thd;
> mx_b_thd = b_thd;
> end;
> end;
> end;
> end;
> end;
> end;
> end;
> end;
> end;
>
> Even though it's aesthetically beautiful, this 7-nested for-loop (evil!)
> executes custom function "analyze" 6*21*8*3*3*3*3 = 81,648 times in this
> case. The iteration vars of the for-loops are global, and therefore are not
> passed to the function as arguments. Inside "analyze" is yet another
> for-loop that runs 4288 iterations on several global vectors that are each
> 4288 x 1 in size. So, the code inside analyze's for-loop gets executed
> 81648*4288 = 350e6 times. Using tic/toc, it takes about 4.5 sec for this
> function to execute. So, 4.5sec/4288 = only 0.001 sec for the code inside
> the loop within "analyze" to run. With these parameters, the whole script
> will run for about 81648*4.5 sec = 4.25 days.
>
> Judd had mentioned that perhaps I'm not doing enough "work" inside the
> inner-most loop. Good point, since it only runs for 0.001 sec. However, I
> don't see a way to get more work done there without moving the next-outer
> for-loop into the function, which is pointless. Even though the inner-most
> loop runs for only 0.001 sec, maybe I just need to focus on trying to
> optimize this down even further. Any reduction * 350e6 could be huge.
> Which brings me to my original question of whether porting "analyze" to C
> and compiling it would help much. Or, from a memory management perspective,
> since I have 11 vectors, each having a 4288x1 size, can/should I convert
> these to int8, single, etc., data types within the vectors if possible? I
> don't see much point here, since it really isn't that much memory savings
> overall. If anyone has any other ideas, let me know. You guys have been
> quite supportive, and I appreciate it.
>
> --Tim
>
I suppose you understand that this is useless unless you show also
what analyze does. Is there a good reason why sig, ong, short etc. are
global variables rather than function parameters?
--
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz
- RE: trying to optimize my octave program, (continued)
- Re: trying to optimize my octave program, Jaroslav Hajek, 2010/03/18
- RE: trying to optimize my octave program, Tim Rueth, 2010/03/18
- Re: trying to optimize my octave program, Judd Storrs, 2010/03/18
- Re: trying to optimize my octave program, Judd Storrs, 2010/03/18
- RE: trying to optimize my octave program, Tim Rueth, 2010/03/19
- Re: trying to optimize my octave program, Judd Storrs, 2010/03/19
- RE: trying to optimize my octave program, Tim Rueth, 2010/03/21
- Re: trying to optimize my octave program, Jaroslav Hajek, 2010/03/19
- Re: trying to optimize my octave program,
Jaroslav Hajek <=
- RE: trying to optimize my octave program, Tim Rueth, 2010/03/19