PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Webinar

Calling varlist C routine from Fortran (corrupted stack?)

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
depietri



Joined: 26 Jul 2004
Posts: 3

PostPosted: Wed Sep 29, 2004 1:35 am    Post subject: Calling varlist C routine from Fortran (corrupted stack?) Reply with quote

Dear all

We are using pgf90 5.2-2 on dual Opteron 64bit-mode on SuSe 9.1 Professional.

Commnad line: "pgf90 -g ......"

In our application (www.cactuscode.org) we have f90 routing calling C routine with varlists arguments. For example we have on an f90 routine the following call:
Code:

       call CCTK_Reduce(ierr, cctkGH, -1, Reduction_Handle, &
             1, 107, rho_max, 1, VarIndex)

to the following C routine:
Code:

void CCTK_FCALL cctk_reduce_
     (int *fortranreturn,
      const cGH **GH,
      const int *proc,
      const int *operation_handle,
      const int *num_out_vals,
      const int *type_out_vals,
      void *out_vals,
      const int *num_in_fields,
      ... );

Now in the calling the argument got messed up and the stack got currupted. Infact this C routine in turns call:
Code:

int CCTK_Reduce(const cGH *GH,
                int proc,
                int operation_handle,
                int num_out_vals,
                int type_out_vals,
                void *out_vals,
                int num_in_fields, ...);

and after some "C" subcall a memory exeception is generated. The debuging session show that in the stack no trace of the Fortarn interface function "cctk_reduce_" is shown.

Rerunning the debugging session a traceing by hand the calling flow everything go well but "cctk_reduce_" receive a bad sequence of argument.

There are workaround for this problem ?

Thanky you for any suggestions
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6206
Location: The Portland Group Inc.

PostPosted: Wed Sep 29, 2004 9:56 am    Post subject: Problem only on Opterons Reply with quote

This is a problem that only occurs on Opterons when using Fortran to C with varargs. When you compile a C program on Opteron using varargs, the EAX register is expected to contain the number of XMM registers that will be used for the varargs. When you call a C function with varargs from Fortran the EAX register is not set since its not needed in Fortran. Since EAX contains garbage, the C varargs becomes corrupt.

To work around this problem is to use the x flag "-Mx,125,0x200" which will set EAX to zero before every call. Note that we generally do not release x flags to the public since they are for the compiler's internal use, new, or experimental. So the caveat to using this flag is that it has not been properly QA'd and is subject to change. However, I believe in this case we plan to give it a name in a future release.

-Mat
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group