%md
# **RunC/C++codeonDatabricks**
This notebook shows how to compile C/C++ code and run it on a Spark cluster in Databricks.
Run C/C++ code on Databricks
This notebook shows how to compile C/C++ code and run it on a Spark cluster in Databricks.
Last refresh: Never
%md
### Setup:Write/CopyC/C++codetoDBFS.
Write/Copy your code to DBFS, so that later your code can be copied onto the Spark Driver and compiled there.
For this simple example, the program could have just been written directly to the local disk of the Spark Driver, but copying to DBFS first makes more sense if you have a large number of C/C++ files.
Setup: Write/Copy C/C++ code to DBFS.
Write/Copy your code to DBFS, so that later your code can be copied onto the Spark Driver and compiled there.
For this simple example, the program could have just been written directly to the local disk of the Spark Driver, but copying to DBFS first makes more sense if you have a large number of C/C++ files.
Last refresh: Never
// This is a very simple test programdbutils.fs.put("dbfs:/tmp/simple.c",
"""#include <stdio.h>int main (int argc, char *argv[]) {char str[100];while (1) {if (!fgets(str, 100, stdin)) {return 0;}printf("Hello, %s", str);}}""", true)
Wrote 182 bytes.
res0: Boolean = true
Command took1.33 seconds
// Verify the program was written over correctly.dbutils.fs.head("dbfs:/tmp/simple.c")
res1: String =
"
#include <stdio.h>
int main (int argc, char *argv[]) {
char str[100];
while (1) {
if (!fgets(str, 100, stdin)) {
return 0;
}
printf("Hello, %s", str);
}
}
"
Run C/C++ code on Databricks
This notebook shows how to compile C/C++ code and run it on a Spark cluster in Databricks.
Last refresh: Never