Program 5:CUDA 1 Parentheses Matching Due Tues 11-29-2016 Write a CUDA program t
ID: 3775315 • Letter: P
Question
Program 5:CUDA 1 Parentheses Matching Due Tues 11-29-2016 Write a CUDA program that will determine whether a given input of parentheses match Write the code for serial version Write a CUDA version that works across multiple MPs Both versions should read in a file of parentheses They will return True if the series matches and False of they don't Analyze Compare the running times of the serial version vs the GPU version Run for several different inputs Deliver Source code for serial and CUDA versions GraphExplanation / Answer
paranthesis.cu
#include < stdio.h >
#define max 50
void main()
{
//declaring variables
char stack[max],input[100];
int top,i;
top = -1;
printf(" Enter expression: ");
gets(input);
// processing each char
for(i=0; input[i] != ''; i++)
{
if( input[i]=='(' || input[i] =='[' || input[i] == '{' )
{
top++;
stack[top]= input[i];
}
else
if ( input[i] == ')' )
{
if( stack[top] == '(' )
top--;
}
else
{
printf("wrong Paranthesis input");
exit(0);
}
}
else
if ( input[i] == ']' )
{
if( stack[top] == '[' )
top--;
else
{
printf("wrong Paranthesis input");
exit(0);
}
}
else
if ( input[i] == '}' )
{
if( stack[top] == '{' )
top--;
else
{
printf("wrong Paranthesis input");
exit(0);
}
}
} // end for
if( top == -1 )
printf("Youe entered expression is balanced one. Good job!!");
else
printf("Youe entered expression is not balanced one. Try again!!");
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.