10
0
mirror of https://gitlab.com/scemama/EZFIO.git synced 2024-12-22 12:23:34 +01:00

Merge pull request #10 from scemama/master

Add hostname in temporary filename (problem on clusters)
This commit is contained in:
Anthony Scemama 2017-07-11 23:00:28 +02:00 committed by GitHub
commit 4b4fad1a00
11 changed files with 135 additions and 91 deletions

View File

@ -4,7 +4,7 @@ EZFIO_ROOT=$( cd $(dirname "${BASH_SOURCE}")/.. ; pwd -P )
function _ezfio_py() function _ezfio_py()
{ {
python ${EZFIO_ROOT}/Python/ezfio.py $@ python "${EZFIO_ROOT}/Python/ezfio.py" $@
} }
@ -84,11 +84,11 @@ function _ezfio_set_file()
{ {
_require_first_argument $@ || return 1 _require_first_argument $@ || return 1
if [[ ! -d $1 ]] if [[ ! -d "$1" ]]
then then
mkdir -p $1 || return 1 mkdir -p "$1" || return 1
fi fi
export EZFIO_FILE=$1 export EZFIO_FILE="$1"
_ezfio_info "Set file ${EZFIO_FILE}" _ezfio_info "Set file ${EZFIO_FILE}"
return 0 return 0
} }
@ -106,12 +106,12 @@ function _ezfio_has()
_require_ezfio_file || return 1 _require_ezfio_file || return 1
_require_first_argument $@ || return 1 _require_first_argument $@ || return 1
if [[ ! -d ${EZFIO_FILE}/${1,,} ]] if [[ ! -d "${EZFIO_FILE}/${1,,}" ]]
then then
return 1 return 1
fi fi
if [[ -z $2 ]] if [[ -z "$2" ]]
then then
return 0 return 0
fi fi
@ -123,14 +123,14 @@ function _ezfio_get()
{ {
_require_ezfio_file || return 1 _require_ezfio_file || return 1
if [[ -z $1 ]] if [[ -z "$1" ]]
then then
ls ${EZFIO_FILE} && return 0 || return 1 ls ${EZFIO_FILE} && return 0 || return 1
fi fi
if [[ -z $2 ]] if [[ -z "$2" ]]
then then
ls ${EZFIO_FILE}/${1,,} && return 0 || return 1 ls "${EZFIO_FILE}/${1,,}" && return 0 || return 1
fi fi
_ezfio_py get $@ && return 0 || return 1 _ezfio_py get $@ && return 0 || return 1
@ -142,11 +142,11 @@ function _ezfio_set()
_require_first_argument $@ || return 1 _require_first_argument $@ || return 1
_require_second_argument $@ || return 2 _require_second_argument $@ || return 2
if [[ -z $3 ]] if [[ -z "$3" ]]
then then
_ezfio_py set $@ || return 1 _ezfio_py set $@ || return 1
else else
echo $3 | _ezfio_py set $1 $2 || return 1 echo "$3" | _ezfio_py set "$1" "$2" || return 1
fi fi
return 0 return 0
} }

0
C/.empty Normal file
View File

View File

@ -28,7 +28,7 @@ include make.config
.PHONY: default clean veryclean archive .PHONY: default clean veryclean archive
default: make.config default: make.config
cd src && $(MAKE) cd src && BUILD_SYSTEM=make $(MAKE)
clean: clean:
- bash -c "[[ -f lib/libezfio.a ]] && rm $$PWD/lib/*" - bash -c "[[ -f lib/libezfio.a ]] && rm $$PWD/lib/*"

View File

@ -37,7 +37,7 @@ def main():
f_name = f[4:] f_name = f[4:]
try: try:
exec """d['%s'] = ezfio.%s"""%(f_name,f_name) exec """d['%s'] = ezfio.%s"""%(f_name,f_name)
except: except IOError:
if do_verbose: if do_verbose:
print "%-40s [%5s]"%(f_name, "Empty") print "%-40s [%5s]"%(f_name, "Empty")
else: else:

View File

@ -26,7 +26,7 @@ d_default = {
"FCFLAGS" : '-O2', "FCFLAGS" : '-O2',
"RANLIB" : 'ranlib', "RANLIB" : 'ranlib',
"AR" : 'ar', "AR" : 'ar',
"NINJA" : 'ninja', "BUILD_SYSTEM" : 'make'
} }
CONFIG_FILES=' '.join([ os.path.join("config",x) for x in os.listdir('config') if x != '.empty']) CONFIG_FILES=' '.join([ os.path.join("config",x) for x in os.listdir('config') if x != '.empty'])
@ -112,7 +112,7 @@ rule build_libezfio_a
description = Building libezfio.a description = Building libezfio.a
rule build_libezfio_irp_a rule build_libezfio_irp_a
command = cp lib/libezfio.a lib/libezfio_irp.a ; {AR} dv lib/libezfio_irp.a irp_stack.irp.o > /dev/null ; {RANLIB} lib/libezfio_irp.a command = cp lib/libezfio.a lib/libezfio_irp.a ; {RANLIB} lib/libezfio_irp.a
description = Building libezfio_irp.a description = Building libezfio_irp.a
rule build_python rule build_python
@ -141,5 +141,4 @@ build Ocaml/ezfio.ml: build_ocaml | lib/libezfio.a
if __name__ == '__main__': if __name__ == '__main__':
create_build_ninja()
create_build_ninja()

View File

@ -1,60 +1,71 @@
# EZFIO is an automatic generator of I/O libraries .EXPORT_ALL_VARIABLES:
# Copyright (C) 2009 Anthony SCEMAMA, CNRS
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Anthony Scemama
# LCPQ - IRSAMC - CNRS
# Universite Paul Sabatier
# 118, route de Narbonne
# 31062 Toulouse Cedex 4
# scemama@irsamc.ups-tlse.fr
DEFAULT_TARGET: all
include ../make.config include ../make.config
export
include irpf90.make # Dark magic below modify with caution!
# "You are Not Expected to Understand This"
# .
# /^\ .
# /\ "V",
# /__\ I O o
# //..\\ I .
# \].`[/ I
# /l\/j\ (] . O
# /. ~~ ,\/I .
# \\L__j^\/I o
# \/--v} I o .
# | | I _________
# | | I c(` ')o
# | l I \. ,/
# _/j L l\_! _//^---^\\_
irpf90.make: $(wildcard *.irp.f) ../config/*
$(IRPF90)
include ../version ifeq ($(BUILD_SYSTEM),ninja)
BUILD_FILE=IRPF90_temp/build.ninja
IRPF90FLAGS += -j
else ifeq ($(BUILD_SYSTEM),make)
BUILD_FILE=IRPF90_temp/build.make
BUILD_SYSTEM += -j
else
DUMMY:
$(error 'Wrong BUILD_SYSTEM: $(BUILD_SYSTEM)')
endif
define run_and_touch
$(BUILD_SYSTEM) -C $(dir $(1) ) -f $(notdir $(1) ) $(addprefix $(CURDIR)/, $(2)) && touch $(2)
endef
export PYTHONPATH:=$(CURDIR):$(PYTHONPATH)
.PHONY: static all .PHONY: static all
all: static ../Python/ezfio.py ../Ocaml/ezfio.ml all: static ../Python/ezfio.py ../Ocaml/ezfio.ml
static: ../lib/libezfio.a ../lib/libezfio_irp.a static: ../lib/libezfio.a ../lib/libezfio_irp.a
../lib/libezfio.a: IRPF90_temp/irpf90.a ../lib/libezfio.a: IRPF90_temp/irpf90.a
rm -f ../lib/libezfio.a rm -f ../lib/libezfio.a
$(AR) cru ../lib/libezfio.a $(OBJ1) cp IRPF90_temp/irpf90.a ../lib/libezfio.a
$(RANLIB) ../lib/libezfio.a $(RANLIB) ../lib/libezfio.a
#No more irp_stack
../lib/libezfio_irp.a: ../lib/libezfio.a ../lib/libezfio_irp.a: ../lib/libezfio.a
rm -f ../lib/libezfio_irp.a
cp ../lib/libezfio.a ../lib/libezfio_irp.a cp ../lib/libezfio.a ../lib/libezfio_irp.a
$(AR) dv ../lib/libezfio_irp.a irp_stack.irp.o
$(RANLIB) ../lib/libezfio_irp.a
../Python/ezfio.py: ../Python/ezfio.py: ../lib/libezfio.a
python create_python.py python create_python.py
../Ocaml/ezfio.ml: ../Ocaml/ezfio.ml: ../lib/libezfio.a
python create_ocaml.py python create_ocaml.py
IRPF90_temp/irpf90.a: $(BUILD_FILE)
$(call run_and_touch, $<, $@)
$(BUILD_FILE): $(shell find . -maxdepth 2 -path ./IRPF90_temp -prune -o -name '*.irp.f' -print) ../config/*
$(IRPF90) $(IRPF90FLAGS)
clean:
rm -f -- $(BUILD_FILE) $(shell find IRPF90_temp -type f \( -name "*.o" -o -name "*.mod" -name "*.a" \) -delete;)
rm -f ../lib/libezfio.a ../lib/libezfio_irp.a
veryclean: clean
rm -rf IRPF90_temp/ IRPF90_man/ irpf90_entities dist tags

View File

@ -27,7 +27,7 @@ format= {
'integer' : ["'(I20)'", "%20d"], 'integer' : ["'(I20)'", "%20d"],
'real' : ["'(E24.15)'","%24.15E"], 'real' : ["'(E24.15)'","%24.15E"],
'double precision': ["'(E24.15)'","%24.15E"], 'double precision': ["'(E24.15)'","%24.15E"],
'logical' : ["'(L)'","%c"], 'logical' : ["'(L1)'","%c"],
'character*(*)' : ["'(A)'","%s"] 'character*(*)' : ["'(A)'","%s"]
} }

View File

@ -40,6 +40,9 @@ print >>file_py, """
version = property(fset=None,fget=get_version) version = property(fset=None,fget=get_version)
"""%(v) """%(v)
file_c = open("../C/ezfio.h","w")
print >>file_c, c_header
import sys import sys
for group in groups.keys(): for group in groups.keys():
@ -77,6 +80,7 @@ for group in groups.keys():
'group': group, 'group': group,
'dims': strdims} 'dims': strdims}
print attributes%d print attributes%d
print >>file_c, attributes_c%d
print >>file_py, attributes_py%d print >>file_py, attributes_py%d
else: else:
d = { 'type': type, d = { 'type': type,
@ -96,6 +100,7 @@ for group in groups.keys():
'dims_py': dims_py, 'dims_py': dims_py,
'dims': dims } 'dims': dims }
print buffered%d print buffered%d
print >>file_c, buffered_c%d
print >>file_py, buffered_py%d print >>file_py, buffered_py%d
else: else:
dims_loop = '' dims_loop = ''
@ -142,5 +147,9 @@ for group in groups.keys():
'declar_loop' : declar_loop} 'declar_loop' : declar_loop}
print attributes_arr%d print attributes_arr%d
print >>file_py, attributes_arr_py%d print >>file_py, attributes_arr_py%d
print >>file_c, attributes_arr_c%d
print >>file_c, c_footer
file_py.close() file_py.close()
file_c.close()

View File

@ -239,38 +239,48 @@ end
#--------- #---------
attributes_c = """ attributes_c = """
void ezfio_set_%(group)s_%(var)s(%(type)s %(var)s) void ezfio_set_%(group)s_%(var)s(%(ctype)s %(var)s)
{ {
ezfio_set_%(group)s_%(var)s_(&%(var)s); ezfio_set_%(group)s_%(var)s_(&%(var)s);
} }
void ezfio_get_%(group)s_%(var)s(%(ctype)s *%(var)s)
{
ezfio_get_%(group)s_%(var)s_(%(var)s);
}
int ezfio_has_%(group)s_%(var)s()
{
ezfio_has_%(group)s_%(var)s_();
}
""" """
c_header = """ attributes_arr_c = """
#ifndef EZFIO_H void ezfio_set_%(group)s_%(var)s(%(ctype)s %(var)s)
#define EZFIO_H {
ezfio_set_%(group)s_%(var)s_(&%(var)s);
}
void ezfio_get_%(group)s_%(var)s(%(ctype)s *%(var)s)
{
ezfio_get_%(group)s_%(var)s_(%(var)s);
}
int ezfio_has_%(group)s_%(var)s()
{
ezfio_has_%(group)s_%(var)s_();
}
"""
calculated_c = attributes_c
c_header = """#ifndef EZFIO_H\n#define EZFIO_H
#include <string.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
"""
c_footer = """
#ifdef __cplusplus
}
#endif
#endif
"""
file_h = [c_header]
file_h +=[ """
void ezfio_set_file_(char* filename, long filename_size);
void ezfio_read_buffer_(int* indices,double* values, int* isize);
void ezfio_write_buffer_(int* indices,double* values, int* isize);
"""]
file_c = [ """
typedef struct typedef struct
{ {
@ -282,7 +292,7 @@ void ezfio_set_file(char* filename)
{ {
long len; long len;
len = strlen(filename); len = strlen(filename);
ezfio_set_file_(filename,mlen); ezfio_set_file_(filename,len);
} }
sparse ezfio_read_buffer(int isize) sparse ezfio_read_buffer(int isize)
@ -297,7 +307,15 @@ void ezfio_write_buffer(sparse data, int isize)
ezfio_write_buffer_(data.indices,data.values,&isize); ezfio_write_buffer_(data.indices,data.values,&isize);
} }
""" ] """
c_footer = """
#ifdef __cplusplus
}
#endif
#endif
"""

View File

@ -128,16 +128,16 @@ logical function exists(path)
character*(*) :: path character*(*) :: path
character*(32) :: V character*(32) :: V
inquire(file=trim(path)//'/.version',exist=exists) inquire(file=trim(path)//'/.version',exist=exists)
if (exists) then ! if (exists) then
open(libezfio_iunit,file=trim(path)//'/.version') ! open(libezfio_iunit,file=trim(path)//'/.version')
read(libezfio_iunit,*) V ! read(libezfio_iunit,*) V
close(libezfio_iunit) ! close(libezfio_iunit)
! integer :: char_to_version ! integer :: char_to_version
! if (char_to_version(V) > char_to_version(libezfio_version)) then ! if (char_to_version(V) > char_to_version(libezfio_version)) then
! call ezfio_error(irp_here, 'This file was generated with version '//trim(V)//& ! call ezfio_error(irp_here, 'This file was generated with version '//trim(V)//&
! ' but the current installed version is '//trim(libezfio_version)//'') ! ' but the current installed version is '//trim(libezfio_version)//'')
! endif ! endif
endif ! endif
end function end function
subroutine ezfio_set_file(filename_in) subroutine ezfio_set_file(filename_in)

View File

@ -23,14 +23,21 @@
! scemama@irsamc.ups-tlse.fr ! scemama@irsamc.ups-tlse.fr
BEGIN_PROVIDER [ integer, PID ] BEGIN_PROVIDER [ integer, PID ]
&BEGIN_PROVIDER [ character*(8), PID_str ] &BEGIN_PROVIDER [ character*(256), PID_str ]
implicit none implicit none
BEGIN_DOC BEGIN_DOC
! Current process ID ! Current process ID
END_DOC END_DOC
integer :: getpid integer :: getpid
character*(240) :: hostname
PID = getpid() PID = getpid()
write(PID_str,'(I8.8)') PID write(PID_str,'(I8.8)') PID
call HOSTNM(hostname)
write(PID_str,'(A,''.'',I8.8,X)') trim(hostname), PID
PID_str = trim(PID_str)
print *, PID_str
call sleep(1)
END_PROVIDER END_PROVIDER
logical function ezfio_exists(path) logical function ezfio_exists(path)
@ -75,7 +82,7 @@ subroutine libezfio_openz(filename,mode,err)
character*(*) :: filename, mode character*(*) :: filename, mode
character*(1024) :: fifo character*(1024) :: fifo
integer :: err integer :: err
fifo = trim(filename)//'.'//PID_str fifo = trim(filename)//'.'//trim(PID_str)
err=1 err=1
if (mode(1:1) == 'r') then if (mode(1:1) == 'r') then
@ -97,7 +104,7 @@ subroutine libezfio_closez(filename,mode)
END_DOC END_DOC
character*(*) :: filename, mode character*(*) :: filename, mode
character*(1024) :: fifo character*(1024) :: fifo
fifo = trim(filename)//'.'//PID_str fifo = trim(filename)//'.'//trim(PID_str)
if (mode(1:1) == 'w') then if (mode(1:1) == 'w') then
close(unit=libezfio_iunit) close(unit=libezfio_iunit)
call system('gzip -c < '//trim(fifo)//' > '//trim(filename)) call system('gzip -c < '//trim(fifo)//' > '//trim(filename))
@ -141,7 +148,7 @@ subroutine ezfio_write_%(type_short)s(dir,fil,dat)
if (libezfio_read_only) then if (libezfio_read_only) then
call ezfio_error(irp_here,'Read-only file.') call ezfio_error(irp_here,'Read-only file.')
endif endif
l_filename(1)=trim(dir)//'/.'//fil//'.'//PID_str l_filename(1)=trim(dir)//'/.'//fil//'.'//trim(PID_str)
l_filename(2)=trim(dir)//'/'//fil l_filename(2)=trim(dir)//'/'//fil
open(unit=libezfio_iunit,file=l_filename(1),form='FORMATTED',action='WRITE') open(unit=libezfio_iunit,file=l_filename(1),form='FORMATTED',action='WRITE')
write(libezfio_iunit,%(fmt)s) dat write(libezfio_iunit,%(fmt)s) dat
@ -216,7 +223,7 @@ subroutine ezfio_write_array_%(type_short)s(dir,fil,rank,dims,dim_max,dat)
if (libezfio_read_only) then if (libezfio_read_only) then
call ezfio_error(irp_here,'Read-only file.') call ezfio_error(irp_here,'Read-only file.')
endif endif
l_filename(1)=trim(dir)//'/.'//fil//PID_str//'.gz' l_filename(1)=trim(dir)//'/.'//fil//trim(PID_str)//'.gz'
l_filename(2)=trim(dir)//'/'//fil//'.gz' l_filename(2)=trim(dir)//'/'//fil//'.gz'
err = 0 err = 0