Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
119 changes: 119 additions & 0 deletions COBOL/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# COBOL Parallel Research Kernels Makefile
#
# This makefile builds COBOL implementations of PRK benchmarks using GNU COBOL
#

# GNU COBOL compiler
COBC := cobc

# Compiler flags for optimization
COBCFLAGS := -O3 -x

# Default target
all: nstream transpose p2p dgemm

# Build nstream benchmark
nstream: nstream.cob
$(COBC) $(COBCFLAGS) -o nstream nstream.cob

# Build transpose benchmark
transpose: transpose.cob
$(COBC) $(COBCFLAGS) -o transpose transpose.cob

# Build p2p benchmark
p2p: p2p.cob
$(COBC) $(COBCFLAGS) -o p2p p2p.cob

# Build dgemm benchmark
dgemm: dgemm.cob
$(COBC) $(COBCFLAGS) -o dgemm dgemm.cob

# Run tests with default parameters
test: test-nstream test-transpose test-p2p test-dgemm

test-nstream: nstream
@echo "Testing nstream..."
./nstream 10 100000

test-transpose: transpose
@echo "Testing transpose..."
./transpose 100 10

test-p2p: p2p
@echo "Testing p2p..."
./p2p 10 50 50

test-dgemm: dgemm
@echo "Testing dgemm..."
./dgemm 10 100

# Run benchmarks with larger parameters
benchmark: benchmark-nstream benchmark-transpose benchmark-p2p benchmark-dgemm

benchmark-nstream: nstream
@echo "Benchmarking nstream..."
./nstream 10 1000000

benchmark-transpose: transpose
@echo "Benchmarking transpose..."
./transpose 500 10

benchmark-p2p: p2p
@echo "Benchmarking p2p..."
./p2p 10 200 200

benchmark-dgemm: dgemm
@echo "Benchmarking dgemm..."
./dgemm 10 200

# Clean build artifacts
clean:
rm -f nstream transpose p2p dgemm

# Install GNU COBOL (requires package manager)
install-cobol-ubuntu:
@echo "Installing GNU COBOL on Ubuntu..."
sudo apt-get update
sudo apt-get install -y gnucobol

install-cobol-macos:
@echo "Installing GNU COBOL on macOS via Homebrew..."
brew install gnu-cobol

install-cobol-fedora:
@echo "Installing GNU COBOL on Fedora..."
sudo dnf install -y gnucobol

# Check GNU COBOL installation
check-cobol:
@echo "Checking GNU COBOL installation..."
@which cobc >/dev/null 2>&1 && echo "GNU COBOL found at: $$(which cobc)" || echo "GNU COBOL not found"
@cobc --version 2>/dev/null || echo "GNU COBOL version check failed"

# Help target
help:
@echo "COBOL PRK Makefile"
@echo ""
@echo "Targets:"
@echo " all - Build all benchmarks"
@echo " nstream - Build nstream benchmark"
@echo " transpose - Build transpose benchmark"
@echo " p2p - Build p2p benchmark"
@echo " dgemm - Build dgemm benchmark"
@echo " test - Run tests with small parameters"
@echo " benchmark - Run benchmarks with larger parameters"
@echo " clean - Remove build artifacts"
@echo " install-cobol-* - Install GNU COBOL (ubuntu/macos/fedora)"
@echo " check-cobol - Check GNU COBOL installation"
@echo " help - Show this help message"
@echo ""
@echo "Requirements:"
@echo " GNU COBOL (cobc) compiler"
@echo ""
@echo "Usage examples:"
@echo " make all"
@echo " make test"
@echo " ./nstream 10 100000"
@echo " ./transpose 100 10"

.PHONY: all test benchmark clean install-cobol-ubuntu install-cobol-macos install-cobol-fedora check-cobol help test-nstream test-transpose test-p2p test-dgemm benchmark-nstream benchmark-transpose benchmark-p2p benchmark-dgemm
189 changes: 189 additions & 0 deletions COBOL/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
# COBOL Parallel Research Kernels

This directory contains COBOL implementations of the Parallel Research Kernels (PRK) benchmarks using GNU COBOL (GnuCOBOL).

## Benchmarks

### Available Benchmarks

1. **nstream** - STREAM triad: `A = B + scalar*C`
- Tests memory bandwidth with vector operations
- Usage: `./nstream <iterations> <vector_length>`

2. **transpose** - Matrix transpose: `B = A^T`
- Tests efficiency of matrix transposition
- Usage: `./transpose <matrix_order> <iterations>`

3. **p2p** - Pipeline execution on 2D grid
- Tests stencil computation patterns
- Usage: `./p2p <iterations> <grid_dim1> <grid_dim2>`

4. **dgemm** - Dense matrix-matrix multiplication: `C += A × B`
- Tests floating-point computation performance
- Usage: `./dgemm <iterations> <matrix_order>`

## Prerequisites

### GNU COBOL Installation

#### macOS (via Homebrew)
```bash
brew install gnu-cobol
```

#### Ubuntu/Debian
```bash
sudo apt-get update
sudo apt-get install gnucobol
```

#### Fedora/RHEL/CentOS
```bash
sudo dnf install gnucobol
# or on older systems:
# sudo yum install gnucobol
```

#### From Source
```bash
# Download from https://sourceforge.net/projects/gnucobol/
wget https://sourceforge.net/projects/gnucobol/files/gnucobol/3.2/gnucobol-3.2.tar.xz
tar -xf gnucobol-3.2.tar.xz
cd gnucobol-3.2
./configure
make
sudo make install
```

### Verification
```bash
cobc --version
```

## Building and Running

### Build All Benchmarks
```bash
make all
```

### Build Individual Benchmarks
```bash
make nstream
make transpose
make p2p
make dgemm
```

### Run Tests (Small Parameters)
```bash
make test
```

### Run Benchmarks (Larger Parameters)
```bash
make benchmark
```

### Individual Test Examples
```bash
# STREAM triad with 10 iterations on vectors of length 100,000
./nstream 10 100000

# Matrix transpose of 100x100 matrix with 10 iterations
./transpose 100 10

# Pipeline on 50x50 grid with 10 iterations
./p2p 10 50 50

# Matrix multiplication of 100x100 matrices with 10 iterations
./dgemm 10 100
```

## Implementation Notes

### COBOL Language Features Used

- **Fixed-point arithmetic** with `COMP-3` (packed decimal) for precision
- **Multi-dimensional arrays** with `OCCURS` clauses
- **Indexed access** for array operations
- **Intrinsic functions** for mathematical operations
- **Command-line argument processing**

### Array Size Limitations

The implementations use statically allocated arrays with these maximum sizes:
- **nstream**: Up to 1,000,000 elements per vector
- **transpose**: Up to 1,000×1,000 matrices
- **p2p**: Up to 500×500 grids
- **dgemm**: Up to 300×300 matrices

These limits can be increased by modifying the `OCCURS` clauses in the source files, but may require more memory.

### Performance Considerations

1. **Compilation**: Use `-O3` for optimization
2. **Memory**: COBOL uses significant memory for large arrays
3. **Precision**: Uses packed decimal for numerical stability
4. **Timing**: Uses `CURRENT-DATE` function (limited precision)

### COBOL-Specific Adaptations

- **Array indexing**: COBOL uses 1-based indexing (converted from 0-based C)
- **Variable naming**: Uses COBOL naming conventions with hyphens
- **Error handling**: Uses COBOL `STOP RUN` for error conditions
- **I/O**: Uses `DISPLAY` for output formatting

## Troubleshooting

### Common Issues

1. **"cobc: command not found"**
- Install GNU COBOL using package manager or from source

2. **Compilation errors about array sizes**
- Reduce the problem size or increase array limits in source code

3. **Runtime errors with large arrays**
- Check available system memory
- Reduce array sizes in the benchmark parameters

4. **Timing precision issues**
- COBOL's `CURRENT-DATE` has limited precision for very fast operations
- Use larger problem sizes for meaningful timing results

### Platform-Specific Notes

- **macOS**: GNU COBOL works well with Homebrew installation
- **Linux**: Package manager installations are generally reliable
- **Windows**: Consider using WSL or Cygwin for GNU COBOL

## Validation

Each benchmark includes validation routines that check:
- Computational correctness using reference checksums
- Numerical precision within acceptable tolerances
- Proper algorithm implementation

Success is indicated by "Solution validates" message.

## Performance Expectations

COBOL performance characteristics:
- **Strengths**: Excellent decimal arithmetic precision, robust I/O
- **Limitations**: Generally slower than compiled C/Fortran for numerical computing
- **Use case**: Demonstrates algorithm implementation in business-oriented language

## Contributing

When modifying the COBOL implementations:
1. Maintain COBOL coding standards and conventions
2. Keep array size limits reasonable for typical systems
3. Preserve numerical accuracy and validation routines
4. Update documentation for any parameter changes

## References

- [GNU COBOL Documentation](https://gnucobol.sourceforge.io/)
- [COBOL Language Reference](https://www.ibm.com/docs/en/cobol-zos)
- [Parallel Research Kernels](https://github.com/ParRes/Kernels)
Loading