Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

USE ONLY question

Intel_C_Intel
員工
1,204 檢視
I been looking at the fortwan_winprint.f90 example and it contains USE ONLY statements.

In my programs I have only used USE statements.

Is the only reason for using the ONLY statement is to stop the clash of subroutine names.
Or does using the ONLY statement speed up compilation time, reduce execution time, or make a smaller executable file?

Thanks,

David
0 積分
9 回應
llynisa
初學者
1,204 檢視
As far as I can remember from the documentation, USE ONLY certainly speeds up compilation. But I use it every time because I find it a very useful way of documenting which routines & constants have been imported from what modules into my source code.

Regards

Alan
Steven_L_Intel1
1,204 檢視
ONLY does speed compilation, especially with very large modules, and I also like the documentation issue.

Steve
Intel_C_Intel
員工
1,204 檢視
I have been going through my code changing USE to USE ONLY.

I find in some places I have to replace USE dfwin with USE dfwin, ONLY : WM_HELP,WM_INITDIALOG, etc.

In other places where WM_HELP & WM_INITDIALOG are used I can remove USE dfwin completely and it compiles OK - I am not using any other USE statements.

Any ideas why this occurs ?

Thanks,
David
Steven_L_Intel1
1,204 檢視
Got IMPLICIT NONE?

The WM_ symbols are defined in DFWINTY, which is implicitly used by all of the various DFWIN modules. If you aren't using IMPLICIT NONE, then the symbols are undeclared variables and get default typing - probably not what you want.

Steve
Intel_C_Intel
員工
1,204 檢視
I haven't used IMPLICIT NONE - but in Project Settings - Compilation Diagnostics, I have ticked undeclared symbols.

I'm still confused.

Dsvid
Steven_L_Intel1
1,204 檢視
How about posting a short example that doesn't use USE statements? I'm interested in seeing it. Do you USE any other modules that USE DFWIN and friends?

Steve
Intel_C_Intel
員工
1,204 檢視
It's my mistake.
I was sometimes using a "USE MyModule" which I hadn't realised included a USE dfwin.

Thanks,
David
Steven_L_Intel1
1,204 檢視
Ok - thought it might be something like that.

I strongly suggest that in your modules you use ONLY clauses, and/or use PRIVATE and then make PUBLIC only the symbols you want to export. ONLY is better than PRIVATE for restricting module namespaces, from the compiler's viewpoint, however. (Both is fine!)

Steve
Intel_C_Intel
員工
1,204 檢視
I replaced my "Use dfwin" with "use dfwin, only:" and found compilation time INCREASED from 10 to 24 minutes.
So I have just gone back to how it was before.

David
回覆