ok@quintus (09/28/88)
Today I received a rather irritating piece of E-mail from someone following up the great Fortran-vs-{C,PL/I,Uncle Tom Cobleigh and all} debate. His claim that malloc() is not a standard part of C I think we can dismiss, and the claim that the NAG library is a de facto part of standard Fortran will probably surprise the Numerical Algorithms Group. But a claim more relevant to comp.lang.fortran was that pointers are *already* "standard practice" in Fortran. Is this true? Of the Fortran compilers I have access to, one has pointers, in the form POINTER /integer variable/ based variable, ..., based variable which is like the PL/I declaration DECLARE 1 not_named_in_fortran 2 based variable ... 2 based variable BASED pointer; except that the pointer is declared as an _integer_ variable (can you believe it?). Is this how other Fortrans having pointers do it?
rchrd@well.UUCP (Richard Friedman) (10/06/88)
The CRAY compiler CFT has a POINTER syntax that is very useful: POINTER (P2XYZ,XYZ(100) ) COMMON //BLOCK(1000000) ... P2XYZ= LOC(BLOCK) + NSIZE ... XYZ(K) = ... Here the POINTER statement defines P2XYZ as a pointer variable for the "pointee"XYZ, which is a 1-dim array. THe LOC function returns the address of its argument. Note that the CRAY is not a virtual memory machine, so LOC returns an actual memory address. POINTERS and LOC are typically used in engineering codes on the Cray to apportion COMMON dynamically. E.g., the size of arrays in common may be determined by input data. -- ...Richard Friedman [rchrd] uucp: {ucbvax,lll-lcc,ptsfa,hplabs}!well!rchrd - or - rchrd@well.uucp
ok@quintus.uucp (Richard A. O'Keefe) (10/07/88)
In article <7306@well.UUCP> rchrd@well.UUCP (Richard Friedman) writes: >The CRAY compiler CFT has a POINTER syntax that is very useful: > POINTER (P2XYZ,XYZ(100) ) > COMMON //BLOCK(1000000) > ... > P2XYZ= LOC(BLOCK) + NSIZE > ... > XYZ(K) = ... In Apollo Fortran this would be INTEGER P2XYZ POINTER /P2XYZ/ XYZ(100) but otherwise similar. What is the data type of P2XYZ in CFT?
rchrd@well.UUCP (Richard Friedman) (10/11/88)
For CFT on CRAY: The data type of a POINTER variable is implied INTEGER. The "pointee" can be any type. -- ...Richard Friedman [rchrd] uucp: {ucbvax,lll-lcc,ptsfa,hplabs}!well!rchrd - or - rchrd@well.uucp
khb%chiba@Sun.COM (Keith Bierman - Sun Tactical Engineering) (02/10/89)
In article <7232@june.cs.washington.edu> david@uw-june.UUCP (David Callahan) writes: >From comp.software-eng, >In article <1328@dsacg3.UUCP> vfm6066@dsacg3.UUCP (John A. Ebersold) writes: >... >I understand that Cray supports some flavor of pointer: integer >variables can be used to define the base of an array. Sort-of C-ish >really but without structures. Anyone have experience with >these? Does the lack of typing on the variables used as pointers >present a problem? Have other vendors provided pointer extensions? Sun and DEC (among others) have both pointers and structures. Use of pointers is _very_ bad for optimization. Personally I am not wild about putting them in....since they are there they will be used...and performance will suffer...then... well you get the picture. > >Fortran 8x has structures, but not pointers. > Wrong. Fortran88 (as ordained by WG5) has them. X3J3 has not produced the ANSI equivalent of the WG5 document (sort of strange since X3J3 wrote the document which WG5 hath ordained...but life can be strange :>) >I have heard it argued that "Fortran programmers need dynamically >allocated arrays, not pointers", but that seems to me to >be only one use for pointers. Does anyone know what some of the >pointer proposals were? Perhaps someone has the text(s) on line. I don't. You are correct that dynamically allocated arrays are only one use (and one which does _not_ require pointers!), however it is the _primary_ use in scientific programs....and as mentioned above pointers cause optimizers real, real, very bad, grief. cheers. khb Keith H. Bierman It's Not My Fault ---- I Voted for Bill & Opus
stein-c@acsu.buffalo.edu (Craig Steinberger) (02/05/91)
Hey Kids! I am trying to use pointers in SunOS 4.1 Fortran. Below are two code segments, and the output from each. Can anyone with experience tell me what is happening and what I did wrong? This program writes a number equal to the index of the array into each array position, i.e. a(3,2,1)=321.0 It then writes it out to a file. program writeme real a(3,3,3) do 12 i=1,3 do 11 j=1,3 do 10 k=1,3 a(i,j,k)=100.*float(i)+10.*float(j)+float(k) 10 continue 11 continue 12 continue write(1,*)(((a(i,j,k),i=1,3),j=1,3),k=1,3) And the output: 111.000 211.000 311.000 121.000 221.000 321.000 131.000 231.000 331.000 112.000 212.000 312.000 122.000 222.000 322.000 132.000 232.000 332.000 113.000 213.000 313.000 123.000 223.000 323.000 133.000 233.000 333.000 OK, so far so good. Now here's a program to read it back in. It then writes the same thing right out again. program readme pointer(pa, a) real a(1,1,*) size=27*8 pa=malloc(size) pia=malloc(size) read(1,*)(((a(i,j,k),i=1,3),j=1,3),k=1,3) write(2,*)(((a(i,j,k),i=1,3),j=1,3),k=1,3) Here is the output from that: 111.000 112.000 113.000 112.000 113.000 123.000 113.000 123.000 133.000 112.000 113.000 123.000 113.000 123.000 133.000 123.000 133.000 233.000 113.000 123.000 133.000 123.000 133.000 233.000 133.000 233.000 333.000 Now, obviously either I screwed up or I don't understand how the pointer concept works in FORTRAN, (Sun Fortran to be specific). My suspicion is that I am off by one somehow. Can anyone help? -- Craig Steinberger stein-c@eng.buffalo.edu SUNY at Buffalo, Computational Fluid Dynamics Lab
khb@chiba.Eng.Sun.COM (Keith Bierman fpgroup) (02/05/91)
Check out the examples (#4 seems apt) in the Reference Guide. The syntax and sematics are quite similar to Cray, so you could get by with their docs (I think). Here is what I did to your code: program readme pointer(pa, a) integer size ! you meant this, didn't you real a size=27*4 ! real is 4, not 8 bytes pa=malloc(size) call sub(a,3) ! we don't have a proper way to adjust shape here end subroutine sub(array,idim) ! generally array,maxi,maxj, maxk real array(idim,idim,idim) ! here we establish shape read(1,*)(((array(i,j,k),i=1,idim),j=1,idim),k=1,idim) write(2,*)(((array(i,j,k),i=1,idim),j=1,idim),k=1,idim) end and it runs diff fort.1 fort.2 returns silently .... the files match. -- ---------------------------------------------------------------- Keith H. Bierman kbierman@Eng.Sun.COM | khb@chiba.Eng.Sun.COM SMI 2550 Garcia 12-33 | (415 336 2648) Mountain View, CA 94043
wang@math.ufl.edu (02/07/91)
In article <57829@eerie.acsu.Buffalo.EDU>, stein-c@acsu.buffalo.edu
(Craig Steinberger) raised a question about the concept of FORTRAN
pointers. Can anyone tell us more about it?