public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Marco Atzeri <marco.atzeri@gmail.com>
To: cygwin@cygwin.com
Subject: Re: Shared memory handling for mixed C/FORTRAN program
Date: Wed, 08 Apr 2015 15:38:00 -0000	[thread overview]
Message-ID: <55254B67.10209@gmail.com> (raw)
In-Reply-To: <1999567694.2259208.1428493743005.JavaMail.yahoo@mail.yahoo.com>



On 4/8/2015 1:49 PM, Christoph Weise wrote:
> I am porting to cygwin a program in FORTRAN/C that relies on C routines to create a shared memory region allowing various independent FORTRAN routines to share data. Program compiles and runs ok on Linux with g77/gcc compilers. I am compiling on cygwin 1.7.33-2(0.280/5/3)with gfortran/gcc (4.8.3).
>
> One C routine creates the shared memory section of a user-defined size. This seems to work just fine, although I had to add two lines to the sys/shm.h file:
>
>
> #define SHM_R        0400        /* or S_IRUGO from <linux/stat.h> */
> #define SHM_W        0200        /* or S_IWUGO from <linux/stat.h> */

don't do that.

Instead use S_IRUSR, S_IWUSR and companions:

http://pubs.opengroup.org/onlinepubs/7908799/xsh/sysstat.h.html


>
> The shm library functions seem to return reasonable info (page size and address, for removal of the shm section).
>
>
> Each FORTRAN routine then calls a C routine to find the shared memory, with a C routine returning pointers to two positions in the section intended for different kinds of data:
>
>
>
> #define PAGESIZE 1024
>
> int findshm(char**pptr,  /* Address of the parameter pointer */
>             float**cptr)  /* Address of the data pointer */
>
> ....calls to shm library functions ....
>
> shmaddr =0;
> p =shmat(shmid,shmaddr,(SHM_R |SHM_W));
> *pptr =p;
> *cptr =(float*)(p +PAGESIZE);
> return npages;
>
>
>
>
>
> The calling FORTRAN code looks like this:
>
>
>
> integer pptr,cptr
> integer npages
> npages =findshm(pptr,cptr)
>
> Although the total size of the created memory section npages is ok, the amount of memory following cptr is too small on cygwin (but not in Linux) and the program crashes for larger datasets with
>
> Program received signal SIGSEGV:Segmentationfault -invalid memory reference.
>
> Thinking it might have to do with the different underlying data types for the pointers (integer vs char/float) in the C versus FORTRAN code, I tried changing the type definitions of the pointers within the FORTRAN routines to
>
> byte pptr
> real*4 cptr
>
> and it all compiles and runs, but gives exactly the same runtime error, and doesn't explain why the program works in Linux.
>
> The pointer cptr is passed to FORTRAN subroutines as
>
> real cbuf(*)
>
> Not sure what I can do at this point (what to look out for, where to get help), so input appreciated.
>
> --
> Problem reports:       http://cygwin.com/problems.html
> FAQ:                   http://cygwin.com/faq/
> Documentation:         http://cygwin.com/docs.html
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

  reply	other threads:[~2015-04-08 15:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-08 11:49 Christoph Weise
2015-04-08 15:38 ` Marco Atzeri [this message]
2015-04-09  7:58 ` Corinna Vinschen
2015-04-10 22:20 ` Christoph Weise
2015-04-11 10:18   ` Corinna Vinschen
2015-04-11 20:25 ` Christoph Weise
2015-04-12 11:23   ` Corinna Vinschen
2015-04-12 12:18     ` Corinna Vinschen
2015-04-13 11:00 ` Christoph Weise
2015-04-14  7:39   ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55254B67.10209@gmail.com \
    --to=marco.atzeri@gmail.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).