forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SCC /64 refuses to compile C source file

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
mecej4



Joined: 31 Oct 2006
Posts: 1430

PostPosted: Thu Sep 10, 2020 3:00 am    Post subject: SCC /64 refuses to compile C source file Reply with quote

The C routine given below implements Marsaglia's KISS RNG. The C code uses unsigned integer arithmetic, so it is not easy to convert to Fortran.

SCC compiles it with no problems, except when /64 is used, in which case it issues a load of spurious error messages.

Code:
/* SUPRKISS32.c, period 5*2^1320481*(2^32-1) */
#ifdef LF
#define RANDOM_R8 random_r8_
#define INITKISS32 initkiss32_
#endif
#define BSIZE 41265
static unsigned long Q[BSIZE],indx=BSIZE,
   carry=362,xcng=1236789,xs=521288629;

#define CNG ( xcng=69609*xcng+123 ) /*Congruential*/
#define XS ( xs^=xs<<13,xs^=xs>>17,xs^=xs>>5 )/*Xorshift*/
#define SUPR ( indx<BSIZE ? Q[indx++] : refill() ) /*CMWC*/
#define KISS SUPR+CNG+XS

int refill( )
{int i; unsigned long z,h;
for(i=0;i<BSIZE;i++){
   h=(carry&1);
   z=((Q[i]<<9)>>1)+((Q[i]<<7)>>1)+(carry>>1);
   carry=(Q[i]>>23)+(Q[i]>>25)+(z>>31);
   Q[i]=~((z<<1)+h);
   }
indx=1; return (Q[0]);
}

#ifdef FTN95
extern "C"
#endif
   void RANDOM_R8(double *x, int *n){
   int i;
   for (i=0; i<*n; i++)x[i] = (KISS)/4294967296.0;
   }
#ifdef FTN95
extern "C"
#endif
void INITKISS32( ){
   unsigned long i;
   for(i=0;i<BSIZE;i++) Q[i]=CNG+XS;
   indx = 0;
   }


I have sometimes wondered why SCC insists on treating C code as if it were C++ code, and decorates routine names a la C++, forcing the user to add extern "C" to enable using the resulting OBJ with Fortran routines. When building 32-bit code, we can use another C compiler.

When building 64-bit code, there is no other C compiler that produces OBJs that slink64 can work with, so bugs in SCC /64 pose an insurmountable obstacle.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6592
Location: Salford, UK

PostPosted: Thu Sep 10, 2020 7:29 am    Post subject: Reply with quote

mecej4

We will take a look at this. The alternative may be to put the C code into a third party DLL.
Back to top
View user's profile Send private message AIM Address
mecej4



Joined: 31 Oct 2006
Posts: 1430

PostPosted: Thu Sep 10, 2020 8:11 am    Post subject: Reply with quote

Thanks, Paul. I already use that solution (building a DLL using a third-party compiler and linking FTN95 code with the DLL), but in this case there is a major inconvenience associated with doing so.

The Marsaglia algorithm employs a large static unsigned int Q[] array and other scalar variables, the contents of which (i.e., the state of the RNG) would need to be preserved between calls to the routine in the DLL. The MS linker provides ways to share data between a DLL and the caller, but does SLINK64 do so?

The alternative would be to move the static variables into the argument list of the DLL routine, but that also has disadvantages. The user would need to make sure to know the list of variables used in the DLL routine, as well as to declare and initialise them as necessary in the Fortran caller.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6592
Location: Salford, UK

PostPosted: Thu Sep 10, 2020 10:15 am    Post subject: Reply with quote

SLINK64 does not provide a way to share data.

I will get back to you when I have the report.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
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 © 2001, 2005 phpBB Group