Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escaping from stage4 sortings for $-variables? #215

Open
tueda opened this issue Jul 7, 2017 · 11 comments
Open

Escaping from stage4 sortings for $-variables? #215

tueda opened this issue Jul 7, 2017 · 11 comments
Labels
question Question about FORM

Comments

@tueda
Copy link
Collaborator

tueda commented Jul 7, 2017

Because of really dangerous memory bugs of #211 for $-variables, I would like to avoid stage4 sortings as much as possible. But I am not sure which parameters are really relevant for that. And it is preferable to save the memory usage. Suppose that I don't have any big local expressions, but have $-variables which become potentially very long polynomials. Does the following setting make sense?

* Adopt the default values.
#:filepatches             256
#:largepatches            256
#:largesize          50000000
#:smallextension     20000000
#:smallsize          10000000
#:sortiosize           100000
#:termsinsmall         100000

* Try to avoid stage4 sortings for $-variables.
* Setting the same values as non-sub parameters may save us from
* the FORM's confusion of buffer sizes(?)
#:subfilepatches          256
#:sublargepatches         256
#:sublargesize       50000000
#:subsmallextension  20000000
#:subsmallsize       10000000
#:subsortiosize        100000
#:subtermsinsmall      100000

* Slightly smaller maxtermsize for each monomial in polynomials.
#:maxtermsize           10000

which consumes 407MB of virtual memory for an empty program. Or better recommendation?

@tueda tueda added the question Question about FORM label Jul 7, 2017
@tueda
Copy link
Collaborator Author

tueda commented Jul 7, 2017

Do other parameters affect on the performance for $-variables? For example, scratchsize?

@vermaseren
Copy link
Owner

vermaseren commented Jul 7, 2017 via email

@jodavies
Copy link
Collaborator

jodavies commented Jul 7, 2017

Can FORM at least print a warning if arguments or dollars hit stage4? (Or terminate completely?)

@tueda
Copy link
Collaborator Author

tueda commented Jul 7, 2017

Thanks. In general, it would be very tricky.

In my specific application, everything is (for now) polynomials and there are no functions. tform doesn't make any sense because all operations have to be done via preprocessor instructions $#x = .... (If I use local expressions instead of $-variables, it will be very awful and slow; I need to selectively update some of many $-variables, like database-operation, for example 5 variables in 10000 variables. I often add/free such variables).

For such a specific situation, is it still risky to set non-sub parameters < sub parameters (to reduce the memory usage), like

#:largesize          500
#:sublargesize       50000000

?

@spj101
Copy link
Contributor

spj101 commented Feb 13, 2018

Sorry to repeat the discussion above but I am wondering: what is the long term plan with Stage4 and $-variables?

Currently I have a similar use case to that described in this question, very many $-variables containing polynomials that can occasionally get quite large (no functions or nesting etc). Clearly I can instead use local expressions but this seems to be a suboptimal use of FORM (it seems most time is spent defining or reading the local expressions).

It seems there are a few options:

  1. Fix Stage4 for $-variables
  2. Allow Stage4 to be disabled for $-variables
  3. Warn or better terminate when Stage4 is entered for $-variables

All of these would be very helpful, it would allow me to speed up our code without worrying that it sometimes gives wrong answers. Thanks!

@vermaseren
Copy link
Owner

vermaseren commented Feb 13, 2018 via email

@spj101
Copy link
Contributor

spj101 commented Feb 13, 2018

Dear @vermaseren,

Thank you for your response. I was not aware of the "holes in the hide file" issue, what you point out may help us.

However, the key reason that I wanted to use $-variables was to avoid the long time it takes to either read in or define local expressions. I think I need my polynomials in separate expressions or $-variables because I would like to pass them to the gcd_ function and I do not want to be subject to the MaxTerm size constraint of function arguments, my polynomials can go beyond such limitations even when adjusting the form.set file accordingly.

I noticed that it seems to take quite some time to define local expressions but $-variables are very fast. Here is a test file that shows roughly what I am doing (assume that the coefficients of A(1),...,A(`t') are polynomials that are usually quite small but occasionally contain many thousands of terms, after I have these local expressions or $-variables I would then pass them to gcd_ and use div_ on them before writing each of them to a file):

#-
Off Statistics;
CF A;

#define t "30000"
#define METHOD1 "1"

L expr =
#do i = 1,`t'
+ `i'*A(`i')
#enddo
;
B+ A;
.sort

#ifdef `METHOD1'
skip;
#do i = 1,`t'
  L a`i' = expr[A(`i')];
#enddo
#endif

#ifdef `METHOD2'
skip;
#do i = 1,`t'
  #$a`i' = expr[A(`i')];
#enddo
#endif

.end

Using METHOD1 I get:

TFORM 4.2.0 (Jan 24 2018, v4.2.0-35-g8b945c1) 64-bits 0 workers  Run: Tue Feb 13 14:43:12 2018
    #-
  16.98 sec + 0.00 sec: 16.98 sec out of 17.12 sec

Using METHOD2:

TFORM 4.2.0 (Jan 24 2018, v4.2.0-35-g8b945c1) 64-bits 0 workers  Run: Tue Feb 13 14:44:46 2018
    #-
  0.21 sec + 0.00 sec: 0.21 sec out of 0.21 sec

Perhaps this is very stupid?

@vermaseren
Copy link
Owner

vermaseren commented Feb 13, 2018 via email

@vermaseren
Copy link
Owner

vermaseren commented Feb 13, 2018 via email

@spj101
Copy link
Contributor

spj101 commented Feb 14, 2018

Dear @vermaseren,

Thank you very much for the changes (a261560, 536e778, 7599180)! They hugely reduce the time for our code to run and have moved the bottleneck elsewhere. I suppose that now I will not rewrite our code to use $-variables, instead I will leave it using expressions.

In your response you mentioned that the Hide trick "creates 30000 modules in each of which it has to run through the list of variables to see that for almost all it has nothing to do, again something of O(30000^2)". Did you mean that in each module it has to run through the list of expressions (not variables)?

Regarding stage4 for dollars, as I will continue to use expressions I am currently not too worried about the memory errors discussed in #211 (comment) . Originally I was concerned that if I rewrite my code to use $-variables it may start to give wrong results just because $-variables accidentally enter stage4. Personally I would rather FORM crash or print a warning than give wrong results. My original question just wondered if there is a way for us to detect that something may have gone wrong due to $-variables entering stage4.

@vermaseren
Copy link
Owner

vermaseren commented Feb 14, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question about FORM
Projects
None yet
Development

No branches or pull requests

4 participants