资源简介
仅可用于科研学习目的,切勿用于商业或论文发表。
代码片段和文件信息
/*
* Some functions callable from fortran to use shared memory
* wv 2011
* shmem stuff from Willem Vermin SARA
*/
#include
#include
#include
#include
#include
#include
/*
* get a shared memory segment
* input: size (fortran integer*8)
* output: shmem id
*/
void getshmem_(size_t *size int*id)
{
key_t key;
int shmflg;
int shmid;
key = IPC_PRIVATE;
shmflg = IPC_CREAT | IPC_EXCL | 0600 | SHM_NORESERVE ;
shmid = shmget(key *size shmflg);
if (shmid == -1)
{
fprintf(stderr“%s in %s: cannot create shared segment %ld \n“__FUNCTION____FILE__*size);
perror(0);
exit(1);
}
*id = shmid;
}
void getshmem_error_(size_t *size int*id)
{
key_t key;
int shmflg;
int shmid;
key = IPC_PRIVATE;
shmflg = IPC_CREAT | IPC_EXCL | 0600 | SHM_NORESERVE ;
shmid = shmget(key *size shmflg);
*id = shmid;
}
/*
* attach shared memory to a pointer
* input: shhmid: shared memory id
* output: address (fortran integer*8)
*/
void attachshmem_(int *shmid void **address)
{
void *shmaddr*r;
int shmflg;
shmflg = 0;
shmaddr = 0;
r = shmat(*shmid shmaddr shmflg);
if (r == (void*) -1)
{
fprintf(stderr“%s in %s: cannot get address of shared segment\n“__FUNCTION____FILE__);
perror(0);
exit(1);
}
*address = r;
}
/*
* detach shared memory from pointer
* input: address (fortran integer*8)
*/
void detachshmem_(void **address)
{
int r;
r = shmdt(*address);
if (r == -1)
{
fprintf(stderr“%s in %s:%d: cannot detach shared segment\n“__FUNCTION____FILE____LINE__);
perror(0);
exit(1);
}
}
/*
* destroy shared memory
* input: shmid: shared memory id
*/
void destroyshmem_(int *shmid)
{
struct shmid_ds buf;
int r = shmctl(*shmidIPC_RMID&buf);
if (r == -1)
{
fprintf(stderr“%s in %s:%d: cannot destroy shared segment\n“__FUNCTION____FILE____LINE__);
perror(0);
exit(1);
}
}
/*
* get a set of semaphores
* input: size
* output: semaphores id
*/
void getsem_(int *size int*id)
{
key_t key;
int semflg;
int semid;
int mysize;
int i rc;
short sarray[(*size)+1];
key = IPC_PRIVATE;
semflg = IPC_CREAT | IPC_EXCL | 0600;
semflg = IPC_CREAT | 0600;
mysize=(*size)+1 ;
/* here I have an odd problem: using *size+1 instead of mysize
sometimes failed
very odd some cross C-Fortran problem no idea */
semid = semget(key mysize semflg);
if (semid == -1)
{
perror(0);
fprintf(stderr“%s in %s: cannot create semaphores \n“__FUNCTION____FILE__);
fprintf(stderr“requested size was %d\n“ mysize);
exit(1);
}
/* ‘1‘ -- The shared memory segment is being used. */
/* ‘0‘ -- The shared memory segment is freed. */
/* the very first sempaphore can be used to loc all others
currently this is not entirely thread save and might fail if no barrier
is used before this lock since we do not
- 上一篇:《企业进销存管理系统》论文范例
- 下一篇:旅游网站 asp 毕业设计
相关资源
- vasp 使用手册 完整版
- 教学互动网站 毕业设计 源代码 asp
- 游戏发布站源代码.rar
- Vasp程序源代码
- asp新闻发布系统源代码
- 同学录网站系统源代码
- 利用vasp工具计算石墨烯的的电子结构
- 网吧管理系统源代码+论文
- ASP人才招聘系统论文及源代码
- VASP 5.4.4 Source Code
- 第一性原理计算软件VASP的LDA赝势文件
- p4vasp for windows install
- vasp 侯柱峰资料
- VASP 5.4.4
- vasp5.3.5.tar
- 汽车销售商城网站asp源代码
- 毕业答辩-ASP基于WEB购物系统(论文源
- 一个招标网站的整站源代码asp+access
- VASP赝势文件PAW PW91
- vasp软件包
- VASP 完整赝势库
- VASP赝势文件PAW PBE
- vaspkit.1.00.linux.x64.tar.gz
- 一个SLR,LR,LALR语法分析器源代码
- 图形化处理软件P4VASP
- 留言本是asp+access版本功能齐全,实用
- ASP毕业设计论文+源代码
- 网上问卷调查系统源代码
- asp图书管理系统源代码
-
vasp scf sc
ript (vasp自洽计算脚本)
评论
共有 条评论