Skip to content

Pm0 5 #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a4c6193
Add import/export lists
Apr 8, 2024
0d09332
Import/Export lists
Apr 8, 2024
50a5739
Add if scope parameters
Apr 25, 2024
e2a9ef9
Remove call run_modes from sysdefs
Apr 29, 2024
b2aeb8c
New import/export system
May 10, 2024
7a0686f
Added split initialisation
Jun 5, 2024
a5859dc
More work on split initialisation
Jun 6, 2024
63567cf
Refactor keyword arguments
Jul 19, 2024
bc579fa
Refactor keyword argumentswq
Jul 19, 2024
72c144d
Closures and dot procs
Sep 10, 2024
b76a0df
New var and reference implementation
Mar 28, 2025
c196dcd
New implementation for loops
Apr 4, 2025
ccea621
Conditional context
Apr 22, 2025
230a7c7
Merge literal values into symbol table
Apr 25, 2025
b442abd
Restructure references
Apr 28, 2025
2a8c8e2
More reference refactoring
May 8, 2025
421ef72
Change LHS syntax
May 12, 2025
f95cb61
Multiple LHS
May 13, 2025
532d911
Assignments
May 14, 2025
def2c30
Implementation of .{}
May 15, 2025
f7ebaeb
Gates types
May 22, 2025
130b691
Test/check
May 29, 2025
e563cb3
Finding library files
Jun 6, 2025
c262d97
Updates to config
Jun 6, 2025
5183396
fmt operator
Jun 10, 2025
889315d
Poly type combiner
Jun 13, 2025
1cd7b63
Type inference for poly types
Jun 19, 2025
f38ab03
Type inference of recursive types
Jun 25, 2025
ce636f0
Basic assignment
Jul 2, 2025
9fe222e
Assignment and references
Jul 3, 2025
375ccb1
Non-distributed references
Jul 4, 2025
cac6a7e
PM__ref command
Jul 7, 2025
fd44afb
Keyword args fix and drop
Jul 11, 2025
34f35f4
Backprop
Jul 14, 2025
8b8d7a4
Backpropagation phase
Jul 18, 2025
53708c5
Keyword arguments and other changes copied over to pmc compiler
Aug 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 2 additions & 89 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,94 +1,7 @@
![ PM logo ](/PM-LOGO.png)
# PM Programming Language
# PM Programming Language -- version 0.5 development
## [www.pm-lang.org](http://www.pm-lang.org)

## Overview
This branch supports ongoing development of PM version 0.5

The PM Programming Language is designed to facilitate the creation
of numerical models on parallel systems. It combines concepts of
parallelisation and vectorisation into a unified model using a 'strand'
as a basic unit of parallelisation. A strand is a very lightweight
entity that does not require its own stack and can map to a single execution
of a loop body. Strands are used in both data and task parallelism and can communicate
with other strands, including those running on other nodes. PM uses a modified form of
the Partitioned Global Address Space approach which builds synchronisation into basic operations
and excludes race conditions.

The PM compiler currently cross-compiles to Fortran+MPI. More target language/library
combinations are planned, including Fortran-MPI-OpenMP and accelerator support (initially
via either OpenMP or OpenACC)

The PM interpreter uses a parallel virtual machine and is designed for debugging PM code.

The language specification (available in /doc) while incomplete in places, will give
a good view of the features of the version 0.4 of the language.

## Status

This is a pre-release version of the PM language. While syntax and semantics are now well
developed, there may be further changes to both in response to feedback.

The implementation is not yet fully free of bugs or unimplemented features. If you encounter
a problem, then please check the latest code on GitHub. If this does not work, then please
raise an issue.

## Contribution

This is an open source project and outside contributions are entirely welcome.

At this stage the most effective contributions are in the are of testing and
feedback on the language design and implementation.

A refactoring of compiler/interpreter source code is underway for version 0.5.
One goal of this will be to make the code more accessible to outside contributors.
In the meantime, bug-fix contributions to the source code by the brave are certainly welcome.


## Installation and use

This is an initial release of version 0.4 of the language. At the moment
the code is designed to be compiled and installed on a Linux system with
MPI. It should be possible to compile on other systems with MPI and Fortan.

To compile PM:

Make sure you have MPI installed and loaded and can run mpifort and mpirun

The current setup is developed on Fedora with gfortran and openmp. You
can edit pm/Makefile and pmc/Makefile to change compilers.

The code should be fairly portable. Portability issues may be addressed by
editing config/sysdep.f90 (read the comments)

To compile the interpreter:

cd pm

make clean

make

You can then run the interpreter (./pm --help for options)

mpirun the interpreter for distributed execution.

To compile PM-to-Fortran compiler:

cd pmc

make clean

make

To compile a PM program to Fortran use ./pmc (./pmc --help for options)

The pmc compiler does not use MPI.

The compiled code will appear as PMOUT.F90 and will need to be compiled using mpifort.

You can then mpirun the resulting executable.

Both compiler and interpreter expect PM source files to have a .pmm extension.


## Watch out for continuing updates.
163 changes: 123 additions & 40 deletions config/sysdep.f90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
!
! Released under the MIT License (MIT)
!
! Copyright (c) Tim Bellerby, 2019
! Copyright (c) Tim Bellerby, 2024
!
! Permission is hereby granted, free of charge, to any person obtaining a copy
! of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -35,11 +35,14 @@ module pm_sysdep
! ********* Error messages ****************
! Error messages in colour
logical:: pm_colour_messages=.true.
logical:: pm_bright_messages=.true.
logical:: pm_bold_messages=.true.
character(len=*),parameter:: pm_error_start_bright=achar(27)//'[91;1m'
character(len=*),parameter:: pm_error_start=achar(27)//'[31;1m'
character(len=*),parameter:: pm_error_end=achar(27)//'[39;22m'
character(len=*),parameter:: pm_loc_start=achar(27)//'[1m'
character(len=*),parameter:: pm_loc_end=achar(27)//'[22m'

! ********* File settings *****************
! Standard output
integer,parameter:: pm_stdout_unit=6
Expand All @@ -50,22 +53,30 @@ module pm_sysdep
! Suffix for input files
character(len=4),parameter:: pm_file_suffix='.pmm'

! Prefix for library files
character(len=15),parameter:: pm_file_prefix='/usr/lib/pm/lib'
! Environment variable holding location of library files
character(len=12),parameter:: pm_env_var='PM_LANG_LIBS'

! Directory separator (one character only)
character(len=1),parameter:: pm_file_dirsep='/'

! Path separator (one character only)
character(len=1),parameter:: pm_lib_path_sep=':'

! Maximum size of file name
integer,parameter:: pm_max_filename_size=4096

! Character value used to signal end of file
character(len=1),parameter:: pm_eof_char=achar(0)

! Default library path
character(len=22):: pm_default_lib_path='/usr/share/pm-lang/lib'
logical:: pm_default_lib_path_set=.true.

! ************ Compiler defaults ****************
integer,parameter:: pm_default_ftn_dims=15
logical,parameter:: pm_default_ftn_has_contiguous=.true.
integer,parameter:: pm_default_ftn_lines=255
integer,parameter:: pm_default_ftn_max_stack_array=10*1024*1024


! ************ Memory model *********************
Expand All @@ -80,13 +91,14 @@ module pm_sysdep

! Types used by memory model (block offsets,object sizes,bitmap flags)

! integer,parameter:: pm_p=kind(1) ! Pointer offsets, object types +
! flags (>~24 bits, typically int)
integer,parameter:: pm_p=8
! integer,parameter:: pm_p=kind(1) ! Pointer offsets, object types +
! flags (>~24 bits, typically int)

integer,parameter:: pm_p=8

integer,parameter:: pm_f=kind(1) ! Bitmap storage (integer word)
! On some systems int64 may
! improve things slightly
integer,parameter:: pm_f=kind(1) ! Bitmap storage (integer word)
! On some systems int64 may
! improve things slightly

! ********* Vector Virtual Machine ********

Expand Down Expand Up @@ -166,20 +178,50 @@ module pm_sysdep

! Long long integers - big enough to address any file
integer,parameter:: pm_lln=MPI_OFFSET_KIND


! Maximum arguments to a PM procedure (must be 2**m-1 for some m)
integer,parameter:: pm_max_args=31
character(len=3),parameter:: pm_maxargs_str=' 31'


contains

function pm_argc() result(n)
integer:: n
n=iargc()
end function pm_argc
function pm_argc() result(n)
integer:: n
n=command_argument_count()
end function pm_argc

subroutine pm_getarg(n,str)
integer,intent(in)::n
character(len=*):: str
call get_command_argument(n,str)
end subroutine pm_getarg

subroutine pm_get_env_var(varname,str,ok)
character(len=*):: varname,str
logical:: ok
integer:: status
call get_environment_variable(varname,str,status=status)
ok=status==0
end subroutine pm_get_env_var

subroutine pm_getarg(n,str)
integer,intent(in)::n
character(len=*):: str
call getarg(n,str)
end subroutine pm_getarg
!!$ function pm_argc() result(n)
!!$ integer:: n
!!$ n=iargc()
!!$ end function pm_argc
!!$
!!$ subroutine pm_getarg(n,str)
!!$ integer,intent(in)::n
!!$ character(len=*):: str
!!$ call getarg(n,str)
!!$ end subroutine pm_getarg

!!$ subroutine pm_get_env_var(varname,str,ok)
!!$ character(len=*):: varname,str
!!$ logical:: ok
!!$ call getenv(varname,str)
!!$ ok=str/=' '
!!$ end subroutine pm_get_env_var

function pm_isatty(l) result(ok)
integer,intent(in)::l
Expand All @@ -194,25 +236,66 @@ end function pm_isatty
! ok=pm_colour_messages
! end function pm_isatty

subroutine pm_module_filename(inbuffer,buffer)
character(len=*):: inbuffer,buffer
integer:: n,m
buffer=inbuffer
n=len_trim(buffer)
if(n>len(pm_file_suffix)) then
if(buffer(n-len(pm_file_suffix)+1:n)==pm_file_suffix) return
endif
if(buffer(1:4)=='lib.') then
m=len(pm_file_prefix)
buffer(m+1:m+n)=buffer(1:n)
buffer(1:m)=pm_file_prefix
endif
do m=1,n
if(buffer(m:m)=='.') then
buffer(m:m)=pm_file_dirsep
endif
enddo
buffer(n+1:n+len(pm_file_suffix))=pm_file_suffix
end subroutine pm_module_filename
subroutine pm_module_filename(inbuffer,buffer,lib_path_set,lib_path)
character(len=*),intent(in):: inbuffer,lib_path
character(len=*),intent(out):: buffer
logical,intent(in):: lib_path_set
integer:: n,m,i,tot,pathlen
logical:: ok
n=len_trim(inbuffer)
if(n>len(pm_file_suffix)) then
if(inbuffer(n-len(pm_file_suffix)+1:n)==pm_file_suffix) then
buffer=inbuffer
return
endif
endif
if(inbuffer(1:4)=='lib.'.and.lib_path_set) then
i=1
do
m=index(lib_path(i:),pm_lib_path_sep)
!!$ write(*,*) 'm=',m,trim(lib_path(i:m-1))
if(m==0) then
m=len_trim(lib_path)
else
m=m+i-2
endif
if(m>=i) then
pathlen=m-i+1
tot=pathlen+n-3
if(tot+len_trim(pm_file_suffix)>len(buffer)) then
if(m+2>len(lib_path)) exit
i=m+2
cycle
endif
buffer(1:pathlen)=lib_path(i:m)
do i=4,n
if(inbuffer(i:i)=='.') then
buffer(i+pathlen-3:i+pathlen-3)=pm_file_dirsep
else
buffer(i+pathlen-3:i+pathlen-3)=inbuffer(i:i)
endif
enddo
buffer(tot+1:)=pm_file_suffix
!!$ write(*,*) 'TRY:',trim(buffer)
inquire(file=trim(buffer),exist=ok)
if(ok) return
else
exit
endif
if(m+2>len(lib_path)) exit
i=m+2
end do
endif
do m=1,n
if(inbuffer(m:m)=='.') then
buffer(m:m)=pm_file_dirsep
else
buffer(m:m)=inbuffer(m:m)
endif
end do
if(n+len(pm_file_suffix)<=len(buffer)) then
buffer(n+1:)=pm_file_suffix
endif
end subroutine pm_module_filename

end module pm_sysdep
Loading