| Most elegant way to read to allocatable array? |
|
 |
Index ‹ fortran
|
- Previous
- 2
- What is run-time error F6501?i had compile and build my program and got no error...when i try to execute
file.exe i find out that the run-time error F6501 occur...im using Window
Xp....im using Microsoft Fortran Powerstation 4.0..then i find out that
the requirement for the program is for window NT and 95...is it error
F6501 is because the fortran did not support Window Xp?..or is that any
other reason...?...need help...tq
p/s: any idea what type of fortran version that support Window Xp?
- 2
- is it possible to pass C++ vectors to fortran subroutinesCraig Powers wrote:
(snip)
>> compute_(&a,&b,&c,&sz);
> Fortran will not know what to do with the address of a std::vector.
> The right way to do this is,
> compute_(&a[0],&b[0],&c[0],&sz);
> It is either guaranteed by the C++ standard, or will be soon, that the
> storage is contiguous (and, as a practical matter, all implementations
> follow this), so that you can pass the address of the first element to
> anything expecting a contiguous sequence.
Do you just mean that the actual data is contiguous, or that the
whole <vector> is? Specifically, is the bounds and length information
contiguous (with possible padding) with the data?
I can see doing it both ways.
-- glen
- 3
- M`I'5-Pe rsecution - Four Year s of MI 5 Perse cution Po sts on I nternet Ne wsgroups
Four Years of "MI5 Persecution" Posts on. Internet Newsgroups
For. approximately the first three years of the MI5 persecution, from June
1990 until late 1992, I kept as quiet as possible, in the. hope that by not
reacting, MI5s interest in me would. decrease and they would simply go away
of their own. accord. This is the sort of behaviour some people employ
against bullies; if the bullies arent getting a reaction, then they. might
simply. go away and victimize someone else.
Unfortunately, this. tactic didnt work. The quieter I became, the more
shrill and hysterical the noise. from the Security Service operatives. For
about two. years I didnt watch TV news at all. Yet this only heightened
their obsessed fixation; they continued to follow. me wherever I went, they
continued to. induce harassment at work by managers and fellow workers, and
they continued to encourage me to commit. suicide. They seemed to regard my
refusal to react as a crime. which they would have to "put right" by ever
more. extreme forms of abuse.
Finally, in 1995, I changed tactics radically. Since late 1994. I had had
accounts with internet providers in Ontario, Canada.. I discovered the
cornucopia of internet newsgroups, on every topic from. consumer
electronics,. to politics and legal topics, and I discovered online
services such as Compuserve and. AOL. In May 1995, I made the first posting
to the conspiracy newsgroup, on the subject. of "BBCs Hidden Shame".
BBC's Hidden. Shame
The internet. newsgroup discussion, which has now reached its fourth
anniversary,. started with an article in alt.conspiracy, which I reproduce
here.
Date: Thu May 4. 18:27:24 1995
Newsgroups:. alt.conspiracy
Subject: BBC's. Hidden Shame
Remember the. two-way televisions in George Orwell's 1984? The ones which watched you
back? Which you could never get rid of, only the sound could be. turned down?
Well the country which brought Orwell into the world has. made his nightmare follow into
the world after him. Since. 1990 the British have been waging war against one of their
own citizens using surveillance. to invade privacy and a campaign of abuse in the
transmitted media in their efforts to humiliate. their "victim".
And the most remarkable thing about. it is that what they do is not even illegal - the
UK has no laws to protect the privacy of. its citizens, nor does it proscribe harassment
or abuse except in the case. of racial abuse.
A lot of people in. England know this to be going on, yet so far they have maintained
perfect "omerta"; not a sound, not a squeak has. escaped into the English press, and for
all the covert harassment absolutely nothing has come out. into the public domain.
Have the British gone mad? I think we should be. told
At this point, I did. not name MI5 as my persecutors. I was still unsure
that they were the. ones responsible for the "psychological terrorism". In
followup posts however. I did name them; and the persecutors have never
denied the. claim; so I think my guess is valid. (The Security Service
Tribunal in 1997. have said "no determination in your favour was made", but
it is a well established fact that MI5 lies routinely to the. Tribunal
which has. never found in favour of a plaintiff, so no conclusions can be
drawn from. this.)
This first post was made to alt.conspiracy,. but further posts were made to
the UK-local. newsgroups, in particular uk.misc but also uk.legal and
uk.politics (which is. now called uk.politics.misc). Some time ago I tried
to take the. battle to the Compuserve forums, UKPOLITICS (which is now
called UKCURRENT - current affairs), but my. articles were censored by the
forum. operators. Such censorship is impossible on the internet newsgroups.
Police Refuse to. Act
I have complained several times to the Metropolitan Police, who. have each
time. refused to help.
From: Green. <email***@***.com>
Newsgroups:. uk.misc,uk.politics,alt.politics.british,soc.culture.british
Subject: Re:. MI5 Persecution: Why Aren't the British Police Doing Their
Job?
Reply-To:. email***@***.com
Date: Sun Apr 7 21:13:30. 1996
In. article <email***@***.com>
. email***@***.com "Mike Corley" writes:
>Last Easter (1995) I went into the. local police station in London and spoke to
>an officer about the harassment against me. But. I couldn't provide tangible
>evidence;. what people said, in many cases years ago, is beyond proof, and
>without something to support my statements. I cannot expect a police officer to
>take the. complaint seriously.
This in itself dos. not suggest that the police have it in for you. The old bill
operates on extremely tight spending limits forced on them. by that pillock Michael
Howard, and without. evidence, they often have higher priorities than chasing something
that cannot go. to court.
I doubt. that the police are actually being leant on, but they probably realise that if
they looked into this, they would be leant on hard. The met always. stays away from
anything that. looks like it has Defence, Security or secret service interest already,
because they realise that they are below. these government agencies in the general
pecking. order.
If I walked into my local nick and complained. that MI5 were snooping on me, they would
show me the door without even looking at my evidence,. because that bored desk seargant
with only five years. to go before he retires doesn't want to start fucking about with
somebody who has incurred the wrath of Stella Rimington. He would rather deal with. the
lost dogs and driving licence producers,. eat his cheese and pickle sandwiches and piss
off home at the end of. his shift than have some high ranking spook having a go at his
boss and getting. him a bollocking.
In short, you have earned much sympathy but little surprise. Just. remember that saying
about the enemy of. your enemies.
Most recently, I wrote in. March 1999 to Charing Cross Police Station
CID. They did not acknowledge or reply to my letter.. When I phoned them
up, the detective Id written to treated me to a. sadly not unusual display
of. police bigotry, with an uneducated rant about "your paranoid rubbish".
It would be nice to think that such uneducated bigotry. is something other
than wholly typical of police. behaviour, but unfortunately that is an
illusion that is rapidly. dispelled.
Uncorruptible Jon Snow of Channel. Four News
From previous articles the reader will. know what I think Jon Snow has
recently been watching me while he reads Channel. Four News in the
evening. Recently I digitized a few moments. of one such broadcast, where
his face twists into a smile, without there being. anything in the news
broadcast to cause. merriment. Here is a usenet post from some time ago on
MI5s "bought and paid for" tools in. the so-called "free" press.
Peter Harding (email***@***.com). wrote:
: I was at speakers'. corner on Sunday. There was one chap who was bellowing
: about something or other, I don't know. what, but one thing he said to
: someone caught. my ear:
: "BBC, MI5, same. thing."
Can't. disagree with that sentiment.
Wasn't it documented that MI5 sometimes "bought" journalists. and broadcasters?
I remember reading a report by some jouralist who had. been offered an extra
tax-free income by MI5 to become their covert. mouthpiece, and had refused.
.............................................................................
> : >mouthpiece, and. had refused.
>. :
> : It was Jon Snow of. Channel 4.
>
> Was it reported in any of the. papers?
It has been reported several times. The most recent. was in Private Eye,
a few months back. As I recall they also wanted. information from him;
journalists would be a natural choice. for members of the Security Service
and the Secret Intelligence Service for. information sources.
> It might be interesting to see what he had. to say regarding their
> attempt. to recruit him.
He was. most concerned that many others would have accepted such an
offer. However, we can probably make an educated. guess as to some of
those who accepted:. Nigel West (Rupert Allason, MP) and Chapman Pincher
would come near to the top. of the list.
Corrupt Security Service agents. steal millions from taxpayers
Money is of course a factor in the. grand equation which is the MI5
persecution. It costs money for the Security Service to. "buy" people in
the media etc. But that is only a. small part of their expenditure of
taxpayers resources. Most of. the expenditure is directly on the salaries
if the agents involved; and in this post I. put forward the theory that MI5
are trying to draw out their involvement for as long. as possible, very
cynically, to maximise their. income and line their own pockets.
At each stage they have tried to pretend that I am something out. of the ordinary.
Either I was very stupid ("he's an idiot") or very clever ("he's like. a genius").
Either I. was a threat to Western civilization (Levin once referred to me as the next
Hitler) or I. was completely defenceless ("a soft toy").
Now, it should be obvious to any person with common-sense that I. am not out of the
ordinary in any way. I have an IQ which is average for the Web,. I am racially white
European, and. there are plenty of other people with schizophrenia or epilepsy out there
who. haven't been targeted for MI5 attention, so why me?
I think the answer is that the MI5. agents who harass me have cynically exploited the
situation. by painting me as extraordinary in order to assure themselves of well-paid
employment funded by the ordinary British. taxpayer. To put it bluntly, they are
stealing millions. of pounds from the taxpayer to feed their own pockets.
This assertion is supported by the. observation that it's the same agents who are doing
the harassment. Six months ago in a local hospital I was harassed by. someone whose face
I had seen (he had stared straight at me aggressively,. at the time I just thought it
was some nutter but it. turns out he was one of "them") aboard a KLM flight a couple of
years ago. It's presumably been the same. people most of the time. I've seen the way
contractors act when they don't want their positions terminated.. Would these agents
really want to lose their well-paid. employment harassing me? Presumably they are
promising their bosses a "breakthrough" (ie my. demise) real-soon-now and have been for
the last seven years, while all the while these MI5 agents skim. millions
off. the taxpayer.
I wouldn't mind a job. like that. Perhaps if I persecute myself a little bit, like
standing in front of a mirror and shouting mindless obscenities, do you reckon. I'd get
a slice of the caky. Service Tribunal. This year Nick Brooks, current
Tribunal Secretary, confirmed to me. that he could not think of a single
case where the Tribunal. had found in favour of a complainant. Here is my
usenet. post from two years ago.
Subject: MI5: "It wasn't. us"
Newsgroups:. uk.misc,uk.legal
Organization: Toronto. Free-Net
"The Security Service Tribunal have now investigated your complaint. and have
asked me to inform. you that no determination in your favour has been made on
your. complaint."
Signed ER. Wilson, Tribunal Secretary
Well that's a relief then. All that spamming for nothing eh.. Gaw blimey, if
they say they're not doing it then it can't be them, can. it?
In a recent letter to Mr Brooks I expressed the opinion that. the Tribunal
were unable to fulfil their responsibilities. in the face of MI5
falsehoods.. Nevertheless, I do intend to make another complaint to the
Tribunal in the near. future, despite the Tribunal appearing to be a
toothless. watchdog.
Discrimination against. a Unit Minority
MI5 have been very clear in their. instructions as to what I should
do. They have openly shouted at me the word "suicide", and also. from the
other abuse it is clear that they want my. existence terminated.
This point is covered in more. detail in a previous article. The following
post. describes the xenophobic nature of MI5s campaign against me. They
have refined their bigotry down to a. unit minority, yet they make use of
the discrimination against the. mentally ill which is a feature of current
British. society.
Subject: Re:. MI5 says "Kill Yourself"
Newsgroups:. uk.misc,uk.legal,uk.politics.misc,uk.media
References:. <email***@***.com>
<53eeev$email***@***.com>
Organization: Toronto. Free-Net
Distribution:
email***@***.com. (Iain L M Hotchkies) wrote:
>Indeed. If you've ever had a 'conversation'. with someone suffering
>from. florid schizophrenia, you'll know how difficult it can be to
>'argue' with. them.
I don't have florid symptoms. But I'm in a difficult situation,. because those
people who don't know, aren't going to believe, and those. who do, they just go
along with the crowd. It's never a good idea to go against the. grain, and the
grain here is defined by interests. in the establishment and the media. Even
people who could say. out loud what was happening won't, because then there's a
risk that they'll be seen as traitors and. ostracised.
Usually. this type of 'hidden abuse' is racial and targetted at a racial
minority within a country. You keep the minorities out of. the good jobs, but
you don't admit. discrimination exists. It happens everywhere, not just in
Britain. The persecution that is going on now is in reality a. refined form of
racism. Instead of. "nigger" it's "nutter", and abusing the mentally ill is
still socially acceptable today.. In 50 years it might not be, but today there
isn't any. social or legal sanction against it.
So really they've refined racial harassment down to. a minority of one. The
words may be different,. but the methods are the same.
3401
- 4
- How to improve the speed of my program.Dear All friends,
I have finished a long Fortran program in console mode for my PhD project. However,
the program run very slow because inside it I should perfrom numerical
interation along a complex contour.
Do 10 I=1,100
aa{i)=Numerical_Integration(x,y,z,i)
10 Continue
I am thinking of improving the speed of above codes, say using multithread
feature of Compaq visual fortran. Can I do something like following.
Thread 1: Do 10 I=1,10
Do 10 I=1,10
aa{i)=Numerical_Integration(x,y,z,i)
10 Continue
Thread 2: Do 20 I=10,20
aa{i)=Numerical_Integration(x,y,z,i)
20 Continue
......
so like this I split the program into 10 thread and run them together. I think
the program should perform much better than my current single thread version.
Is what I am thinking correct? If so, how can I do this and hope that you can
leave me some examples? thanks very much.
Best Rgds,
- 4
- fortran give false value !!!hi every body .
i am an streng problem with fortran 90 .
i have a function , i know the value of function for x=1 , y=0 , d=2
it must be zero .
in matlab , this function for this values return zero , but in fortran
give (-1)!!!!!!!
function=(3/(x^2+y^2)^2*x-4*x^3/(x^2+y^2)^3+1/((x-d)^2+y^2)^2*(2*x-2*d)-2*(1/2*x-1/2*d)/((x-d)^2+y^2)^3*(2*x-2*d)^2+2*(1/2*x-1/2*d)/((x-d)^2+y^2)^2)*(1-1/2/(x^2+y^2)+y^2/(x^2+y^2)^2-1/2/((x-d)^2+y^2)+y^2/((x-d)^2+y^2)^2)+(1-1/2/(x^2+y^2)+x^2/(x^2+y^2)^2-1/2/((x-d)^2+y^2)+(1/2*x-1/2*d)/((x-d)^2+y^2)^2*(2*x-2*d))*(1/(x^2+y^2)^2*x-4*y^2/(x^2+y^2)^3*x+1/2/((x-d)^2+y^2)^2*(2*x-2*d)-2*y^2/((x-d)^2+y^2)^3*(2*x-2*d))-(1/(x^2+y^2)^2*y-4*x^2/(x^2+y^2)^3*y+1/((x-d)^2+y^2)^2*y-4*(1/2*x-1/2*d)/((x-d)^2+y^2)^3*y*(2*x-2*d))*(x/(x^2+y^2)^2*y+1/2*y/((x-d)^2+y^2)^2*(2*x-2*d))-(x/(x^2+y^2)^2*y+2*(1/2*x-1/2*d)/((x-d)^2+y^2)^2*y)*(1/(x^2+y^2)^2*y-4*x^2/(x^2+y^2)^3*y-y/((x-d)^2+y^2)^3*(2*x-2*d)^2+1/((x-d)^2+y^2)^2*y)
i can't understand where the error is . ( i replace ^ with ** in
fortran , program has no logical error ,and compiles ,but the returned
value is false !!!!!!)
can anyone help me ?
best,nakisa
- 4
- equivalencing allocatable arraysIs it legal to equivalence allocatable arrays? If so, then when the
first array gets allocated, does the second one automatically get
allocated as well?
- 9
- Problem linking Intel Math Kernel LibraryI'm not a particularly savy linux user, but I have managed to install
Intel Fortran, C++, and MKL on my PC's linux partition (Ubuntu 6.0.6).
Now I want to use the free Fortran package PROPACK to do singular value
decompositions of large sparse matrices. Using the make file included
with PROPACK works fine until it tries to link and optimize the example
programs included with the package:
make[2]: Entering directory `/home/ron/Desktop/PROPACK/double/Examples'
ifort -cm -w95 -assume buffered_io -vec_report0 -O3 -ipo -xN -Vaxlib
-o example.LINUX_ICC_IA32.x example.o matvec.o
-L/opt/intel/mkl/8.1.1/lib/32 -L.. -L. ../libdpropack_LINUX_ICC_IA32.a
../libdlapack_util_LINUX_ICC_IA32.a -lmkl_p4 -lguide
../libdlapack_util_LINUX_ICC_IA32.a
IPO: performing multi-file optimizations
IPO: generating object file /tmp/ipo_ifort4usUFH.o
/opt/intel/mkl/8.1.1/lib/32/libmkl_p4.so: undefined reference to
`vsCos'
/opt/intel/mkl/8.1.1/lib/32/libmkl_p4.so: undefined reference to
`vslDeleteStream'
/opt/intel/mkl/8.1.1/lib/32/libmkl_p4.so: undefined reference to
`vdSin'
/opt/intel/mkl/8.1.1/lib/32/libmkl_p4.so: undefined reference to
`viRngUniformBits'
/opt/intel/mkl/8.1.1/lib/32/libmkl_p4.so: undefined reference to
`vslNewStream'
/opt/intel/mkl/8.1.1/lib/32/libmkl_p4.so: undefined reference to
`vdCos'
/opt/intel/mkl/8.1.1/lib/32/libmkl_p4.so: undefined reference to
`vsSin'
make[2]: *** [example.LINUX_ICC_IA32.x] Error 1
make[2]: Leaving directory `/home/ron/Desktop/PROPACK/double/Examples'
I figured out that the above undefined references are functions from
the Intel VML/VSL package, so I added -lmkl_vml_p4 after -lmkl_p4 in
the above ifort line, but it still generates the same errors.
Any insights or suggestions?
Thanks,
Ron
- 11
- How to generate dynamic formatsI usually define a global variable prescribing the format for printing a
real variable. Something like
character(len=*) :: rform='(F15.5)'
and then use rform whenever I have to print a real variable. The
advantage is that all the variables in the program are printed uniformly
and I have to change at just one place to change the output. This method
works fine as long as I have to print just one real variable per write
statement.
But how can I elegantly extend this when printing more than one real
variable? I tried
write(*, 2rform) temp1, temp2
But as expected, it did not work since 2rform is a valid string.
May be a program would clearly explain my situation
program dynamic_formats
implicit none
character(len=*) :: rform='(F15.5)'
real :: temp1=5.0, temp2=6.0, temp3=7.0
write(*, rform) temp1
! This prints temp1, temp2 on separate lines
write(*, rform//rform) temp1, temp2
! What is the easiest way to do something like the following.
! write(*, 2rform) temp1, temp2
! write(*, 3rform) temp1, temp2, temp3
end program dynamic_formats
Thanks in advance
raju
- 12
- Question about elemental functionsHello,
I'm testing m_strings.f95 from "http://nn-online.org/code/strings/". It
compiles fine using IFORT 9.1 and CVF 6.6b. However on SGI, compiler
complains about the following (and many more similar) elemental
functions:
elemental function len_s(s)
implicit none
type(string), intent(in) :: s
integer :: len_s
len_s = s%len
end function len_s
where string type is defined in the same module as:
type string
private
integer :: len = 0
integer :: size = 0
character, pointer :: chars(:) => null()
end type string
Compiler complains on the ONLY executable line "len_s = s%len". Error
message says:
"S" must not be defined inside of a elemental subprogram. It is in
common, a dummy argument or host or use associated.
Huh ?!?
Can someone please decipher this error message, and possibly suggest a
work around?
Thanks.
- 13
- Undefined symbol - lapack math libsHi,
I have an application which uses math/matrix solving lib like blas,
lapack. When i build the binary using forte7 , it passes. But when i
change the compiler to forte8, i get 2 undefined symbol errors :
Undefined first referenced
symbol in file
zgetrf_
../../output/SunOS_32/lib/forte8/opt/libsmx.a(smxlapack.o)
zgetrs_
../../output/SunOS_32/lib/forte8/opt/libsmx.a(smxlapack.o)
Any clue as what could be the reason ? Any options i need to provide
to
the linker or the library which contains these functions?
Regards, ~Pervinder
- 14
- Segmentation FaultMark Westwood wrote:
> What might the compiler do / not do with no flags set that is different
> from the situation where the -g or -Mbounds flag is set ? The Portland
> Group support team weren't very forthcoming with a hard answer to this
> question.
This behaviour of Portland sounds familar to me.
But generally spoken, changing flags will change the layout of the
generated code, and a false write can have different consequences. So,
it is not necessarily a compiler bug. A smart boundschecker might help here.
To simplify debugging with respect to MPI, you can link this against an
MPICH1 library which is configured for the ch_shmem (shared memory
device). This way, you can easily launch the executable like "solver -np 1".
--
Joachim - reply to joachim at domain ccrl-nece dot de
Opinion expressed is personal and does not constitute
an opinion or statement of NEC Laboratories.
- 15
- How can I read a file which size > 2G?Does anyboby know how to read a file with size > 2G using an EXE file
compiled by g77.
I know PGI fortran can do it? How about other fortran compiler?
Thx.
- 16
- September 1996?I am now looking at the Forum list and the LATEST message shown is
from 24 September 1996.
Something just happened?
I mean, something serious, but like different form 9 September 1945?
- 16
- Need some help in fixing a fileHi
I just downloaded an archive of old DEC VMS fortran routines that I am
planning to use for vt100 graphics o/p. The problem is that the file is
messed up - all CR/LF's have been replaced with ^M's :
TERMINAL^MC^MC FOR TEXT WRITING^MC NOTE <CR> AT END OF TEXT LINE SETS
MODE BACK TO WHITE!^MC HENCE MUST RESET BLACK MODE BEFORE EACH
WRITE^MC^MC^MC THIS ROUTINE ERASES #NL LINES STARTING AT Y POSTION
=180^MC^M CALL PLOT(0.,180.,0)^M CALL DELAY(5)^M DO 1 I=1,NL^M CALL
TOUT(27)^M CALL TOUT(127)^M WRITE(7,2)^M CALL DELAY(5)^M CALL
TOUT(27)^M CALL TOUT(127)^M WRITE(7,3)^M CALL DELAY(5)^M CALL
TOUT(27)^M CALL TOUT(127)^M WRITE(7,4)^M CALL DELAY(5)^M CALL
TOUT(27)^M CALL TOUT(127)^M WRITE(7,5)^M CALL DELAY(5)^M2
FORMAT(' ')^M3 FORMAT(1H+,72('#'))^M4 FORMAT(1H+,72('H'))^M5
FORMAT(1H+,72('I'))^M1 CONTINUE^M CALL TOUT(27) !SET DATA MODE TO
WHITE^M CALL TOUT(97)^M CALL
I know that the unix command tr can help me here. Could someone suggest how
do I go about fixing it ?
Thanks,
MS
- 16
- More object-oriented programming, was Re: ... comment on FortressRichard Maine wrote:
> I have related before the tale of how I "saw the light" and realized
> that OO could have a place in Fortran, and specifically in my Fortran
> codes. I had read material and seen presentations about OO before, but
> it just didn't seem to "click" with me. I couldn't see why I would care
> about any of that stuff, which seemed rather academic and disconnected
> from things that I did with Fortran. But then John Cuthbertson gave a
> presentation at one of the committee meetings. His presentation put it
> in Fortran terms and showed how some of the ideas fit. Suddenly, I
> realized that this did make sense to me, and indeed that I had been
> doing things along that general line for... well... a long time. I just
> hadn't known the fancy terms for what I was doing. I also hadn't
> realized that the language could actually help instead of get in the way
> - as it so often had; I had formerly done many "cheats/tricks" to get
> around places where the language seemed to be "fighting" me.
You've mentioned this several times before, and it just occurred to me
to ask: Do you know if any of the materials from that presentation (or
related things) are available online? It sounds like something I'd find
useful.
- Brooks
--
The "bmoses-nospam" address is valid; no unmunging needed.
|
| Author |
Message |
James Giles

|
Posted: 2007-1-22 10:50:36 |
Top |
fortran, Most elegant way to read to allocatable array?
Gary Scott wrote:
...
> My assumption was that once you query it, it is a reserved (negative
> or whatever) number that can't be used anywhere else regardless of
> whether it actuall gets connected or not. If a second inquire
> occurs, it must return a different number.
Most implementations have a limited number of different unit
numbers that are legal. A program that opens a lot of files
must usually reuse some of the numbers. You can't simultaneously
open more than a certain number on most operating systems
snyway.
--
J. Giles
"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare
|
| |
|
| |
 |
James Giles

|
Posted: 2007-1-22 10:50:00 |
Top |
fortran >> Most elegant way to read to allocatable array?
Gary Scott wrote:
...
> My assumption was that once you query it, it is a reserved (negative
> or whatever) number that can't be used anywhere else regardless of
> whether it actuall gets connected or not. If a second inquire
> occurs, it must return a different number.
Most implementations have a limited number of different unit
numbers that are legal. A program that opens a lot of files
must usually reuse some of the numbers. You can't simultaneously
open more than a certain number on most operating systems
snyway.
--
J. Giles
"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare
|
| |
|
| |
 |
James Giles

|
Posted: 2007-1-22 10:56:00 |
Top |
fortran >> Most elegant way to read to allocatable array?
email***@***.com wrote:
...
> No, the problem is that it is numeric. The numeric value has to be
> translated into a reference to the real data structure that contains
> the necessary data. That requires using a global table to map
> numbers to the corresponding data structures. In threaded code,
> that means using locks. I have seen real world programs that
> spend 30+% of their execution time in the locking routines for I/O.
> Yes, they are doing things like reading a direct-access file one
> character at a time, but codes like that do exist.
Locks are required anyway to ensure distinct threads don't try
doing I/O "simultaneously" on the same file. Sure, without the
unit number lookup there's one less lock. Actually that only
needs to be locked when it's being modified (during OPEN
statement processing). Such table locks are not that expensive.
I guess it depends on how you implement locks in general
though. Been there, done that.
--
J. Giles
"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare
|
| |
|
| |
 |
Gary Scott

|
Posted: 2007-1-22 21:55:00 |
Top |
fortran >> Most elegant way to read to allocatable array?
James Giles wrote:
> Gary Scott wrote:
> ...
>
>>My assumption was that once you query it, it is a reserved (negative
>>or whatever) number that can't be used anywhere else regardless of
>>whether it actuall gets connected or not. If a second inquire
>>occurs, it must return a different number.
>
>
> Most implementations have a limited number of different unit
> numbers that are legal. A program that opens a lot of files
> must usually reuse some of the numbers. You can't simultaneously
> open more than a certain number on most operating systems
> snyway.
>
Most implementations that I've used allow any positive value allowed in
a default integer. There are typically limits on the number of
simultaneously assigned files.
--
Gary Scott
mailto:garylscott@sbcglobal dot net
***** 5 Jan: Back from 7 days in Cozumel! *****
Fortran Library: http://www.fortranlib.com
Support the Original G95 Project: http://www.g95.org
-OR-
Support the GNU GFortran Project: http://gcc.gnu.org/fortran/index.html
If you want to do the impossible, don't hire an expert because he knows
it can't be done.
-- Henry Ford
|
| |
|
| |
 |
pa

|
Posted: 2007-1-22 23:00:00 |
Top |
fortran >> Most elegant way to read to allocatable array?
Gary Scott <email***@***.com> wrote:
> Pierre Asselin wrote:
> >
> > [ ... ]
> > The minimal change to Fortran could be a new key in the OPEN
> > statement, for example OPEN(NEWUNIT=ivar, FILE=...).
> I personally don't consider that to be any better than an
> INQUIRE(FREEUNIT=ivar) method followed by a normal OPEN(UNIT...).
Which is what I do, but you have to loop over ivar until you find
a free unit (or cut bait). I ended up with 15 lines of boilerplate
that I would rather not have written.
Also, the scheme is vulnerable to conflicts with old code, as
Richard points out.
call get_me_an_unused_unit(ivar)
open(unit=ivar, file='important')
call DUSTYDECK(in,out)
write(ivar,*) out
There is no telling what units are hard-coded in DUSTYDECK.
> I consider INQUIRE to be more natural, otherwise, you're having OPEN
> perform an implicit inquire with the NEWUNIT specifier. It also allows
> you to INQUIRE a free unit without immediately opening/assigning to
> something.
There is no reason to deprecate INQUIRE. As to what feels natural,
I think this is just habit, pure and simple. I had to get used to
C's way of doing things when I learned C; comparing after many
years, processor-chosen handles are better than user-chosen handles.
I couldn't have told you that ahead of time.
--
pa at panix dot com
|
| |
|
| |
 |
pa

|
Posted: 2007-1-22 23:06:00 |
Top |
fortran >> Most elegant way to read to allocatable array?
Richard Maine <email***@***.com> wrote:
> [ ... ] Having OPEN return a negative unit number,
> which can't conflict with an open of a valid user-assigned unit number,
> avoids that problem.
It also breaks some of my code, in subroutines that take a unit
number for optional output and use iunit<0 to mean "don't write
anything", which is legal by today's standard. If we reserve -1
to mean "impossible unit" and specify that OPEN(NEWUNIT_or_whatever=)
returns a negative number other than -1, I can fix my code by a
trivial change to the test. Otherwise, I have to add an extra
logical argument or use F90+ features such as optional arguments.
Reserving -1 seems like a simple thing to do.
--
pa at panix dot com
|
| |
|
| |
 |
nospam

|
Posted: 2007-1-23 0:47:00 |
Top |
fortran >> Most elegant way to read to allocatable array?
Pierre Asselin <email***@***.com> wrote:
> Richard Maine <email***@***.com> wrote:
>
> > [ ... ] Having OPEN return a negative unit number,
> > which can't conflict with an open of a valid user-assigned unit number,
> > avoids that problem.
>
> It also breaks some of my code, in subroutines that take a unit
> number for optional output and use iunit<0 to mean "don't write
> anything", which is legal by today's standard. If we reserve -1
> to mean "impossible unit" and specify that OPEN(NEWUNIT_or_whatever=)
> returns a negative number other than -1, I can fix my code by a
> trivial change to the test. Otherwise, I have to add an extra
> logical argument or use F90+ features such as optional arguments.
>
> Reserving -1 seems like a simple thing to do.
Makes sense to me. In fact, checking f2003, I see that INPUT_UNIT,
OUTPUT_UNIT, and ERROR_UNIT are specifically prohibitted from being -1.
I don't recall that level of detail of the OPEN(NEWUNIT_or_whatever=)
proposal, but it would certainly seem that the idea in f2003 is to
reserve -1, which would be sort of pointless if it wasn't done
consistently.
Hmm. The one other place in f2003 where a negative unit number is
alllowed is in DTIO. I don't off-hand see a restriction against -1
there. I might possibly have missed it. Seems to me like one belongs
there. And Note 9.44 will need some attention if the NEWUNIT= feature is
added.
--
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
|
| |
|
| |
 |
nospam

|
Posted: 2007-1-23 1:03:00 |
Top |
fortran >> Most elegant way to read to allocatable array?
Gary Scott <email***@***.com> wrote:
[about unit numbers]
> Most implementations that I've used allow any positive value allowed in
> a default integer.
That seems typical of the more recent implementations. However, I would
have said that smaller limits than that were common earlier. I've seen
limits of 63, 99, and 255. My personal portability guideline is to stop
at 99. (The 63 limit was unusual, and I think a later version of that
compiler upped it).
--
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
|
| |
|
| |
 |
glen herrmannsfeldt

|
Posted: 2007-1-23 2:02:00 |
Top |
fortran >> Most elegant way to read to allocatable array?
Gary Scott <email***@***.com> wrote:
(snip on UNIT numbers)
> Most implementations that I've used allow any positive value allowed in
> a default integer. There are typically limits on the number of
> simultaneously assigned files.
It is easy enough to use a hash table to accept any valid postive
integer. I am pretty sure that many Fortran 66 implementations
didn't do that, instead using a fixed size table and directly
indexing it.
For OS/360 and successors the unit number maps directly to the
DDname, allowing for only two digits. I believe the actual
maximum is a sysgen option.
-- glen
|
| |
|
| |
 |
Dan Nagle

|
Posted: 2007-1-23 2:25:00 |
Top |
fortran >> Most elegant way to read to allocatable array?
Hello,
-1 is off limits because inquire returns -1
to mean no such unit.
Richard E Maine wrote:
> Pierre Asselin <email***@***.com> wrote:
>
>> Richard Maine <email***@***.com> wrote:
>>
>>> [ ... ] Having OPEN return a negative unit number,
>>> which can't conflict with an open of a valid user-assigned unit number,
>>> avoids that problem.
>> It also breaks some of my code, in subroutines that take a unit
>> number for optional output and use iunit<0 to mean "don't write
>> anything", which is legal by today's standard. If we reserve -1
>> to mean "impossible unit" and specify that OPEN(NEWUNIT_or_whatever=)
>> returns a negative number other than -1, I can fix my code by a
>> trivial change to the test. Otherwise, I have to add an extra
>> logical argument or use F90+ features such as optional arguments.
>>
>> Reserving -1 seems like a simple thing to do.
>
> Makes sense to me. In fact, checking f2003, I see that INPUT_UNIT,
> OUTPUT_UNIT, and ERROR_UNIT are specifically prohibitted from being -1.
> I don't recall that level of detail of the OPEN(NEWUNIT_or_whatever=)
> proposal, but it would certainly seem that the idea in f2003 is to
> reserve -1, which would be sort of pointless if it wasn't done
> consistently.
>
> Hmm. The one other place in f2003 where a negative unit number is
> alllowed is in DTIO. I don't off-hand see a restriction against -1
> there. I might possibly have missed it. Seems to me like one belongs
> there. And Note 9.44 will need some attention if the NEWUNIT= feature is
> added.
>
--
Cheers!
Dan Nagle
Purple Sage Computing Solutions, Inc.
|
| |
|
| |
 |
nospam

|
Posted: 2007-1-23 2:37:00 |
Top |
fortran >> Most elegant way to read to allocatable array?
(I've re-arranged the top-posting for clarity)
> Richard E Maine wrote:
> > Pierre Asselin <email***@***.com> wrote:
> >> Reserving -1 seems like a simple thing to do.
> > Makes sense to me....
> > Hmm. The one other place in f2003 where a negative unit number is
> > alllowed is in DTIO. I don't off-hand see a restriction against -1
> > there. I might possibly have missed it. Seems to me like one belongs
> > there. And Note 9.44 will need some attention if the NEWUNIT= feature is
> > added.
> >
Dan Nagle <email***@***.com> replied:
> -1 is off limits because inquire returns -1
> to mean no such unit.
That would be part of why it would make sense to keep -1 off limits, but
I don't see that it follows that the standard disallows DTIO from using
-1. I see that it would be a poor choice for a compiler to make, but
that's not the same thing as being disallowed. I would think that the
standard should explicitly disallow -1 as a DTIO unit number, just like
it explicitly disallows it for INPUT_UNIT, OUTPUT_UNIT, and ERROR_UNIT.
After all, the disallowance is explicit in those 3 cases, which one
could apply the sam eargument to.
--
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
|
| |
|
| |
 |
pa

|
Posted: 2007-1-23 22:58:00 |
Top |
fortran >> Most elegant way to read to allocatable array?
email***@***.com wrote:
> Pierre Asselin wrote:
> > The problem here is not that the handle is numeric, but that the
> > the responsibility for its value is forced on the user.
> No, the problem is that it is numeric. The numeric value has to be
> translated into a reference to the real data structure that contains
> the necessary data. That requires using a global table to map
> numbers to the corresponding data structures. In threaded code,
> that means using locks. I have seen real world programs that
> spend 30+% of their execution time in the locking routines for I/O.
> Yes, they are doing things like reading a direct-access file one
> character at a time, but codes like that do exist.
Is the lock required on all I/O operations or just on OPEN/CLOSE
? It seems to me that two threads could do simultaneous I/O on
different units without any locking overhead if the run-time library
is implemented right --but I've never written one so I may be
completely wrong about that.
If you mean concurrent I/O on the same unit, that's a much bigger
beast. There was a long thread in c.l.c++.moderated on how
underspecified that language is for multi-threaded programming.
If anything, Fortran is even more underspecified. Presumably
the Fortran support for parallel processing will come in at a
higher level, e.g. co-arrays in F08.
> Never add a feature to a language that requires global state. It
> will cause trouble in a multi-threaded environment, and that is
> where computing is headed.
Except that the feature is already in, and has been since the
earliest days of Fortran. My proposal, if you want to call it
that, is orthogonal to threading nightmares.
--
pa at panix dot com
|
| |
|
| |
 |
Janne Blomqvist

|
Posted: 2007-1-24 7:24:00 |
Top |
fortran >> Most elegant way to read to allocatable array?
In article <ep57qh$rbq$email***@***.com>, Pierre Asselin wrote:
> email***@***.com wrote:
>
>> Pierre Asselin wrote:
>
>> > The problem here is not that the handle is numeric, but that the
>> > the responsibility for its value is forced on the user.
>
>> No, the problem is that it is numeric. The numeric value has to be
>> translated into a reference to the real data structure that contains
>> the necessary data. That requires using a global table to map
>> numbers to the corresponding data structures. In threaded code,
>> that means using locks. I have seen real world programs that
>> spend 30+% of their execution time in the locking routines for I/O.
>> Yes, they are doing things like reading a direct-access file one
>> character at a time, but codes like that do exist.
>
> Is the lock required on all I/O operations or just on OPEN/CLOSE
> ?
I suspect it's needed, e.g. you need to make sure that one thread
doesn't close the unit while another is doing i/o in it, no?
> It seems to me that two threads could do simultaneous I/O on
> different units without any locking overhead if the run-time library
> is implemented right --but I've never written one so I may be
> completely wrong about that.
You can find a brief description of how gfortran does it at
http://gcc.gnu.org/viewcvs/*checkout*/trunk/libgfortran/io/unit.c
(gfortran supports openmp, so the library needs to be thread safe).
Basically there is one lock which protects the tree which holds the
data structures that the library keeps for each open unit, and then
there is one lock per unit.
> If you mean concurrent I/O on the same unit, that's a much bigger
> beast. There was a long thread in c.l.c++.moderated on how
> underspecified that language is for multi-threaded programming.
> If anything, Fortran is even more underspecified. Presumably
> the Fortran support for parallel processing will come in at a
> higher level, e.g. co-arrays in F08.
Should be doable at least for direct access. Could work for reading
sequential and stream as well if you take the view that the file
position is per-thread instead of a global property, though it should
be noted that co-array Fortran apparently forbids opening a sequential
file with action=read on multiple images. See
ftp://ftp.nag.co.uk/sc22wg5/N1601-N1650/N1639.txt
--
Janne Blomqvist
|
| |
|
| |
 |
Gary Scott

|
Posted: 2007-1-24 7:37:00 |
Top |
fortran >> Most elegant way to read to allocatable array?
Janne Blomqvist wrote:
> In article <ep57qh$rbq$email***@***.com>, Pierre Asselin wrote:
>
>>email***@***.com wrote:
>>
>>
>>>Pierre Asselin wrote:
>>
>>>>The problem here is not that the handle is numeric, but that the
>>>>the responsibility for its value is forced on the user.
>>
>>>No, the problem is that it is numeric. The numeric value has to be
>>>translated into a reference to the real data structure that contains
>>>the necessary data. That requires using a global table to map
>>>numbers to the corresponding data structures. In threaded code,
>>>that means using locks. I have seen real world programs that
>>>spend 30+% of their execution time in the locking routines for I/O.
>>>Yes, they are doing things like reading a direct-access file one
>>>character at a time, but codes like that do exist.
>>
>>Is the lock required on all I/O operations or just on OPEN/CLOSE
>>?
>
>
> I suspect it's needed, e.g. you need to make sure that one thread
> doesn't close the unit while another is doing i/o in it, no?
Not necessarily. I would say that that is an application decision to
communicate between the threads (e.g. master/slave) and ensure that only
the thread that knows it is safe to do so does so. It isn't uncommon
for a multithreaded application to funnel all I/O activity through a
dedicated IO thread or separate IO process. I use a small file mapping
area (I once tried pipes for cross network synchronization and it seemed
to work really well) to communicate across threads and processes with a
fairly simple handshaking instruction/status interface. Some of this
becomes straightforwarded once you have basic thread/process facilities
within the language...maybe by my 90th birthday.
>
>
>>It seems to me that two threads could do simultaneous I/O on
>>different units without any locking overhead if the run-time library
>>is implemented right --but I've never written one so I may be
>>completely wrong about that.
>
>
> You can find a brief description of how gfortran does it at
> http://gcc.gnu.org/viewcvs/*checkout*/trunk/libgfortran/io/unit.c
> (gfortran supports openmp, so the library needs to be thread safe).
>
> Basically there is one lock which protects the tree which holds the
> data structures that the library keeps for each open unit, and then
> there is one lock per unit.
>
>
>>If you mean concurrent I/O on the same unit, that's a much bigger
>>beast. There was a long thread in c.l.c++.moderated on how
>>underspecified that language is for multi-threaded programming.
>>If anything, Fortran is even more underspecified. Presumably
>>the Fortran support for parallel processing will come in at a
>>higher level, e.g. co-arrays in F08.
>
>
> Should be doable at least for direct access. Could work for reading
> sequential and stream as well if you take the view that the file
> position is per-thread instead of a global property, though it should
> be noted that co-array Fortran apparently forbids opening a sequential
> file with action=read on multiple images. See
> ftp://ftp.nag.co.uk/sc22wg5/N1601-N1650/N1639.txt
>
--
Gary Scott
mailto:garylscott@sbcglobal dot net
***** 5 Jan: Back from 7 days in Cozumel! *****
Fortran Library: http://www.fortranlib.com
Support the Original G95 Project: http://www.g95.org
-OR-
Support the GNU GFortran Project: http://gcc.gnu.org/fortran/index.html
If you want to do the impossible, don't hire an expert because he knows
it can't be done.
-- Henry Ford
|
| |
|
| |
 |
kargl

|
Posted: 2007-1-24 7:59:00 |
Top |
fortran >> Most elegant way to read to allocatable array?
In article <r%wth.22446$email***@***.com>,
Gary Scott <email***@***.com> writes:
> Janne Blomqvist wrote:
>
>> In article <ep57qh$rbq$email***@***.com>, Pierre Asselin wrote:
>>
>>>email***@***.com wrote:
>>>
>>>
>>>>Pierre Asselin wrote:
>>>
>>>>>The problem here is not that the handle is numeric, but that the
>>>>>the responsibility for its value is forced on the user.
>>>
>>>>No, the problem is that it is numeric. The numeric value has to be
>>>>translated into a reference to the real data structure that contains
>>>>the necessary data. That requires using a global table to map
>>>>numbers to the corresponding data structures. In threaded code,
>>>>that means using locks. I have seen real world programs that
>>>>spend 30+% of their execution time in the locking routines for I/O.
>>>>Yes, they are doing things like reading a direct-access file one
>>>>character at a time, but codes like that do exist.
>>>
>>>Is the lock required on all I/O operations or just on OPEN/CLOSE
>>>?
>>
>>
>> I suspect it's needed, e.g. you need to make sure that one thread
>> doesn't close the unit while another is doing i/o in it, no?
>
> Not necessarily. I would say that that is an application decision to
> communicate between the threads (e.g. master/slave) and ensure that only
> the thread that knows it is safe to do so does so. It isn't uncommon
> for a multithreaded application to funnel all I/O activity through a
> dedicated IO thread or separate IO process. I use a small file mapping
> area (I once tried pipes for cross network synchronization and it seemed
> to work really well) to communicate across threads and processes with a
> fairly simple handshaking instruction/status interface. Some of this
> becomes straightforwarded once you have basic thread/process facilities
> within the language...maybe by my 90th birthday.
>
As the writer of the application, you can indeed funnel all I/O
through a dedicated thread to try to economize locking. From the
gfortran perspective, its runtime library can't assume everyone
knows how to properly lock the I/O channels, so it takes a defensive
position with tracking/applying locking to IO units.
--
Steve
http://troutmask.apl.washington.edu/~kargl/
|
| |
|
| |
 |
James Giles

|
Posted: 2007-1-24 8:35:00 |
Top |
fortran >> Most elegant way to read to allocatable array?
Janne Blomqvist wrote:
> In article <ep57qh$rbq$email***@***.com>, Pierre Asselin wrote:
...
>> Is the lock required on all I/O operations or just on OPEN/CLOSE
>> ?
>
> I suspect it's needed, e.g. you need to make sure that one thread
> doesn't close the unit while another is doing i/o in it, no?
That would be a lock that's needed whether the I/O used unit numbers
or handles. The lock on the I/O unit table is unlocked as soon as
you've looked up the corresponding handle. Since it's only a
table lookup it's fast and no thread spends much time in that
critical section. So, unit numbers don't really contributte much
to the overhead of handling threads. (Yes, the table has to be
locked longer during OPEN and CLOSE since you're modifying
it. And yes, things that don't modify the table could be let into
the critical section several at a time.)
>> If you mean concurrent I/O on the same unit, that's a much bigger
>> beast. There was a long thread in c.l.c++.moderated on how
>> underspecified that language is for multi-threaded programming.
>> If anything, Fortran is even more underspecified. Presumably
>> the Fortran support for parallel processing will come in at a
>> higher level, e.g. co-arrays in F08.
I've done concurrent I/O on the same unit with Fortran 77 before.
The rule was the any number of threads could simultaneously read
the file but only one could write and only when no reads or other
writes were in progress. You have to address several issues.
But it can be made to work.
--
J. Giles
"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare
|
| |
|
| |
 |
Janne Blomqvist

|
Posted: 2007-1-24 15:27:00 |
Top |
fortran >> Most elegant way to read to allocatable array?
James Giles wrote:
> Janne Blomqvist wrote:
>> In article <ep57qh$rbq$email***@***.com>, Pierre Asselin wrote:
> ...
>>> Is the lock required on all I/O operations or just on OPEN/CLOSE
>>> ?
>>
>> I suspect it's needed, e.g. you need to make sure that one thread
>> doesn't close the unit while another is doing i/o in it, no?
>
> That would be a lock that's needed whether the I/O used unit numbers
> or handles.
I don't know what I meant above (?), but anyway, AFAICS gfortran needs
to acquire this global lock for every read or write to do the unit
number -> pointer to the unit structure mapping. So if Fortran used
opaque handles instead of unit numbers, then the handle could contain
the pointer directly and the global lock would not be needed (since
the lock for the unit itself naturally resides in the unit
structure). OPEN/CLOSE would still need the global lock, but they
aren't that performance critical.
Other compilers may do it differently, I suppose.
> The lock on the I/O unit table is unlocked as soon as
> you've looked up the corresponding handle. Since it's only a
> table lookup it's fast and no thread spends much time in that
> critical section. So, unit numbers don't really contributte much
> to the overhead of handling threads.
Yes, though presumably you could, as usual, design some pathological
examples where it would be significant. E.g. as explained by Robert
Corbett.
--
Janne Blomqvist
|
| |
|
| |
 |
James Giles

|
Posted: 2007-1-24 16:07:00 |
Top |
fortran >> Most elegant way to read to allocatable array?
Janne Blomqvist wrote:
> James Giles wrote:
>> Janne Blomqvist wrote:
...
>>> I suspect it's needed, e.g. you need to make sure that one thread
>>> doesn't close the unit while another is doing i/o in it, no?
>>
>> That would be a lock that's needed whether the I/O used unit numbers
>> or handles.
>
> I don't know what I meant above (?), but anyway, AFAICS gfortran needs
> to acquire this global lock for every read or write to do the unit
> number -> pointer to the unit structure mapping. [...]
Yes, but that particular table only needs to be locked while you look
up that one piece of data. That's then unlocked. But, then you must
lock the table entry for the specific file you're actually working on.
That second lock must be set even if you were to eliminate unit
numbers from the language and began to use "handles" or some
such feature.
Since the unit number table look-up is rather fast, the time lost waiting
on that first lock is trivial unless the locking mechanism you use has
lots of overhead itself. It's unlikely that the unit number look-up
table will be locked when a process gets there. Even in a program
with lots of threads which each do lots of I/O, the odds of a clash
are small.
> Yes, though presumably you could, as usual, design some pathological
> examples where it would be significant. E.g. as explained by Robert
> Corbett.
That's why you prove correctness and specify exactly what
assumptions went into the proof. Most pathological examples
are resolved by detecting them and issuing a message. Things
like the above: suppose you try to close from one thread while
still trying to do I/O on the same file from another thread. If the
one doing I/O gets there first all's well. If the close gets there
first you simply issue the usual message that the program is
attempting I/O on a unit that's not open. Too bad, but it's the
programmer's fault for creating such a race condition in his
(her) program in the first place. The latter case is no different
than if the file were closed before an I/O attempt in a single
threaded code.
--
J. Giles
"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare
|
| |
|
| |
 |
glen herrmannsfeldt

|
Posted: 2007-1-24 19:00:00 |
Top |
fortran >> Most elegant way to read to allocatable array?
Pierre Asselin wrote:
(snip regarding unit numbers)
> The problem here is not that the handle is numeric, but that the
> the responsibility for its value is forced on the user. In
> retrospect, that was a bad idea. It causes no end of trouble when
> integrating codes from different authors. To make matters worse,
> there are no guidelines for choosing a value, as Richard reminds
> us above.
If it was alphanumeric and chosen by the user, then the probability
of accidentally choosing one already used is much smaller.
I did always like the MVS DDname better than the small integers
of unix file descriptors. Though some are against the whole
idea of DDnames connecting to data sets.
(snip)
> let's not forget that under stdio is a low-level file handle provided
> by the operating system. Under Posix, this handle is an integer;
(snip)
> The temptation to use arithmetic on handle variables or to otherwise
> clobber them must not be that strong, because users just don't do
> that. The big difference with Fortran is that the numerical value
> is chosen by the open() call instead of the user.
Unix users like to do that all the time.
The way to redirect stdin is to open a new file, close(0)
and dup(newfile). dup() duplicates an open descriptor on the
lowest available, which will then be zero. If that isn't
good enough, there is dup2() to duplicate it on any
available fd. I think after the dup, then the other one
is closed, so there won't be two open fd's for the same
file.
-- glen
|
| |
|
| |
 |
Dick Hendrickson

|
Posted: 2007-1-25 6:06:00 |
Top |
fortran >> Most elegant way to read to allocatable array?
Richard Maine wrote:
> Michael Prager <email***@***.com> wrote:
>
>> Richard Maine <email***@***.com> wrote:
>>
>>> Sort of related - I didn't mention it at the time, but I second
>>> Beliavsky's advice to avoid opening units 5 and 6 (or any unit numbers
>>> less than 10, but 5 and 6 are the "worst"). Those are exactly the unit
>>> numbers *MOST* likely to have problems. They are often special-cased in
>>> several ways.
>
> (Oh. I missed the "/" part of the "/=", as Glen noted).
>
>> Would it be unthinkable for the next Fortran standard to make
>> obsolescent the use of unit numbers < 10 for disk I/O? This
>> issue comes up again and again and again, and since it's not in
>> the standard, new users seem to learn about it only by being
>> burnt.
>
> I have pushed much more for the whole concept of unit numbers to be
> phased out. I think it is one of Fortran's unfortunate hostorical
> features, which made sense in days long ago, but is just a hindrance
> today. Patching up little bits of it here and there won't fix it.
>
> I've seen two proposals that I like.
>
> 1. The more drastic one, but I think the best in the long run. Introduce
> a new non-numeric file "handle". Allow open to return it, and allow it
> to be specified in the other I/O statements. Basically, you'd have the
> option of using either unit numbers or file handles. That should provide
> a transitional capability. Basically the way that most more recent
> languages do such things.
>
> 2. The best "hack" I've seen is to have a system function to provide an
> unused unit number. In order to avoid conflicts with hard-wired unit
> numbers in other code, it would have to be a negative number. We already
> (in f2003) have the concept of negative unit numbers as something that
> the system can assign, but that user's can't otherwise use.
>
> Note that this pretty much has to be a compiler function in order to
> avoid all possible conflicts.
[snip]
this comment is a little late, but I've been out of town.
F2008 has a NEWUNIT=scalar-integer-variable specifier on the OPEN
statement. Its job is to assign a value to the scalar integer
variable that is guaranteed to be an unused unit number. They
have to be negative and not equal to any of the special negative
values. It's sort of a compromise between a handle and a hack.
Dick Hendrickson
|
| |
|
| |
 |
Janne Blomqvist

|
Posted: 2007-1-25 6:14:00 |
Top |
fortran >> Most elegant way to read to allocatable array?
James Giles wrote:
> Janne Blomqvist wrote:
>> I don't know what I meant above (?), but anyway, AFAICS gfortran needs
>> to acquire this global lock for every read or write to do the unit
>> number -> pointer to the unit structure mapping. [...]
>
> Yes, but that particular table only needs to be locked while you look
> up that one piece of data. That's then unlocked. But, then you must
> lock the table entry for the specific file you're actually working on.
Yes, obviously.
> That second lock must be set even if you were to eliminate unit
> numbers from the language and began to use "handles" or some
> such feature.
I'm not arguing against you, just pointing out that with handles one
can avoid the global lock; I don't think that is a particularly strong
argument for introducing I/O handles. Actually I kind of like the
OPEN(NEWUNIT=foo, ...) idea as being simpler and more like how Fortran
currently works.
>> Yes, though presumably you could, as usual, design some pathological
>> examples where it would be significant. E.g. as explained by Robert
>> Corbett.
>
> That's why you prove correctness and specify exactly what
> assumptions went into the proof.
I meant pathological as in R.C.:s example of a multithreaded program
spending a large amount of time waiting on the unit table lock.
> Most pathological examples
> are resolved by detecting them and issuing a message. Things
> like the above: suppose you try to close from one thread while
> still trying to do I/O on the same file from another thread. If the
> one doing I/O gets there first all's well. If the close gets there
> first you simply issue the usual message that the program is
> attempting I/O on a unit that's not open. Too bad, but it's the
> programmer's fault for creating such a race condition in his
> (her) program in the first place. The latter case is no different
> than if the file were closed before an I/O attempt in a single
> threaded code.
But this is a poor example for Fortran, since IIRC the standard
doesn't require you to explicitly OPEN units before using them, no?
--
Janne Blomqvist
|
| |
|
| |
 |
| |
 |
Index ‹ fortran |
- Next
- 1
- gfortran & openmp on windowsI developed a copy of gomp in win32 thread, and built a copy of gfortran
with win32 thread for openmp, and tested on some examples. So far, it works
OK. However, the compiler cannot read the file from the statement "use
omp_lib". I got the following error message
Fatal Error: Reading module omp_lib at line 16 column 27: Bad name
gcc: Internal error: Aborted (program f951)
Please submit a full bug report.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
Fortunately, it is not absolutely necessary to have the statement "use
omp_lib". The compiler still works. I wonder if "pthread version" encounters
a similar problem.
The configuration is as
Using built-in specs.
Target: i386-pc-mingw32
Configured with:
../gcc-4.2-20060520-mingw32/configure --with-gcc --with-gnu-ld --with-gnu-as
--host=i386-pc-mingw32 --build=x86_64-unknown-linux-gnu --target=i386-pc-mi
ngw32 --prefix=/home/gfortran/gcc-native-mingw32-4.2-20060520 --disable-shar
ed --disable-nls --with-gmp=/home/gfortran/gmp-mingw32 --with-mpfr=/home/gfo
rtran/mpfr-mingw32 --with-sysroot=/home/gfortran/gcc-cross-mingw32-4.2-20060
520 --enable-threads=win32 --enable-languages=c,c++,fortran --enable-libgomp
--disable-win32-registry
Thread model: win32
gcc version 4.2.0 20060520 (experimental)
Thank you.
JL
--
Posted via a free Usenet account from http://www.teranews.com
- 2
- How to compare two strings?email***@***.com wrote in message <email***@***.com>...
>I thought I could test two strings with the code below, but it doesn't
>work. I'm passing a string into the function below, but the result is
>always 'not equal'. How are strings compared in Fortran 77?
This is Fortran 90 or later.
> function evaluateinput(str1) result(string)
> implicit none
> character(12) str1
character(len=*) :: str1
is required for a dummy argument that receives an argument
whose length can be anything.
> character(12) string
> if (str1 .EQ. 'test') then
if (str1 == 'test') then
> string = 'equal'
> else
> string = 'not equal'
> endif
> return
> end
- 3
- [OT] Re: Intel Fortran license?Richard E Maine wrote:
|
| But when I had a keyboard die and was happy with one that was $7.95 or
| so (in fact I like the cheap ones *better* than the ones with all the
| extra crap^h^h^hfeatures)
Amen to that.
I'm a proud user of a 5-year old Chicony KB-7906 with "ergonomic" shape,
costed around $25 at the time. Apart from excellent quality, the thing
I most like about it is that it has 101 key (or less, lazy to count);
I doubt I could find anything similar these days.
--
Jugoslav
___________
www.xeffort.com
Please reply to the newsgroup.
You can find my real e-mail on my home page above.
- 4
- NAG on Fortran for finance quantshttp://fenews.com/fen35/where_num_matters/where_num_matters.html
Malcolm Cohen of NAG has written an article on the advantages of a
matrix-oriented language like Fortran 2003 for quantitative finance
(QF), an area where C++ is now dominant.
I am glad he wrote the article and hope that NAG is successful in
promoting Fortran in QF. However, NAG would be more persuasive in
promoting Fortran 95 and later versions if it fully adopted the
standard itself in its math libraries. The NAG Fortran 77 library
continues to be provide substantially more functionality than the
Fortran 90 library. It would not be difficult to include all the
functionality of the Fortran 77 library in the Fortran 90 library,
simply by writing wrappers for the F77 code that eliminate arguments
specifying array sizes and providing workspace arrays.
One NAG procedure I have considered using, G13DCF, which estimates
vector ARMA time series models, has 27 (!) arguments, at least 11 of
which are worksspace or array dimension arguments that could be easily
removed. I am sure many other arguments could be made OPTIONAL. There
is no exact equivalent in their F90 library.
NAG has not only failed to make the entire functionality of their
traditional F77 library available in their F90 library, they are
adding NEW procedures ONLY to the F77 and C libraries. An example is
their GARCH subroutines, use to model time series with changing
variance, a hot topic in finance. (The Nobel prize in economics this
year was awarded to an inventor of GARCH). Subroutines such as G05HKF
in F77 have no equivalent in their F90 library.
Numerical Recipes got it right: they made available a Fortran 90
version of their full library soon after F90 was standardized. What I
am talking about is not hard to do. Buyers can still use their F77
library if they prefer, of course.
NAG might be unsuccessful in promoting modern Fortran in quantitative
finance even if it did things properly, due to the bad connotations of
the "F-word" in that field. But its current approach almost ensures
that its market share in quantitative finance will be miniscule,
compared to more user-friendly products like Matlab and S-Plus.
- 5
- Another question for you - files nameI would like to create files whose name is related to one on more
input-output data of my programs.
The problem is that I don't know how to give a "dynamic name" to files,
neither if it's possible or not to be honest at all :-)
At the moment, I create files in this way:
open (34, file='chosen.kumac')
were "chosen.kumac" it's not dynamic at all - I mean, it's not a function
of the input-output of the program.
My problem, basically, is that the number of files I have to create depends
on input-output data: so a priori, in my program, I can't write these
instruction (while I can write IN files dynamic stuff - I still thank you
for your help).
I could manage this problem with some "if - then - goto" statements, but
that wouldn't be a serious solution.
Ciao!
- 6
- array allocation in a subroutineHi.
I would like allocate an array in a subroutine. It works if this array
is allocated before the subroutine, and I deallocate it in the
subroutine before a reallocation, but I get a segmentation fault, it
this array arrives to the subroutine before any allocation. Could
someone tell me what's wrong in this sample code? Thank you very much.
Nico
subroutine sub(a)
real,allocatable,dimension(:,:)::a
if(allocated(a)) deallocate(a)
allocate(a(10,10))
endsubroutine sub
program test
real,allocatable,dimension(:,:)::a
call sub(a)
endprogram test
--
Nicolas LIMARE
- 7
- Just say Fortran (was: Fortran 2000 article by John Reid)bv <email***@***.com> wrote in message news:<email***@***.com>...
> analyst41 wrote:
> >
> > Isn't there any one else out there that would like to evolve f77 into
> > the modern age while retaining the essential elegance of the language
> > and keeping it SMALL ?
>
> You bet, except that you won't find them in the c.l.f. frequent "flier"
> pack, but within the 150,000 (daily) netlib crowd which is apparently
> too busy for computationally useless "featuritis" chat.
>
> http://netlib.org/utk/misc/counts.html
I am really serious. There is classic case of "The emperor has no
clothes on" with respect to how Fortran has evolved after F77. At
first I thought that there was nothing to do except to rave and rant -
but a gentleman massively annoyed the cloud-cuckooland regulars here
by announcing that he has publsihed a book on "Classical Fortran" and
teaches a course based on that.
Thats when I realized that there is still hope - Why not go back to
the future - reject nearly every thing in F90 onwards and evolve the
astoundingly simple and powerful f77 in a different way ?
Since the gurus make it a point that only f77 and before were
"FORTRAN" and that their language has now become "Fortran" - may be we
should leave "Fortran" to the gurus and try to save and evolve
FORTRAN.
I myelf am maintaining 20000 + lines of FORTRAN code in a mission
critical application for a billion dollar plus corporation - and i am
too busy to start codifying what really belongs in FORTRAN. But would
be willing to join in as a charter member if others want to to go back
to FORTRAN 77 and look at whats really happening in computing today
and restore it to its rightful place.
- 8
- Statement functionsRichard E Maine wrote:
> Anyway, "obsolescent" describes something that is in the process of
> becoming obsolete, but is not yet obsolete. Something is not formally
> considered obsolete until it is deleted from the standard.
The distinction is subtle and theoretical. It could just as well been
taken directly out of the standard right away, making it obsolete.
In practice, many compilers would still support it anyway if it becomes
obsoleted, maybe producing a warning if asked to comply with the
standard. They keep it because a) it's already implemented, and b)
they'd like to support legacy code. They would most certainly do this
warning approach if it is declared "just" obsolescent too.
Anyone who doesn't really care about maintainability, wouldn't care much
about the warning either. Anyone who cares about future maintainability,
would care so much about the warning and standard that the feature would
be banned from use alltogether.
So in practice the difference becomes NIL.
--
-+-Ben-+-
- 9
- Fortran 2008 (was Re: New style DO syntax?)Richard Maine wrote:
> My personal opinion is that f2008 is being rushed too fast, but a delay
> of 1000 years is probably more than I was thinking. :-) I do suspect
> that full f2003 compilers will be out before the f2008 standard, but not
> by as much as I'd like to see. It seems to me that the current schedule
> allows zero opportunity for any actual experience with full-language
> f2003 compilers to influence f2008. After all, the f2008 feature set
> seems to be largely settled already, or at least enough so that changes
> to it are likely to be resisted as being too late - but there are no
> f2003 compilers yet.
I agree with Mr. Maine. A company can work on version 2 of a product
while putting the final touches on version 1, but final decisions about
version 2 should NOT be made until customers gain experience with
version 1 and can give feedback. Whether there should even be a version
2 should depend on the success of version 1 in the marketplace. Because
one can call any project a "success" by redefining "success", the
criteria for success should be defined beforehand.
One argument made for future Fortran standards is that "a language
either evolves or dies." I wonder about this. C is still one of the
most important and popular programming languages, and it's my
impression that the C99 standard has very little to do with this.
Most public domain Fortran code is still in FORTRAN -- modern Fortran
is underused. I think translating the important FORTRAN libraries to
Fortran 95 or 2003 could be an important service to the Fortran
community. Two people that have worked on this are Alan Miller
http://users.bigpond.net.au/amiller/ and John Burkardt
http://www.scs.fsu.edu/~burkardt/f_src/f_src.html . Burkardt quickly
fixes reported errors in his posted codes.
The Fortran 2003 book by Metcalf, Reid, and Cohen is good but perhaps
not suitable to beginning programmers. More books on Fortran 2003 are
needed IMO.
I think it is more important right now for Fortranners to use the
language that is available and discover its strengths and limitations,
before making the language even bigger.
- 10
- helppppp....Dear all,
I want to get the header name from a data file and include it in the
function in the fortran.
For eg.
program main
character*80 getheader
open (1, file = 'input.doc', access= 'sequential',
& status = 'old')
read(1,'(A)')getheader
close(1)
call function(getheader)
end program main
subroutine function(getheader)
character*80 header
# include "getheader"
..............
............
end
Now the problem is that it is not accepting the getheader
To be noted is that getheader conatins the path of the header
file...say ../inc/read.h
The error that i get is getheader is not a file or directory..
PLZZ can anyone throw light on this!!!!
- 11
- LNK1120 error and librariesGoodmorning everybody,
I make this program to test the "ERF function", I need it in my program
but when I build a message of fatal error appears LNK1120: 1 unresolved
externals.
program test_erf
real(4) :: x,erf,e
external erf
x=3
e = erf(x)
write(6,*)e
end program test_erf
Somebody could tell me where I make mistake? I think that maybe the
function erf is not included in the math library of Fortran, if it's so
how can I update it?
Do you know if there is also the inverse of error function in the
libraries? ("inverf" or "erfinv"....)
Thanks for your help,
Regards
Leandro
- 12
- why is this happening?James Giles wrote:
>>Sorry, but this has little if anything at all to do with
>>submodules. It *CERTAINLY* is not the main justification of
>>submodules. I don't recognize it as even being related to
>>submodules at all, but if it is related, it is much more as a minor
>>side effect than as the main purpose.
>
>
> Well, I can find no other justification of the feature. It does
> nothing else that's new. The intent (as explicitly stated in the
> early discussions I read) was to allow independent compilation
> while still performing interface matching at compile time.
> Why don't you enlighten us about any other capability it
> provides that there's nat already a simpler way to accomplish
> in hte existing language.
>
As an amateur interloper to the cockfight, can I put forward the notion
that submodules exist to address data protection/hiding issues in large
modules. To give an example, there are situations -- I've encountered
them myself -- where a module gets rather large and difficult to
maintain. Yet, it can't be broken up into disjoint modules, due to the
need to maintain the ability to manipulate a derived type that has
PRIVATE components. In such circumstances, submodules can be used to
break up the original module into seperate units, that are to a large
part independent but retain the ability to manipulate the derived type
defined in the (stub) parent module.
To some extent, this mimicks the 'friend' attribute in C++. Without
submodules, I can't see a way to achieve this, so I'm looking forward to
using the new feature.
cheers,
RIch
- 13
- F77-C: Passing Fortran FUNCTION as an argument for a C FunctionHello,
I have a Fortran FUNCTION f1, a Fortran SUBROUTINE s1 and a C function
c1.
c1 has following prototype:
void c1(double *,double (*fkt)(double,double*));
Now i want to CALL c1 from s1 and pass f1 as the second argument for c1.
Is it possible? If yes, then how should i define c1 interface in
Fortran? And how do i call c1 then?
tia,
schamil
- 14
- Text wrapping in output under Intel compilerHello all; maybe I am being dense with this one, or maybe not (almost
certainly I am)...
I am compiling some F95 code with the Intel compiler, ifort (version
8.1). When I run the compiled executable, the screen output wraps at 80
characters. Can I stop it from wrapping artificially? A quick scan of
the man pages doesn't shed any light on this.
The system I am running under is Linux, Fedora Core 2; perhaps there is
an environment variable that I need to alter or set?
Many thanks,
Dave Taylor
- 15
- Using Orderpack...Hey Folks,
I am having some difficulties figuring out how to use some of the
ranking modules found in Orderpack (http://www.fortran-2000.com/). I
was hoping somebody could point me in the right direction.
I have a multidimensional array (trainarray) I want to rank with
respect to element 2. I have posted the code I use to read the data
and initialize the array. Orderpack contains a module called MRGRNK
I'd like to use that will rank the array. But, for the life of me, I
can not figure out how to implement it. Could somebody show me how to
use these (or similar) types of modules?
Thanks Much.
R. Lowe
program timed
INTEGER i,j,l,n
REAL, DIMENSION(1716,23)::trainarray
OPEN (UNIT=14,FILE='E:\fortran\readltm\savi_trainx.txt',STATUS='old')
DO i=1,1716
READ(14,*) trainarray(i,1), trainarray(i,2), trainarray(i,3),
trainarray(i,4), &
trainarray(i,5), trainarray(i,6), trainarray(i,7),
trainarray(i,8), &
trainarray(i,9), trainarray(i,10), trainarray(i,11),
trainarray(i,12), &
trainarray(i,13), trainarray(i,14), trainarray(i,15),
trainarray(i,16), &
trainarray(i,17), trainarray(i,18), trainarray(i,19),
trainarray(i,20), &
trainarray(i,21), trainarray(i,22), trainarray(i,23)
rnkarray(i,1) = trainarray(i,2)
END do
CLOSE(14)
PRINT *, trainarray(200, 21)
PRINT *, trainarray(200, 1)
end program timed
|
|
|