Saved in:
Bibliographic Details
Main Author: Christen, Patrik
Format: Preprint
Published: 2024
Subjects:
Online Access:https://arxiv.org/abs/2410.10022
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866916462977875968
author Christen, Patrik
author_facet Christen, Patrik
contents This study explores running times of different ways to program cellular automata in C and C++, i.e. looping through arrays by different means, the effect of structures and objects, and the choice of data structure (array versus vector in C++) and compiler (GNU gcc versus Apple clang). Using arrays instead of vectors, using pointers instead of array indices, using C instead of C++, and using structures and objects instead of primitive data types has little to negligible effects on the running time. Also, the choice of compiler has only a minor effect, except for simple update functions, in which case clang seems to find better ways to optimise it, especially for index-based access. If one is interested in multi-state cellular automata, structures and objects can be used without loss of performance in C and C++, respectively. The study supports the recommendation from practice to use vector in C++ and adds to it the use of index-based access for cellular automata. Future studies might investigate Apple's Metal shader or compiler optimisation, especially with respect to the update function.
format Preprint
id arxiv_https___arxiv_org_abs_2410_10022
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle Programming of Cellular Automata in C and C++
Christen, Patrik
Programming Languages
This study explores running times of different ways to program cellular automata in C and C++, i.e. looping through arrays by different means, the effect of structures and objects, and the choice of data structure (array versus vector in C++) and compiler (GNU gcc versus Apple clang). Using arrays instead of vectors, using pointers instead of array indices, using C instead of C++, and using structures and objects instead of primitive data types has little to negligible effects on the running time. Also, the choice of compiler has only a minor effect, except for simple update functions, in which case clang seems to find better ways to optimise it, especially for index-based access. If one is interested in multi-state cellular automata, structures and objects can be used without loss of performance in C and C++, respectively. The study supports the recommendation from practice to use vector in C++ and adds to it the use of index-based access for cellular automata. Future studies might investigate Apple's Metal shader or compiler optimisation, especially with respect to the update function.
title Programming of Cellular Automata in C and C++
topic Programming Languages
url https://arxiv.org/abs/2410.10022