* DEC C / VAX C problems
@ 1994-01-14 9:44 Matthias Kaspar
1994-01-14 18:21 ` Steve Hobbs
1994-01-18 20:11 ` Ken Cowan
0 siblings, 2 replies; 3+ messages in thread
From: Matthias Kaspar @ 1994-01-14 9:44 UTC (permalink / raw)
Hi everybody
Recently I got stuck with two C specific problems, one concerning DEC C on an
OpenVMS V1.5 AXP system (DEC 3000/500), another one concerning VAX C on a
VAXstation 4000-90, VMS-V5.5-2H4.
I am by no means experienced in C so please don't flame me if the following
questions seem obviuos to you.
*****************************************************************************
* *
* Problem 1 Using DEC C, SYSTEM$SPACE seems to delay the computation of *
* many functions in math.h on an OpenVMS AXP system. *
* *
*****************************************************************************
Use DEC C on an OpenVMS AXP system to compile the following source and analyze
the time elapsed with the Performance Coverage Analyzer V4.1-1.
#include stdio
#include math
main()
{
double x,y=1;
int i;
for (i=0;i<200000000;i++) x=sin(y);
}
Compile and link this with the /debug qualifier. Use
$ define lib$debug pca$collector
and check the elapsed time with the Performance Coverage Analyzer PCA V4.1-1.
As expected, about 98% of the elapsed time is spent in the main() routine.
Change sin(y) to cos(y) - still no problems.
Now change cos(y) to tan(y) or to sinh(y) or to cosh(y) or to tanh(y) or to
exp(y) and you're in for a surprise. It takes ages to compute these functions
(reduce the upper bound of the loop by two orders of magnitude if you are
impatient) and PCA will tell you that something between 80% and 96% (!!!) of
the time elapsed are spent in a routine called SYSTEM$SPACE.
What does it do? When is it called? Why is it called?
Why is so much time spent there when computing some functions like tan(x),
sinh(x), cosh(x), tanh(x) or exp(x) but practically no time when computing
sin(x) or cos(x) ?
Might this be an OpenVMS / DEC C bug? Might this be a PCA bug? (Or do I just
miss something terribly important when it comes to compute tan(x), sinh(x),
cosh(x), tanh(x) or exp(x) ?)
Does DEC know about this? What can I do about this?
How can I compute tanh(x) in DEC C (that's the function I desperately need)
without loosing lots of CPU time in this peculiar SYSTEM$SPACE? (It doesn't
make any sense to compose tanh(x) from a couple of exp(x)'s, because it takes
even longer to compute an exp(x) than a tanh(x), so it wouldn't be an
improvement. It doesn't make any sense either to call the Fortran tanh(x) from
the DEC C program, if tried to do so but still 90%+ of the elapsed time are
spent - you guessed it - in SYSTEM$SPACE.)
Right now I am trying a series expansion of tanh(x). However, I am not
satisfied and I would would prefer to use a built-in function.
SYSTEM$SPACE does not cause any problems computing the above functions
in VAX C on a VAXstation, nor does SYSTEM$SPACE delays the computation
of these functions in Fortran both on a VAX and an OpenVMS AXP system.
*******************************************************************************
*
* Problem 2 Using VAX C on a VAXstation with VMS, fwrite fails
* in case of fixed-length, record-formated files
*
*******************************************************************************
Somehow I do not succed to use the fwrite function on a VAXstation
4000-90 under VMS-V5.5-2H4. Please take a look at the following source...
#include stdio
main()
{
float x[100];
int i,j;
FILE *myfile;
for (j=0;j<100;j++) x[j]=(float)j; /* just for fun */
myfile=fopen("data.dat","w","ctx=rec","rfm=fix","mrs=512","shr=get,put");
/*I need the record format because the files have to be shareable*/
perror("\nperror after fopen...");
if (myfile==0) printf("\nfopen returns NULL pointer...");
else{
i=fwrite(&x[0],sizeof(float), 100,myfile);
perror("perror after fwrite... ");
printf("\nfwrite returns...%d",i);
fclose(myfile);
}
/*just for fun try to reopen and read the file. However, you don't need this
part to reproduce the error*/
myfile=fopen("data.dat","r","ctx=rec","rfm=fix","mrs=512","shr=get,put");
perror("\nperror after fopen for read...");
if (myfile==0) printf("\n fopen returns NULL pointer...");
else{
i=fread(&x[0],sizeof(float),100,myfile);
perror("perror after fread... ");
printf("\nfread returns...%d",i);
fclose(myfile);
}
}
Now the first fopen succeds in opening the file data.dat. A $ dir data.dat/full
tells me the file as been created correctly. The fwrite function however
returns 0 and consequently hasn't written a single byte to the file. perror
after the fwrite gives an error message. The output I get looks like this...
perror after fopen...: error 0
perror after fwrite... : non-translatable vms error code: 0x186A4, vms message:
%rms-f-rsz, invalid record size
fwrite returns...0
The following lines are of course due to the attempt to read the empty file
(I guess...)
perror after fopen for read...: non-translatable vms error code: 0x186A4, vms
message:%rms-f-rsz, invalid record size
perror after fread... : non-translatable vms error code: 0x186A4, vms message:
%rms-f-rsz, invalid record size
fread returns...0
I have tried different record sizes (512, 1024, 2048, 4096, 8192 bytes), I have
tried to write different numbers of items and different items to the file, it
just does not work.
However, compiling the source with DEC C on an OpenVMS AXP system presents no
problems at all, the code runs as expected and does NOT generate the above
error messages. 100 floats (400 bytes) are written to the file, fwrite correctly
returns the number of items written, that is 100. Reading the file afterwards
works all right too. If I take this data.dat created on an OpenVMS AXP system
and copy it to the above VAXstation, the second part of the code succeds in
opening and reading the file, so fread works with VAX C, just fwrite presents
difficulties to me.
What can I do about this? Is this a VMS bug? (Or am I just too stupid to use
fwrite correctly?)
Why does it work on an OpenVMS AXP system, but fails on a VAXstation?
Thanks a lot for taking the time to read all this. Any comments or suggestions
are most welcome. In case you know of any DEC Email address I might confront
with these questions, please tell me.
As I don't expect these problems to be of general interest please send replies
to one of these Internet nodes:
mkaspar@axp601.gsi.de (mkaspar@[140.181.98.71])
mkaspar@vscn.gsi.de (mkaspar@[140.181.97.141])
kaspar@IKF007.IKF.PHYSIK.UNI-FRANKFURT.DE (kaspar@[141.2.34.13])
Anyone interested in replies should send me an Email, I will of course be happy
to forward any incomming mail.
Thanks again, I really appreciate your help.
Bye,
Matthias Kaspar
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: DEC C / VAX C problems
1994-01-14 9:44 DEC C / VAX C problems Matthias Kaspar
@ 1994-01-14 18:21 ` Steve Hobbs
1994-01-18 20:11 ` Ken Cowan
1 sibling, 0 replies; 3+ messages in thread
From: Steve Hobbs @ 1994-01-14 18:21 UTC (permalink / raw)
In article <1994Jan14.104449@rzhp9a.gsi.de>, kaspar@rzhp9a.gsi.de (Matthias
Kaspar) asks about the performance of the following program:
>#include stdio
>#include math
>
>main()
>{
>double x,y=1;
>int i;
>for (i=0;i<200000000;i++) x=sin(y);
>}
>
It runs very fast calling sin (as written) or calling cos but runs much
slower if sin is replaced by tan, sinh, cosh, tanh, or exp.
The reason is a compiler optimization which is able to delete all calls to
sin or cos because x is a dead variable and sin/cos have no side effects.
However, when tan, sinh, cosh, tanh, or exp are called, this optimization
cannot be done because these math functions could have the side effect
of setting the errno variable. Therefore, in these cases most of the
execution time is spent in the math library which is a shareable image placed
in system space so that it can be easily shared between different
user images.
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: DEC C / VAX C problems
1994-01-14 9:44 DEC C / VAX C problems Matthias Kaspar
1994-01-14 18:21 ` Steve Hobbs
@ 1994-01-18 20:11 ` Ken Cowan
1 sibling, 0 replies; 3+ messages in thread
From: Ken Cowan @ 1994-01-18 20:11 UTC (permalink / raw)
In article <1994Jan14.104449@rzhp9a.gsi.de>, kaspar@rzhp9a.gsi.de (Matthias Kaspar) writes:
|>Path: jac.zko.dec.com!pa.dec.com!decwrl!uunet!Germany.EU.net!netmbx.de!zrz.TU-Berlin.DE!math.fu-berlin.de!news.th-darmstadt.de!rzhp9a.gsi.de!kaspar
|>From: kaspar@rzhp9a.gsi.de (Matthias Kaspar)
|>Newsgroups: comp.sys.dec
|>Subject: DEC C / VAX C problems
|>Date: Fri, 14 Jan 94 04:44:49 EST
|>Organization: GSI, Darmstadt, Germany
|>Lines: 174
|>Distribution: world
|>Message-ID: <1994Jan14.104449@rzhp9a.gsi.de>
|>NNTP-Posting-Host: rzhp9a.gsi.de
|>Keywords: DEC C, VAX C, SYSTEM$SPACE, fwrite
|>
|>Hi everybody
|>
|>Recently I got stuck with two C specific problems, one concerning DEC C on an
|>OpenVMS V1.5 AXP system (DEC 3000/500), another one concerning VAX C on a
|>VAXstation 4000-90, VMS-V5.5-2H4.
|>
|>I am by no means experienced in C so please don't flame me if the following
|>questions seem obviuos to you.
|>
|>*****************************************************************************
|>* *
|>* Problem 1 Using DEC C, SYSTEM$SPACE seems to delay the computation of *
|>* many functions in math.h on an OpenVMS AXP system. *
|>* *
|>*****************************************************************************
Steve Hobbs answered this previously. The compiler can optimize
away many of the calls to sin.
|>*******************************************************************************
|>*
|>* Problem 2 Using VAX C on a VAXstation with VMS, fwrite fails
|>* in case of fixed-length, record-formated files
|>*
|>*******************************************************************************
|>
|>Somehow I do not succed to use the fwrite function on a VAXstation
|>4000-90 under VMS-V5.5-2H4. Please take a look at the following source...
|>
|>#include stdio
|>main()
|>{
|>float x[100];
|>int i,j;
|>FILE *myfile;
|>
|>for (j=0;j<100;j++) x[j]=(float)j; /* just for fun */
|>
|>myfile=fopen("data.dat","w","ctx=rec","rfm=fix","mrs=512","shr=get,put");
|>/*I need the record format because the files have to be shareable*/
|>perror("\nperror after fopen...");
|>if (myfile==0) printf("\nfopen returns NULL pointer...");
|>else{
|> i=fwrite(&x[0],sizeof(float), 100,myfile);
|> perror("perror after fwrite... ");
|> printf("\nfwrite returns...%d",i);
|> fclose(myfile);
|> }
|>
|>/*just for fun try to reopen and read the file. However, you don't need this
|>part to reproduce the error*/
|>
|>myfile=fopen("data.dat","r","ctx=rec","rfm=fix","mrs=512","shr=get,put");
|>perror("\nperror after fopen for read...");
|>if (myfile==0) printf("\n fopen returns NULL pointer...");
|>else{
|> i=fread(&x[0],sizeof(float),100,myfile);
|> perror("perror after fread... ");
|> printf("\nfread returns...%d",i);
|> fclose(myfile);
|> }
|>}
|>
|>
|>Now the first fopen succeds in opening the file data.dat. A $ dir data.dat/full
|>tells me the file as been created correctly. The fwrite function however
|>returns 0 and consequently hasn't written a single byte to the file. perror
|>after the fwrite gives an error message. The output I get looks like this...
|>
|>perror after fopen...: error 0
|>perror after fwrite... : non-translatable vms error code: 0x186A4, vms message:
|>%rms-f-rsz, invalid record size
|>
|>fwrite returns...0
|>
|>The following lines are of course due to the attempt to read the empty file
|>(I guess...)
|>
|>perror after fopen for read...: non-translatable vms error code: 0x186A4, vms
|>message:%rms-f-rsz, invalid record size
|>perror after fread... : non-translatable vms error code: 0x186A4, vms message:
|>%rms-f-rsz, invalid record size
|>fread returns...0
|>
|>I have tried different record sizes (512, 1024, 2048, 4096, 8192 bytes), I have
|>tried to write different numbers of items and different items to the file, it
|>just does not work.
|>
|>However, compiling the source with DEC C on an OpenVMS AXP system presents no
|>problems at all, the code runs as expected and does NOT generate the above
|>error messages. 100 floats (400 bytes) are written to the file, fwrite correctly
|>returns the number of items written, that is 100. Reading the file afterwards
|>works all right too. If I take this data.dat created on an OpenVMS AXP system
|>and copy it to the above VAXstation, the second part of the code succeds in
|>opening and reading the file, so fread works with VAX C, just fwrite presents
|>difficulties to me.
|>
|>What can I do about this? Is this a VMS bug? (Or am I just too stupid to use
|>fwrite correctly?)
|>
|>Why does it work on an OpenVMS AXP system, but fails on a VAXstation?
|>
That fwrite call tells VAX C to write 100 records that are each
4 bytes long. The fopen statement says to create a file where
every record is a fixed length, and that length is 512. RMS
complains because it expects 512 and it is only given 4 at a time.
Try mrs=4 if you want 4 byte records, or mrs=400 and 1 item of 400
bytes (the size of the whole array) for the fwrite().
DEC C works a little differently. It interprets the fwrite call
as a desire to write 400 bytes, using as many records as necessary.
I used fopen mode "wb" since the program is writing binary data.
|>
|>Thanks a lot for taking the time to read all this. Any comments or suggestions
|>are most welcome. In case you know of any DEC Email address I might confront
|>with these questions, please tell me.
|>
|>As I don't expect these problems to be of general interest please send replies
|>to one of these Internet nodes:
|>
|>mkaspar@axp601.gsi.de (mkaspar@[140.181.98.71])
|>mkaspar@vscn.gsi.de (mkaspar@[140.181.97.141])
|>kaspar@IKF007.IKF.PHYSIK.UNI-FRANKFURT.DE (kaspar@[141.2.34.13])
|>
|>Anyone interested in replies should send me an Email, I will of course be happy
|>to forward any incomming mail.
|>
|>Thanks again, I really appreciate your help.
|>
|>Bye,
|>
|>Matthias Kaspar
|>
|>
|>
--
Ken Cowan, ZK2-3/Q8 cowan@rtl.enet.dec.com
Digital Equipment Corporation decwrl!rtl!cowan
110 Spit Brook Rd,
Nashua, NH 03062
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1994-01-18 20:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1994-01-14 9:44 DEC C / VAX C problems Matthias Kaspar
1994-01-14 18:21 ` Steve Hobbs
1994-01-18 20:11 ` Ken Cowan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox