MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
failoverSCI.cpp
1 /*
2  Copyright (C) 2003-2006 MySQL AB
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include <ndb_global.h>
20 
21 #include "sisci_types.h"
22 #include "sisci_api.h"
23 #include "sisci_error.h"
24 //#include "sisci_demolib.h"
25 #include <NdbTick.h>
26 #include <NdbSleep.h>
27 #define NO_CALLBACK NULL
28 #define NO_FLAGS 0
29 #define DATA_TRANSFER_READY 8
30 
31 sci_error_t error;
32 sci_desc_t sdOne;
33 sci_desc_t sdTwo;
34 sci_local_segment_t localSegmentOne;
35 sci_local_segment_t localSegmentTwo;
36 sci_remote_segment_t remoteSegmentOne;
37 sci_remote_segment_t remoteSegmentTwo;
38 sci_map_t localMapOne;
39 sci_map_t localMapTwo;
40 sci_map_t remoteMapOne;
41 sci_map_t remoteMapTwo;
42 unsigned int localAdapterNo = 0;
43 unsigned int standbyAdapterNo = 1;
44 unsigned int localNodeId1;
45 unsigned int localNodeId2;
46 unsigned int remoteNodeId1 = 0;
47 unsigned int remoteNodeId2 = 0;
48 unsigned int localSegmentId;
49 unsigned int remoteSegmentId1;
50 unsigned int remoteSegmentId2;
51 unsigned int segmentSize = 8192;
52 unsigned int offset = 0;
53 unsigned int client = 0;
54 unsigned int server = 0;
55 unsigned int *localbufferPtr;
56 static int data;
57 static int interruptConnected=0;
58 
59 /*********************************************************************************/
60 /* U S A G E */
61 /* */
62 /*********************************************************************************/
63 
64 void Usage()
65 {
66  printf("Usage of shmem\n");
67  printf("shmem -rn <remote node-id> -client/server [ -adapterno <adapter no> -size <segment size> ] \n\n");
68  printf(" -rn : Remote node-id\n");
69  printf(" -client : The local node is client\n");
70  printf(" -server : The local node is server\n");
71  printf(" -adapterno : Local adapter number (default %d)\n", localAdapterNo);
72  printf(" -size : Segment block size (default %d)\n", segmentSize);
73  printf(" -help : This helpscreen\n");
74 
75  printf("\n");
76 }
77 
78 
79 /*********************************************************************************/
80 /* P R I N T P A R A M E T E R S */
81 /* */
82 /*********************************************************************************/
83 void PrintParameters(void)
84 {
85 
86  printf("Test parameters for %s \n",(client) ? "client" : "server" );
87  printf("----------------------------\n\n");
88  printf("Local node-id1 : %d\n",localNodeId1);
89  printf("Local node-id2 : %d\n",localNodeId2);
90  // printf("Remote node-id : %d\n",remoteNodeId);
91  printf("Local adapter no. : %d\n",localAdapterNo);
92  printf("Segment size : %d\n",segmentSize);
93  printf("----------------------------\n\n");
94 
95 }
96 
97 
98 /*********************************************************************************/
99 /* F I L L S E G M E N T W I T H D A T A */
100 /* */
101 /*********************************************************************************/
102 
103 sci_error_t GetLocalNodeId(Uint32 localAdapterNo, Uint32* localNodeId)
104 {
105  sci_query_adapter_t queryAdapter;
106  sci_error_t error;
107  unsigned int _localNodeId;
108 
109  queryAdapter.subcommand = SCI_Q_ADAPTER_NODEID;
110  queryAdapter.localAdapterNo = localAdapterNo;
111  queryAdapter.data = &_localNodeId;
112 
113  SCIQuery(SCI_Q_ADAPTER,&queryAdapter,NO_FLAGS,&error);
114 
115  *localNodeId=_localNodeId;
116 
117  return error;
118 }
119 
120 
121 
122 
123 
124 
125 sci_error_t SendInterrupt(sci_desc_t sd,
126  Uint32 localAdapterNo,
127  Uint32 localSciNodeId,
128  Uint32 remoteSciNodeId,
129  Uint32 interruptNo){
130 
131  sci_error_t error;
132  sci_remote_interrupt_t remoteInterrupt;
133  Uint32 timeOut = SCI_INFINITE_TIMEOUT;
134 
135  // Now connect to the other sides interrupt flag
136  do {
137  SCIConnectInterrupt(sd, &remoteInterrupt, remoteSciNodeId, localAdapterNo,
138  interruptNo, timeOut, NO_FLAGS, &error);
139  } while (error != SCI_ERR_OK);
140 
141  if (error != SCI_ERR_OK) {
142  fprintf(stderr, "SCIConnectInterrupt failed - Error code 0x%x\n", error);
143  return error;
144  }
145 
146  // Trigger interrupt
147  printf("\nNode %u sent interrupt (0x%x) to node %d\n",localSciNodeId, interruptNo, remoteSciNodeId);
148  SCITriggerInterrupt(remoteInterrupt, NO_FLAGS, &error);
149  if (error != SCI_ERR_OK) {
150  fprintf(stderr, "SCITriggerInterrupt failed - Error code 0x%x\n", error);
151  return error;
152  }
153 
154 
155  // Disconnect and remove interrupts
156  SCIDisconnectInterrupt(remoteInterrupt, NO_FLAGS, &error);
157  if (error != SCI_ERR_OK) {
158  fprintf(stderr, "SCIDisconnectInterrupt failed - Error code 0x%x\n", error);
159  return error;
160  }
161 
162  return error;
163 }
164 
165 
166 sci_error_t ReceiveInterrupt(sci_desc_t sd,
167  Uint32 localAdapterNo,
168  Uint32 localSciNodeId,
169  Uint32 interruptNo,
170  Uint32 timeout) {
171 
172  sci_error_t error;
173  sci_local_interrupt_t localInterrupt;
174  Uint32 timeOut = SCI_INFINITE_TIMEOUT;
175 
176  // Create an interrupt
177  SCICreateInterrupt(sd, &localInterrupt, localAdapterNo,
178  &interruptNo, 0, NULL, SCI_FLAG_FIXED_INTNO, &error);
179  if (error != SCI_ERR_OK) {
180  fprintf(stderr, "SCICreateInterrupt failed - Error code 0x%x\n", error);
181  return error;
182  }
183 
184 
185  // Wait for an interrupt
186  SCIWaitForInterrupt(localInterrupt, timeOut, NO_FLAGS, &error);
187 
188  printf("\nNode %u received interrupt (0x%x)\n", localSciNodeId, interruptNo);
189 
190  // Remove interrupt
191 
192  SCIRemoveInterrupt(localInterrupt, NO_FLAGS, &error);
193  if (error != SCI_ERR_OK) {
194  fprintf(stderr, "SCIRemoveInterrupt failed - Error code 0x%x\n", error);
195  return error;
196  }
197  return error;
198 }
199 
200 
201 sci_error_t FillSegmentWithData(unsigned int segmentSize, int reverse)
202 {
203  unsigned int i;
204  unsigned int nostores;
205 
206 
207  nostores = (segmentSize) / sizeof(unsigned int);
208 
209  /* Allocate buffer */
210 
211  localbufferPtr = (unsigned int*)malloc( segmentSize );
212  if ( localbufferPtr == NULL ) {
213  /*
214  * Unable to create local buffer - Insufficient memory available
215  */
216  return SCI_ERR_NOSPC;
217  }
218  if(reverse) {
219  /* Fill in the data into a local buffer */
220  printf("Filling forward order \n");
221  for (i=0;i<nostores;i++) {
222  localbufferPtr[i] = i;
223  }
224  }
225  else {
226  int temp=nostores;
227  printf("Filling reverse order \n");
228  for (i=0;i<nostores;i++) {
229  localbufferPtr[i] = temp-- ;
230 
231  }
232 
233  }
234 
235  return SCI_ERR_OK;
236 }
237 
238 
239 
240 
241 /*********************************************************************************/
242 /* P R I N T C L I E N T D A T A */
243 /* */
244 /*********************************************************************************/
245 
246 void PrintClientData(void)
247 {
248  unsigned int i;
249 
250  printf("\nClient data: ");
251  /* Print the first 20 entries in the segment */
252  for (i=0;i<20;i++) {
253  printf("%d ",localbufferPtr[i]);
254  }
255 
256  printf("\n");
257 }
258 
259 
260 /*********************************************************************************/
261 /* P R I N T S E R V E R D A T A */
262 /* */
263 /*********************************************************************************/
264 
265 void PrintServerData(volatile unsigned int *localMapAddr)
266 {
267 
268  unsigned int *buffer;
269  int i;
270 
271  // printf("\nServer data: ");
272  buffer = (unsigned int *)localMapAddr;
273 
274  /* Print the first 20 entries in the segment */
275  for (i=0; i< 20; i++) {
276 
277  printf("%d ",buffer[i]);
278  }
279  printf("\n");
280 
281 }
282 
283 
284 
285 /*********************************************************************************/
286 /* T R A N S F E R D A T A */
287 /* */
288 /*********************************************************************************/
289 
290 unsigned int TransferData(sci_map_t remoteMap,
291  volatile unsigned int *remoteSegmentAddr1,
292  volatile unsigned int *remoteSegmentAddr2,
293  unsigned int segmentSize)
294 
295 {
296 
297  volatile unsigned int *remoteBuffer1;
298  volatile unsigned int *remoteBuffer;
299  volatile unsigned int *remoteBuffer2;
300  static int times = 0;
301  sci_sequence_t sequence;
302  sci_error_t error;
303  unsigned int nostores;
304  unsigned int j;
305  sci_sequence_status_t sequenceStatus;
306 
307 
308  remoteBuffer1 = (volatile unsigned int *)remoteSegmentAddr1;
309  remoteBuffer2 = (volatile unsigned int *)remoteSegmentAddr2;
310  remoteBuffer=remoteBuffer1;
311 
312  /* 4-byte test only */
313  nostores = (segmentSize) / sizeof(unsigned int);
314 
315  /* Create a sequence for data error checking */
316  SCICreateMapSequence(remoteMapOne,&sequence,NO_FLAGS,&error);
317  if (error != SCI_ERR_OK) {
318  fprintf(stderr,"SCICreateMapSequence failed - Error code 0x%x\n",error);
319  return error;
320  }
321 
322 
323 
324  /* Fill in the data into a local buffer */
325  error = SendInterrupt(sdOne,localAdapterNo,localNodeId1,remoteNodeId1, DATA_TRANSFER_READY);
326 
327  error = FillSegmentWithData(segmentSize, 0);
328 
329  tryagain:
330  PrintServerData(localbufferPtr);
331  fprintf(stderr,"After recover \n");
332  while(1){
333 
334 
335  //data=0;
336 
337  if (error != SCI_ERR_OK) {
338  /*
339  * Unable to create local buffer - Insufficient memory available
340  */
341  printf( "Unable to create local buffer - Insufficient memory available\n" );
342 
343  return error;
344  }
345 
346  do {
347  /* Start data error checking */
348  sequenceStatus = SCIStartSequence(sequence,NO_FLAGS,&error);
349  } while (sequenceStatus != SCI_SEQ_OK) ;
350 
351 
352  /* Transfer data to remote node */
353  for (j=0;j<nostores;j++) {
354  remoteBuffer[j] = localbufferPtr[j];
355  }
356 
357  /* Check for error after data transfer */
358  sequenceStatus = SCICheckSequence(sequence,NO_FLAGS,&error);
359  if (sequenceStatus != SCI_SEQ_OK) {
360  fprintf(stderr,"Data transfer failed\n");
361  if(times==0) {
362  error = FillSegmentWithData(segmentSize, 1);
363 
364  SCICreateMapSequence(remoteMapTwo,&sequence,NO_FLAGS,&error);
365  if (error != SCI_ERR_OK) {
366  fprintf(stderr,"SCICreateMapSequence failed - Error code 0x%x\n",error);
367  return error;
368  return SCI_ERR_TRANSFER_FAILED;
369  }
370  }
371  else
372  {
373  error = FillSegmentWithData(segmentSize, 0);
374  /* Create a sequence for data error checking */
375  SCICreateMapSequence(remoteMapOne,&sequence,NO_FLAGS,&error);
376  if (error != SCI_ERR_OK) {
377  fprintf(stderr,"SCICreateMapSequence failed - Error code 0x%x\n",error);
378  return error;
379  return SCI_ERR_TRANSFER_FAILED;
380  }
381 
382  }
383  fprintf(stderr,"Recovery \n");
384  if(times==0)
385  remoteBuffer=remoteBuffer2;
386  else
387  remoteBuffer=remoteBuffer1;
388  times++;
389  printf("remotebuffer %p times %d\n", remoteBuffer, times);
390  goto tryagain;
391 
392  }
393  int timeout=0;
394  // error = SendInterrupt(sdOne,localAdapterNo,localNodeId1,remoteNodeId1, DATA_TRANSFER_READY);
395  // NdbSleep_MilliSleep(100);
396  //error = ReceiveInterrupt(sdOne,localAdapterNo,localNodeId1,DATA_TRANSFER_READY, timeout);
397 
398  }
399  /* Remove the Sequence */
400  SCIRemoveSequence(sequence,NO_FLAGS, &error);
401  if (error != SCI_ERR_OK) {
402  fprintf(stderr,"SCIRemoveSequence failed - Error code 0x%x\n",error);
403  return error;
404  }
405 
406  return SCI_ERR_OK;
407 }
408 
409 
410 /*********************************************************************************/
411 /* S H M E M C L I E N T N O D E */
412 /* */
413 /*********************************************************************************/
414 
415 unsigned int ShmemClientNode(void)
416 {
417 
418  volatile unsigned int *remoteMapAddr1;
419  volatile unsigned int *remoteMapAddr2;
420  printf("here?\n");
421 
422 
423  /* Create a segmentId */
424  remoteSegmentId1 = 1;//(remoteNodeId1 << 16) | localNodeId1;
425 
426  /* Connect to remote segment */
427 
428  printf("Connect to remote segment .... \n");
429  printf("segid = %d node %d \n",remoteSegmentId1, remoteNodeId1 );
430 
431  do {
432  SCIConnectSegment(sdOne,
433  &remoteSegmentOne,
434  remoteNodeId1,
435  remoteSegmentId1,
436  localAdapterNo,
437  NO_CALLBACK,
438  NULL,
439  SCI_INFINITE_TIMEOUT,
440  NO_FLAGS,
441  &error);
442 
443  } while (error != SCI_ERR_OK);
444 
445 
446  printf("connected\n");
447 
448  // remoteSegmentId2 = (remoteNodeId2 << 16) | localNodeId2;
449  // printf("segid = %d\n",remoteSegmentId2 );
450  printf("segid = %d node %d \n",remoteSegmentId1, remoteNodeId1 );
451  do {
452  SCIConnectSegment(sdTwo,
453  &remoteSegmentTwo,
454  remoteNodeId2,
455  remoteSegmentId1,
456  standbyAdapterNo,
457  NO_CALLBACK,
458  NULL,
459  SCI_INFINITE_TIMEOUT,
460  NO_FLAGS,
461  &error);
462 
463  } while (error != SCI_ERR_OK);
464 
465 
466 
467  printf("connected 3\n");
468  printf("Remote segment (id=0x%x) is connected.\n", remoteSegmentId2);
469 
470 
471  /* Map remote segment to user space */
472  remoteMapAddr1 = (unsigned int*)SCIMapRemoteSegment(remoteSegmentOne,&remoteMapOne,offset,segmentSize,NULL,NO_FLAGS,&error);
473  if (error == SCI_ERR_OK) {
474  printf("Remote segment (id=0x%x) is mapped to user space @ 0x%x. \n", remoteSegmentId1, remoteMapAddr1);
475  } else {
476  fprintf(stderr,"SCIMapRemoteSegment failed - Error code 0x%x\n",error);
477  return 0;
478  }
479 
480  remoteMapAddr2 = (unsigned int *)SCIMapRemoteSegment(remoteSegmentTwo,&remoteMapTwo,offset,segmentSize,NULL,NO_FLAGS,&error);
481  if (error == SCI_ERR_OK) {
482  printf("Remote segment (id=0x%x) is mapped to user space @ 0x%x. \n", remoteSegmentId2, remoteMapAddr2);
483  } else {
484  fprintf(stderr,"SCIMapRemoteSegment failed - Error code 0x%x\n",error);
485  return 0;
486  }
487 
488 
489  /* Start data transfer and error checking */
490  error = (sci_error_t)TransferData(remoteMapOne,remoteMapAddr1, remoteMapAddr2,segmentSize);
491  if (error == SCI_ERR_OK) {
492  printf("Data transfer done!\n\n");
493  } else {
494  fprintf(stderr,"Data transfer failed - Error code 0x%x\n\n",error);
495  return 0;
496  }
497 
498  /* Send an interrupt to remote node telling that the data transfer is ready */
499  error = SendInterrupt(sdOne,localAdapterNo,localNodeId1,remoteNodeId1, DATA_TRANSFER_READY);
500  if (error == SCI_ERR_OK) {
501  printf("\nInterrupt message sent to remote node\n");
502  } else {
503  printf("\nInterrupt synchronization failed\n");
504  return 0;
505  }
506 
507  PrintClientData();
508 
509  /* Unmap remote segment */
510  SCIUnmapSegment(remoteMapOne,NO_FLAGS,&error);
511  if (error == SCI_ERR_OK) {
512  printf("The remote segment is unmapped\n");
513  } else {
514  fprintf(stderr,"SCIUnmapSegment failed - Error code 0x%x\n",error);
515  return 0;
516  }
517 
518  SCIUnmapSegment(remoteMapTwo,NO_FLAGS,&error);
519  if (error == SCI_ERR_OK) {
520  printf("The remote segment is unmapped\n");
521  } else {
522  fprintf(stderr,"SCIUnmapSegment failed - Error code 0x%x\n",error);
523  return 0;
524  }
525  /* Disconnect segment */
526  SCIDisconnectSegment(remoteSegmentOne,NO_FLAGS,&error);
527  if (error == SCI_ERR_OK) {
528  printf("The segment is disconnected\n");
529  } else {
530  fprintf(stderr,"SCIDisconnectSegment failed - Error code 0x%x\n",error);
531  return 0;
532  }
533 
534  SCIDisconnectSegment(remoteSegmentTwo,NO_FLAGS,&error);
535  if (error == SCI_ERR_OK) {
536  printf("The segment is disconnected\n");
537  } else {
538  fprintf(stderr,"SCIDisconnectSegment failed - Error code 0x%x\n",error);
539  return 0;
540  }
541 
542 
543  return 1;
544 }
545 
546 
547 /*********************************************************************************/
548 /* S H M E M S E R V E R N O D E */
549 /* */
550 /*********************************************************************************/
551 
552 unsigned int ShmemServerNode(void)
553 {
554 
555  unsigned int *localMapAddr;
556 
557  /* Create a segmentId */
558  localSegmentId =1;// (localNodeId1 << 16) | remoteNodeId1;
559 
560  /* Create local segment */
561  SCICreateSegment(sdOne,&localSegmentOne,localSegmentId, segmentSize, NO_CALLBACK, NULL, NO_FLAGS,&error);
562  if (error == SCI_ERR_OK) {
563  printf("Local segment (id=%d, size=%d) is created. \n", localSegmentId, segmentSize);
564  } else {
565  fprintf(stderr,"SCICreateSegment failed - Error code 0x%x\n",error);
566  return 0;
567  }
568 
569  //localSegmentId = (localNodeId2 << 16) | remoteNodeId2;
570  /*
571  SCICreateSegment(sdTwo,&localSegmentTwo,localSegmentId+1, segmentSize, NO_CALLBACK, NULL, NO_FLAGS,&error);
572  if (error == SCI_ERR_OK) {
573  printf("Local segment (id=%d, size=%d) is created (2). \n", localSegmentId, segmentSize);
574  } else {
575  fprintf(stderr,"SCICreateSegment failed - Error code 0x%x\n",error);
576  return 0;
577  }
578 
579  printf("segment one %p segment 2 %p\n", localSegmentOne, localSegmentTwo);
580  */
581  /* Prepare the segment */
582  SCIPrepareSegment(localSegmentOne,localAdapterNo,NO_FLAGS,&error);
583  if (error == SCI_ERR_OK) {
584  printf("Local segment (id=%d, size=%d) is prepared. \n", localSegmentId, segmentSize);
585  } else {
586  fprintf(stderr,"SCIPrepareSegment failed - Error code 0x%x\n",error);
587  return 0;
588  }
589 
590 
591  /* Prepare the segment */
592 
593  SCIPrepareSegment(localSegmentOne,standbyAdapterNo,NO_FLAGS,&error);
594  if (error == SCI_ERR_OK) {
595  printf("Local segment (id=%d, size=%d) is created. \n", localSegmentId, segmentSize);
596  } else {
597  fprintf(stderr,"SCIPrepareSegment failed - Error code 0x%x\n",error);
598  return 0;
599  }
600 
601 
602  /* Map local segment to user space */
603  localMapAddr = (unsigned int *)SCIMapLocalSegment(localSegmentOne,&localMapOne, offset,segmentSize, NULL,NO_FLAGS,&error);
604  if (error == SCI_ERR_OK) {
605  printf("Local segment (id=0x%x) is mapped to user space @ 0x%x.\n", localSegmentId, localMapAddr);
606  } else {
607  fprintf(stderr,"SCIMapLocalSegment failed - Error code 0x%x\n",error);
608  return 0;
609  }
610 
611 
612  /* Map local segment to user space */
613  /*
614  localMapAddr = (unsigned int *)SCIMapLocalSegment(localSegmentTwo,&localMapTwo, offset,segmentSize, NULL,NO_FLAGS,&error);
615  if (error == SCI_ERR_OK) {
616  printf("Local segment (id=0x%x) is mapped to user space @ 0x%x.\n", localSegmentId, localMapAddr);
617  printf("Local segment (id=%d) is mapped to user space.\n", localSegmentId);
618  } else {
619  fprintf(stderr,"SCIMapLocalSegment failed - Error code 0x%x\n",error);
620  return 0;
621  }
622  */
623 
624  /* Set the segment available */
625  SCISetSegmentAvailable(localSegmentOne, localAdapterNo, NO_FLAGS, &error);
626  if (error == SCI_ERR_OK) {
627  printf("Local segment (id=0x%x) is available for remote connections. \n", localSegmentId);
628  } else {
629  fprintf(stderr,"SCISetSegmentAvailable failed - Error code 0x%x\n",error);
630  return 0;
631  }
632 
633 
634  SCISetSegmentAvailable(localSegmentOne, standbyAdapterNo, NO_FLAGS, &error);
635  if (error == SCI_ERR_OK) {
636  printf("Local segment (id=0x%x) is available for remote connections. \n", localSegmentId);
637  } else {
638  fprintf(stderr,"SCISetSegmentAvailable failed - Error code 0x%x\n",error);
639  return 0;
640  }
641  int timeout=0;
642  error = ReceiveInterrupt(sdOne,localAdapterNo,localNodeId1,DATA_TRANSFER_READY, timeout);
643 
644  if (error == SCI_ERR_OK) {
645  printf("\nThe data transfer is ready\n");
646  } else {
647  printf("\nInterrupt synchronization failed\n");
648  return 0;
649  }
650 
651 
652  again:
653 
654  // printf("Wait for the shared memory data transfer .....");
655  /* Wait for interrupt signal telling that block transfer is ready */
656 
657  //printf("\nData transfer done!\n");
658  //PrintClientData()
659  PrintServerData(localMapAddr);
660  /*Uint32 micros;
661  Uint32 micros2;
662  NDB_TICKS secs;
663  NdbTick_CurrentMicrosecond(&secs, &micros);
664  error = SendInterrupt(sdOne,localAdapterNo,localNodeId1,remoteNodeId1, DATA_TRANSFER_READY);
665  NdbTick_CurrentMicrosecond(&secs, &micros2);
666  printf("TIME ELAPSED %d \n", micros2-micros);
667 // NdbSleep_MilliSleep(100);
668  */
669  goto again;
670 
671  /* Unmap local segment */
672  SCIUnmapSegment(localMapTwo,NO_FLAGS,&error);
673  if (error == SCI_ERR_OK) {
674  printf("The local segment is unmapped\n");
675  } else {
676  fprintf(stderr,"SCIUnmapSegment failed - Error code 0x%x\n",error);
677  return 0;
678  }
679 
680  /* Unmap local segment */
681  SCIUnmapSegment(localMapOne,NO_FLAGS,&error);
682  if (error == SCI_ERR_OK) {
683  printf("The local segment is unmapped\n");
684  } else {
685  fprintf(stderr,"SCIUnmapSegment failed - Error code 0x%x\n",error);
686  return 0;
687  }
688  /* Remove local segment */
689  SCIRemoveSegment(localSegmentOne,NO_FLAGS,&error);
690  if (error == SCI_ERR_OK) {
691  printf("The local segment is removed\n");
692  } else {
693  fprintf(stderr,"SCIRemoveSegment failed - Error code 0x%x\n",error);
694  return 0;
695  }
696 
697  /* Remove local segment */
698  SCIRemoveSegment(localSegmentTwo,NO_FLAGS,&error);
699  if (error == SCI_ERR_OK) {
700  printf("The local segment is removed\n");
701  } else {
702  fprintf(stderr,"SCIRemoveSegment failed - Error code 0x%x\n",error);
703  return 0;
704  }
705 
706 
707 
708 
709  return 1;
710 }
711 
712 
713 
714 /*********************************************************************************/
715 /* M A I N */
716 /* */
717 /*********************************************************************************/
718 
719 int main(int argc,char *argv[])
720 {
721 
722  int counter;
723 
724  printf("\n %s compiled %s : %s\n\n",argv[0],__DATE__,__TIME__);
725 
726  if (argc<3) {
727  Usage();
728  exit(-1);
729  }
730 
731 
732  /* Get the parameters */
733  for (counter=1; counter<argc; counter++) {
734 
735  if (!strcmp("-rn",argv[counter])) {
736  // remoteNodeId = strtol(argv[counter+1],(char **) NULL,10);
737  continue;
738  }
739 
740  if (!strcmp("-size",argv[counter])) {
741  segmentSize = strtol(argv[counter+1],(char **) NULL,10);
742  continue;
743  }
744 
745  if (!strcmp("-adapterno",argv[counter])) {
746  localAdapterNo = strtol(argv[counter+1],(char **) NULL,10);
747  continue;
748  }
749 
750  if (!strcmp("-client",argv[counter])) {
751  client = 1;
752  continue;
753  }
754 
755  if (!strcmp("-server",argv[counter])) {
756  server = 1;
757  continue;
758  }
759 
760  if (!strcmp("-help",argv[counter])) {
761  Usage();
762  exit(0);
763  }
764  }
765 
766  // if (remoteNodeId == 0) {
767  // fprintf(stderr,"Remote node-id is not specified. Use -rn <remote node-id>\n");
768  // exit(-1);
769  //}
770 
771  if (server == 0 && client == 0) {
772  fprintf(stderr,"You must specify a client node or a server node\n");
773  exit(-1);
774  }
775 
776  if (server == 1 && client == 1) {
777  fprintf(stderr,"Both server node and client node is selected.\n");
778  fprintf(stderr,"You must specify either a client or a server node\n");
779  exit(-1);
780  }
781 
782 
783  /* Initialize the SISCI library */
784  SCIInitialize(NO_FLAGS, &error);
785  if (error != SCI_ERR_OK) {
786  fprintf(stderr,"SCIInitialize failed - Error code: 0x%x\n",error);
787  exit(error);
788  }
789 
790 
791  /* Open a file descriptor */
792  SCIOpen(&sdOne,NO_FLAGS,&error);
793  if (error != SCI_ERR_OK) {
794  if (error == SCI_ERR_INCONSISTENT_VERSIONS) {
795  fprintf(stderr,"Version mismatch between SISCI user library and SISCI driver\n");
796  }
797  fprintf(stderr,"SCIOpen failed - Error code 0x%x\n",error);
798  exit(error);
799  }
800 
801  /* Open a file descriptor */
802  SCIOpen(&sdTwo,NO_FLAGS,&error);
803  if (error != SCI_ERR_OK) {
804  if (error == SCI_ERR_INCONSISTENT_VERSIONS) {
805  fprintf(stderr,"Version mismatch between SISCI user library and SISCI driver\n");
806  }
807  fprintf(stderr,"SCIOpen failed - Error code 0x%x\n",error);
808  exit(error);
809  }
810 
811 
812  /* Get local node-id */
813  error = GetLocalNodeId(localAdapterNo, &localNodeId1);
814  error = GetLocalNodeId(standbyAdapterNo, &localNodeId2);
815  if (error != SCI_ERR_OK) {
816  fprintf(stderr,"Could not find the local adapter %d\n", localAdapterNo);
817  SCIClose(sdOne,NO_FLAGS,&error);
818  SCIClose(sdTwo,NO_FLAGS,&error);
819  exit(-1);
820  }
821 
822 
823  /* Print parameters */
824  PrintParameters();
825 
826  if (client) {
827  remoteNodeId1=324;
828  remoteNodeId2=328;
829  ShmemClientNode();
830  } else {
831  remoteNodeId1=452;
832  remoteNodeId2=456;
833  ShmemServerNode();
834  }
835 
836  /* Close the file descriptor */
837  SCIClose(sdOne,NO_FLAGS,&error);
838  SCIClose(sdTwo,NO_FLAGS,&error);
839  if (error != SCI_ERR_OK) {
840  fprintf(stderr,"SCIClose failed - Error code: 0x%x\n",error);
841  }
842 
843 
844  /* Free allocated resources */
845  SCITerminate();
846 
847  return SCI_ERR_OK;
848 }
849 
850 
851 
852 
853 
854 
855 
856 
857 
858 
859 
860 
861 
862 
863 
864 
865