-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen-vscode.py
87 lines (75 loc) · 1.68 KB
/
gen-vscode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
import json
import sys
import os
import string
scriptpath = os.path.dirname(os.path.realpath(sys.argv[0]))
with open(scriptpath + '/mpi.json') as data_file:
mpi_interface = json.load(data_file)
IFACE="{"
for f in mpi_interface:
fd = mpi_interface[f]
rtype=""
if(f=="MPI_Wtime"):
rtype = "double"
else:
rtype = "int"
IFACE+= "\n\"" + f + "\": {\n"
IFACE+= "\t\"prefix\": [\""+f+"\"],\n"
IFACE+= "\t\"description\" : \"MPI " + f.replace("MPI_", "") + " Snippet\",\n"
IFACE+= "\t\"body\" : [ \"" + f + "("
for i in range(0, len(fd)):
arg=fd[i]
name = arg[1];
ctype = arg[0];
#ARRAY CASE
array=""
try:
idx=ctype.index("[")
except ValueError:
idx=-1
if idx!=-1:
array=ctype[idx:]
ctype=ctype[0:idx]
IFACE+=" ${" + str(i+1) + ":" + ctype + " " + name + array + "}"
if i < (len(fd) - 1):
IFACE += ","
IFACE+= ");\"]\n"
IFACE+="},\n"
#This is the static part
IFACE += """
"Main() MPI" : {
"prefix" : ["mainmpi", "mpimain", "mpi-main" ],
"description": "Generate a basic MPI program",
"body" : [
"#include <mpi.h>",
"",
"int main( int argc, char *argv[])",
"{",
"\\tint rank, size;",
"\\tMPI_Init(&argc, &argv);",
"\\tMPI_Comm_rank(MPI_COMM_WORLD, &rank);",
"\\tMPI_Comm_size(MPI_COMM_WORLD, &size);",
"\\t",
"\\t${1:printf(\\"Rank: %d/%d\\\\n\\", rank, size);}",
"\\t",
"\\tMPI_Finalize();",
"\\t",
"\\treturn 0;",
"}"
]},
"Comm Self": {
"prefix": ["cself", "CS"],
"description": "Expand to MPI_COMM_SELF",
"body" : "MPI_COMM_SELF"
},
"Comm World": {
"prefix": ["cworld", "CW"],
"description": "Expand to MPI_COMM_WORLD",
"body" : "MPI_COMM_WORLD"
},
"""
IFACE+="}\n"
f = open("./UltiSnips/c.json", "w" )
f.write( IFACE );
f.close()