Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //MatrixOp.x
- struct matrix{
- float n00;
- float n01;
- float n10;
- float n11;
- };
- struct doubleInput{
- struct matrix in0;
- struct matrix in1;
- char operation;
- };
- struct singleInput{
- struct matrix in;
- char operation;
- };
- program MATRIXOP_PROG{
- version MATRIXOP_VER{
- struct matrix ADD(doubleInput) = 1;
- } = 1;
- } = 0x2fffffff;
- //Client----------------------------------------------------------
- #include "matrixOp.h"
- //CLIENT
- struct matrix matrixOp_prog_1(char *host, struct matrix m0, struct matrix m1, char op, CLIENT *clnt){
- struct matrix *result;
- struct doubleInput din;
- if(op == 'a'){
- din.in0 = m0;
- din.in1 = m1;
- din.operation = op;
- result = add_1(&din, clnt);
- if(result == (float *) NULL) clnt_perror(clnt, "add failed");
- return &result;
- }
- }
- int main(int argc, char *argv[]){
- char *host;
- float m0_00, m0_01, m0_10, m0_11;
- float m1_00, m1_01, m1_10, m1_11;
- char operation;
- struct matrix m0;
- struct matrix m1;
- CLIENT *clnt;
- if(argc<2){
- printf("Specify host. Probably localhost");
- exit(1);
- }
- printf("Welcome to addition\n");
- printf("Enter m0_00:");
- scanf("%f", &m0_00);
- printf("Enter m0_01:");
- scanf("%f", &m0_01);
- printf("Enter m0_10:");
- scanf("%f", &m0_10);
- printf("Enter m0_11:");
- scanf("%f", &m0_11);
- m0.n00 = m0_00;
- m0.n01 = m0_01;
- m0.n10 = m0_10;
- m0.n11 = m0_11;
- printf("Enter m1_00:");
- scanf("%f", &m1_00);
- printf("Enter m1_01:");
- scanf("%f", &m1_01);
- printf("Enter m1_10:");
- scanf("%f", &m1_10);
- printf("Enter m1_11:");
- scanf("%f", &m1_11);
- m1.n00 = m1_00;
- m1.n01 = m1_01;
- m1.n10 = m1_10;
- m1.n11 = m1_11;
- operation = 'a';
- host = argv[1];
- clnt = clnt_create(host, MATRIXOP_PROG, MATRIXOP_VER, "udp");
- if(clnt==null){
- clnt_pcreateerror(host);
- exit(1);
- }
- struct matrix ans = matrixOp_prog_1(host, m0, m1, operation, clnt);
- printf("Answer: (%f, %f), (%f, %f)", ans->n00, ans->n01, ans->n10, ans->n11);
- clnt_destroy(clnt);
- exit(0);
- }
- //-----------------------------------------
- //#SERVER
- #include "matrixOp.h"
- struct matrix * add_1_svc(struct doubleInput in, struct svc_req *rqstp){
- struct matrix result;
- result.n00 = in.in0.n00 + in.in1.n00;
- result.n01 = in.in0.n01 + in.in1.n01;
- result.n10 = in.in0.n10 + in.in1.n10;
- result.n11 = in.in0.n11 + in.in1.n11;
- return &result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement