Skip to content

Commit 382bfd1

Browse files
committed
Minimal Enzyme Example (No ImpactX)
1 parent 264ff61 commit 382bfd1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/main.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,22 @@
1717
# include <mpi.h>
1818
#endif
1919

20+
#include <stdio.h>
21+
extern double __enzyme_autodiff(void*, double);
22+
double square(double x) {
23+
return x * x;
24+
}
25+
double dsquare(double x) {
26+
// This returns the derivative of square or 2 * x
27+
return __enzyme_autodiff((void*) square, x);
28+
}
29+
2030

2131
int main(int argc, char* argv[])
2232
{
33+
for(double i=1; i<5; i++)
34+
printf("square(%f)=%f, dsquare(%f)=%f", i, square(i), i, dsquare(i));
35+
2336
#if defined(AMREX_USE_MPI)
2437
AMREX_ALWAYS_ASSERT(MPI_SUCCESS == MPI_Init(&argc, &argv));
2538
#endif

0 commit comments

Comments
 (0)