Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

What is the benefit of USE, ONLY(!)
Hi,

I was asked by a colleague what is the great benefit of the ONLY
qualifier in combination with the USE statement. Well, I think together
with 'renaming' it enables you to do something like

USE crs7_operations, ONLY : matmul7 => matrix_vector_multiplication
USE crs9_operations, ONLY : matmul9 => matrix_vector_multiplication

That is, both modules provide exactly the same methods but differ, e.g.,
in the way of implementation (performance, safety) and/or data types. If
you omit the ONLY statement then you will have to rename ALL methods by
hand. Is this right?

Can you image other situations in which the ONLY qualifier brings
additional advantages.

I need some 'advantages' because my colleague reported that the time for
compiling (ifc,g95) the code drastically increases when USE ... ONLY is
employed.

Thanks in advance,
Matthias Moeller

Report this thread to moderator Post Follow-up to this message
Old Post
Matthias Möller
07-18-06 09:00 AM


Re: What is the benefit of USE, ONLY(!)
> Can you image other situations in which the ONLY qualifier brings
> additional advantages.

It makes clear what parts of a module are actually used (or intended to be
used) and avoids cluttering the name space - i.e., symbols coming into scope
that you don't want to have or even don't know of.

> I need some 'advantages' because my colleague reported that the time for
> compiling (ifc,g95) the code drastically increases when USE ... ONLY is
> employed.

I see no reason - except a decidedly sub-optimal implementation - why that
should be the case. Are the versions of the compilers you are using the
current ones?

Jan

Report this thread to moderator Post Follow-up to this message
Old Post
Jan Vorbrüggen
07-18-06 09:00 AM


Re: What is the benefit of USE, ONLY(!)
Jan Vorbrüggen schrieb: 
>
> It makes clear what parts of a module are actually used (or intended to be
> used) and avoids cluttering the name space - i.e., symbols coming into
> scope
> that you don't want to have or even don't know of.
> 
>
> I see no reason - except a decidedly sub-optimal implementation - why that
> should be the case. Are the versions of the compilers you are using the
> current ones?

This is what my colleague measured

ifort 9.1.038 (32bit):
0'  1''   nur mit use
1'20''  mit use only

ifort 9.1.038 (64bit):
0' 1''  nur mit use
1'13''  mit use only

g95 2006-07-11:
0' 0.3''   nur mit use
0' 6''     mit use only

Matthias

Report this thread to moderator Post Follow-up to this message
Old Post
Matthias Möller
07-18-06 09:00 AM


Re: What is the benefit of USE, ONLY(!)
Matthias Möller wrote:
> Hi,

Hello.

> Can you image other situations in which the ONLY qualifier brings
> additional advantages.

We use it for evolving our software design by looking at the
only patterns.  For example, you may find that only a small
subset of a given module actually gets used repeatedly, and
gives one a candidate for splitting the module or moving
the particular method to another module.

ONLYs are part of our coding standard -- see website below.

Regards,
--
Bil Kleb
http://fun3d.larc.nasa.gov

Report this thread to moderator Post Follow-up to this message
Old Post
Bil Kleb
07-18-06 12:59 PM


Re: What is the benefit of USE, ONLY(!)
Jan Vorbr=FCggen wrote: 
>
> It makes clear what parts of a module are actually used (or intended to be
> used) and avoids cluttering the name space - i.e., symbols coming into sc=
ope
> that you don't want to have or even don't know of.

It can also make it easier to find where a procedure is defined. My
convention is to store module foo_mod in source foo.f90, so if I see
code "use foo_mod, only: bar" I know where to find the version of
procedure "bar" used in the code.


Report this thread to moderator Post Follow-up to this message
Old Post
beliavsky@aol.com
07-18-06 12:59 PM


Re: What is the benefit of USE, ONLY(!)
Matthias M=F6ller wrote:
> USE crs7_operations, ONLY : matmul7 =3D> matrix_vector_multiplication
> USE crs9_operations, ONLY : matmul9 =3D> matrix_vector_multiplication
>
> That is, both modules provide exactly the same methods but differ, e.g.,
> in the way of implementation (performance, safety) and/or data types. If
> you omit the ONLY statement then you will have to rename ALL methods by
> hand. Is this right?

As I remember, you can omit the ONLY and still have a rename-list, say:

USE crs7_operations, matmul7 =3D> matrix_vector_multiplication
USE crs9_operations, matmul9 =3D> matrix_vector_multiplication


Report this thread to moderator Post Follow-up to this message
Old Post
jwm
07-18-06 12:59 PM


Re: What is the benefit of USE, ONLY(!)
jwm schrieb:
> Matthias Möller wrote: 
>
> As I remember, you can omit the ONLY and still have a rename-list, say:
>
>    USE crs7_operations, matmul7 => matrix_vector_multiplication
>    USE crs9_operations, matmul9 => matrix_vector_multiplication
>
Yes, I think so. However, the compiler will complain if modules
crs7_operations and crs9_operations have, say, 200 routines with the
same name which you have to rename by hand.

Matthias

Report this thread to moderator Post Follow-up to this message
Old Post
Matthias Möller
07-18-06 12:59 PM


Re: What is the benefit of USE, ONLY(!)
On Mon, 17 Jul 2006 23:58:53 -0700, Matthias M=F6ller wrote
(in article <e9i0re$i0c$1@nx6.HRZ.Uni-Dortmund.DE> ):

> my colleague reported that the time for
> compiling (ifc,g95) the code drastically increases when USE ... ONLY is
> employed.

That puzzles me. I'd expect that, if anything, the ONLY ought to help
speed compilation by lowering the number of symbols being dealt with
(only likely to be relevant of there are a large number of symbols in
the module). I'd swear I recall suggestions to add ONLY specifiers in
order to speed up compilation in early implementations of DVF.

I'll note (and hope that nobody is reading :-)) that I rarely use ONLY
in my own codes. I know that many people here recommend the use of ONLY
as a good style. Some are quite emphatic about it; others less so.
While I can see the arguments for a style that uses ONLY, I don't
actually do that myself and the arguments haven't convinced me to
change my style. I won't argue that you should avoid ONLY. But I will
claim, in self justification, that it is ok to do so.

No, I won't argue the point. We already had those arguments. As I said,
my position on this is one of accepting that multiple style choices are
reasonable on this matter. I don't have any interest in convincing
others that they must adopt my own style choice in the matter, and I
know that they aren't going to convince me that my choice is horrid (I
already saw the arguments, and they don't convince me). So there seems
no point in debating.

--
Richard Maine                     | Good judgment comes from
experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov            |       -- Mark Twain


Report this thread to moderator Post Follow-up to this message
Old Post
Richard Maine
07-19-06 12:01 AM


Re: What is the benefit of USE, ONLY(!)
Hi,
I find "USE,ONLY" to be *VERY USEFUL* in making the code more readable
and
making it more structured.

By using "use only"  we can define only those
subroutines/functions...etc that are used
from that module.  In a single glance, you can know that out of the 50
or more
subroutines defined in the module, which routines are begin used .

Needless to say, its a great help while you are debugging large codes.

Moreove I feel the use of "ONLY" goes well with the concept of OOPS. If
the
subroutine doesn't need all the routines in the module file.....why
should they be visible to the subroutine.

--Ari



Matthias M=F6ller wrote:
> Hi,
>
> I was asked by a colleague what is the great benefit of the ONLY
> qualifier in combination with the USE statement. Well, I think together
> with 'renaming' it enables you to do something like
>
> USE crs7_operations, ONLY : matmul7 =3D> matrix_vector_multiplication
> USE crs9_operations, ONLY : matmul9 =3D> matrix_vector_multiplication
>
> That is, both modules provide exactly the same methods but differ, e.g.,
> in the way of implementation (performance, safety) and/or data types. If
> you omit the ONLY statement then you will have to rename ALL methods by
> hand. Is this right?
>
> Can you image other situations in which the ONLY qualifier brings
> additional advantages.
>
> I need some 'advantages' because my colleague reported that the time for
> compiling (ifc,g95) the code drastically increases when USE ... ONLY is
> employed.
>=20
> Thanks in advance,
> Matthias Moeller


Report this thread to moderator Post Follow-up to this message
Old Post
Ari
07-19-06 12:01 AM


Re: What is the benefit of USE, ONLY(!)
Richard Maine wrote:
> On Mon, 17 Jul 2006 23:58:53 -0700, Matthias M=F6ller wrote
> (in article <e9i0re$i0c$1@nx6.HRZ.Uni-Dortmund.DE> ):
> 
>
> That puzzles me. I'd expect that, if anything, the ONLY ought to help
> speed compilation by lowering the number of symbols being dealt with
> (only likely to be relevant of there are a large number of symbols in
> the module). I'd swear I recall suggestions to add ONLY specifiers in
> order to speed up compilation in early implementations of DVF.

I can easily imagine why using ONLY might make compilation slower.
When ONLY is not present, the compiler might simply dump all of the
symbols into the symbol table.  With ONLY, the compiler must look up
each symbol in the module file individually.  If the compiler used
linear scan to find the symbols and there were a lot of symbols, the
time to look up the symbols would grow quadratically, while the time
to simply dump the symbols into the symbol table would grow linearly.

Bob Corbett


Report this thread to moderator Post Follow-up to this message
Old Post
robert.corbett@sun.com
07-19-06 12:01 AM


Sponsored Links




Last Thread Next Thread Next
Pages (4): [1] 2 3 4 »
Search this forum -> 
Post New Thread

Fortran archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:05 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.